blob: 379fcce7ac7f18665dbed9c17e65eec952cc4711 [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 * All generated callsites for interface invokes and invocation slow paths will load arguments
209 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
210 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
211 * stack and call the appropriate C helper.
212 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
213 *
214 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
215 * of the target Method* in r0 and method->code_ in r1.
216 *
217 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
218 * thread and we branch to another stub to deliver it.
219 *
220 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
221 * pointing back to the original caller.
222 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700223MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
224 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700225 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700226VAR(c_name, 0):
Ian Rogers7caad772012-03-30 01:07:54 -0700227 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
228 // return address
229 pushl %edi
230 pushl %esi
231 pushl %ebp
232 pushl %ebx
233 pushl %edx
234 pushl %ecx
235 pushl %eax // <-- callee save Method* to go here
236 movl %esp, %edx // remember SP
237 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700238 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers7caad772012-03-30 01:07:54 -0700239 pushl %edx // pass SP
240 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
241 pushl 32(%edx) // pass caller Method*
242 pushl %ecx // pass arg2
243 pushl %eax // pass arg1
244 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
245 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700246 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogers7caad772012-03-30 01:07:54 -0700247 popl %ecx // Restore args
248 popl %edx
249 popl %ebx
250 popl %ebp // Restore callee saves.
251 popl %esi
252 // Swap EDI callee save with code pointer.
253 xchgl %edi, (%esp)
254 testl %eax, %eax // Branch forward if exception pending.
255 jz 1f
256 // Tail call to intended method.
257 ret
2581:
jeffhao20b5c6c2012-05-21 14:15:18 -0700259 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers7caad772012-03-30 01:07:54 -0700260 DELIVER_PENDING_EXCEPTION
Elliott Hughes787ec202012-03-29 17:14:15 -0700261END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700262
263INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline
264INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
265
266INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
267INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
268INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
269INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
270
Ian Rogersd36c52e2012-04-09 16:29:25 -0700271MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
272 .globl VAR(c_name, 0)
273 ALIGN_FUNCTION_ENTRY
274VAR(c_name, 0):
275 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
276 mov %esp, %edx // remember SP
277 // Outgoing argument set up
278 subl MACRO_LITERAL(8), %esp // push padding
279 pushl %edx // pass SP
280 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
281 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
282 addl MACRO_LITERAL(16), %esp // pop arguments
283 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700284 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700285END_MACRO
286
287MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
288 .globl VAR(c_name, 0)
289 ALIGN_FUNCTION_ENTRY
290VAR(c_name, 0):
291 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
292 mov %esp, %edx // remember SP
293 // Outgoing argument set up
294 pushl %eax // push padding
295 pushl %edx // pass SP
296 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
297 pushl %eax // pass arg1
298 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
299 addl MACRO_LITERAL(16), %esp // pop arguments
300 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700301 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700302END_MACRO
303
304MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogers7caad772012-03-30 01:07:54 -0700305 .globl VAR(c_name, 0)
306 ALIGN_FUNCTION_ENTRY
307VAR(c_name, 0):
308 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
309 mov %esp, %edx // remember SP
310 // Outgoing argument set up
311 pushl %edx // pass SP
312 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
313 pushl %ecx // pass arg2
314 pushl %eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700315 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700316 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -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 Rogers7caad772012-03-30 01:07:54 -0700319END_MACRO
320
Ian Rogersd36c52e2012-04-09 16:29:25 -0700321MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogers7caad772012-03-30 01:07:54 -0700322 .globl VAR(c_name, 0)
323 ALIGN_FUNCTION_ENTRY
324VAR(c_name, 0):
325 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
326 mov %esp, %ebx // remember SP
327 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700328 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers7caad772012-03-30 01:07:54 -0700329 pushl %ebx // pass SP
330 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
331 pushl %edx // pass arg3
332 pushl %ecx // pass arg2
333 pushl %eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700334 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700335 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700336 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700337 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersd36c52e2012-04-09 16:29:25 -0700338END_MACRO
339
340MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700341 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700342 jz 1f // if eax == 0 goto 1
343 ret // return
3441: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700345 DELIVER_PENDING_EXCEPTION
346END_MACRO
347
Ian Rogersd36c52e2012-04-09 16:29:25 -0700348MACRO0(RETURN_IF_EAX_ZERO)
349 testl %eax, %eax // eax == 0 ?
350 jnz 1f // if eax != 0 goto 1
351 ret // return
3521: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700353 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700354END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700355
jeffhaod66a8752012-05-22 15:30:16 -0700356MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
357 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
358 testl %ebx, %ebx // ebx == 0 ?
359 jnz 1f // if ebx != 0 goto 1
360 ret // return
3611: // deliver exception on current thread
362 DELIVER_PENDING_EXCEPTION
363END_MACRO
364
Ian Rogersd36c52e2012-04-09 16:29:25 -0700365TWO_ARG_DOWNCALL art_alloc_object_from_code, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
366TWO_ARG_DOWNCALL art_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
367THREE_ARG_DOWNCALL art_alloc_array_from_code, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
368THREE_ARG_DOWNCALL art_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
369THREE_ARG_DOWNCALL art_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
370THREE_ARG_DOWNCALL art_check_and_alloc_array_from_code_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
371
372TWO_ARG_DOWNCALL art_resolve_string_from_code, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
373TWO_ARG_DOWNCALL art_initialize_static_storage_from_code, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
Elliott Hughese87c7bc2012-04-16 20:42:34 -0700374TWO_ARG_DOWNCALL art_initialize_type_from_code, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
375TWO_ARG_DOWNCALL art_initialize_type_and_verify_access_from_code, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700376
jeffhao7e4fcb82013-01-10 18:11:08 -0800377 /*
378 * On entry, eax and ecx must be preserved, edx is dex PC
379 */
jeffhao162fd332013-01-08 16:21:01 -0800380DEFINE_FUNCTION art_update_debugger
jeffhao7e4fcb82013-01-10 18:11:08 -0800381 mov %eax, %ebx // stash away eax so that it's saved as if it were an argument
jeffhao162fd332013-01-08 16:21:01 -0800382 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800383 subl LITERAL(4), %esp // alignment padding
jeffhao162fd332013-01-08 16:21:01 -0800384 pushl %esp // pass arg2 (sp)
385 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
386 pushl %edx // pass arg0 (dex pc)
387 call SYMBOL(artUpdateDebuggerFromCode) // artUpdateDebuggerFromCode(int32_t, Thread*, Method**)
jeffhao7e4fcb82013-01-10 18:11:08 -0800388 addl LITERAL(16), %esp // pop arguments
jeffhao162fd332013-01-08 16:21:01 -0800389 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7e4fcb82013-01-10 18:11:08 -0800390 mov %ebx, %eax // restore original eax
jeffhao162fd332013-01-08 16:21:01 -0800391 ret
392
Ian Rogers474b6da2012-09-25 00:20:38 -0700393DEFINE_FUNCTION art_get_and_clear_exception
394 subl LITERAL(8), %esp // alignment padding
395 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
396 call SYMBOL(GetAndClearException) // (Thread*)
397 addl LITERAL(12), %esp // pop arguments
398 ret
399
Ian Rogersd36c52e2012-04-09 16:29:25 -0700400ONE_ARG_DOWNCALL art_lock_object_from_code, artLockObjectFromCode, ret
401ONE_ARG_DOWNCALL art_unlock_object_from_code, artUnlockObjectFromCode, RETURN_IF_EAX_ZERO
402
403TWO_ARG_DOWNCALL art_handle_fill_data_from_code, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700404
Elliott Hughes5e284222012-04-04 13:38:03 -0700405DEFINE_FUNCTION art_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700406 pushl %eax // alignment padding
407 pushl %ecx // pass arg2
408 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700409 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700410 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700411 ret
412
Elliott Hughes5e284222012-04-04 13:38:03 -0700413DEFINE_FUNCTION art_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700414 pushl %edx // pass arg3
415 pushl %ecx // pass arg2
416 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700417 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700418 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700419 ret
420
Ian Rogersd36c52e2012-04-09 16:29:25 -0700421TWO_ARG_DOWNCALL art_check_cast_from_code, artCheckCastFromCode, RETURN_IF_EAX_ZERO
422TWO_ARG_DOWNCALL art_can_put_array_element_from_code, artCanPutArrayElementFromCode, RETURN_IF_EAX_ZERO
423
424NO_ARG_DOWNCALL art_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700425
jeffhao292188d2012-05-17 15:45:04 -0700426DEFINE_FUNCTION art_fmod_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700427 subl LITERAL(12), %esp // alignment padding
428 pushl %ebx // pass arg4 b.hi
429 pushl %edx // pass arg3 b.lo
430 pushl %ecx // pass arg2 a.hi
431 pushl %eax // pass arg1 a.lo
432 call SYMBOL(fmod) // (jdouble a, jdouble b)
433 fstpl (%esp) // pop return value off fp stack
434 movsd (%esp), %xmm0 // place into %xmm0
435 addl LITERAL(28), %esp // pop arguments
jeffhao292188d2012-05-17 15:45:04 -0700436 ret
437
438DEFINE_FUNCTION art_fmodf_from_code
jeffhao1395b1e2012-06-13 18:05:13 -0700439 pushl %eax // alignment padding
440 pushl %ecx // pass arg2 b
441 pushl %eax // pass arg1 a
442 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700443 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700444 movss (%esp), %xmm0 // place into %xmm0
445 addl LITERAL(12), %esp // pop arguments
jeffhao292188d2012-05-17 15:45:04 -0700446 ret
447
jeffhao41005dd2012-05-09 17:58:52 -0700448DEFINE_FUNCTION art_l2d_from_code
449 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700450 pushl %ecx // pass arg2 a.hi
451 pushl %eax // pass arg1 a.lo
452 call SYMBOL(art_l2d) // (jlong a)
jeffhao292188d2012-05-17 15:45:04 -0700453 fstpl (%esp) // pop return value off fp stack
jeffhao41005dd2012-05-09 17:58:52 -0700454 movsd (%esp), %xmm0 // place into %xmm0
455 addl LITERAL(12), %esp // pop arguments
456 ret
457
458DEFINE_FUNCTION art_l2f_from_code
459 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700460 pushl %ecx // pass arg2 a.hi
461 pushl %eax // pass arg1 a.lo
462 call SYMBOL(art_l2f) // (jlong a)
Ian Rogers1b09b092012-08-20 15:35:52 -0700463 fstps (%esp) // pop return value off fp stack
jeffhao41005dd2012-05-09 17:58:52 -0700464 movss (%esp), %xmm0 // place into %xmm0
465 addl LITERAL(12), %esp // pop arguments
466 ret
467
468DEFINE_FUNCTION art_d2l_from_code
469 pushl %eax // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700470 pushl %ecx // pass arg2 a.hi
471 pushl %eax // pass arg1 a.lo
472 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700473 addl LITERAL(12), %esp // pop arguments
474 ret
475
476DEFINE_FUNCTION art_f2l_from_code
477 subl LITERAL(8), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700478 pushl %eax // pass arg1 a
479 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700480 addl LITERAL(12), %esp // pop arguments
481 ret
482
Elliott Hughes5e284222012-04-04 13:38:03 -0700483DEFINE_FUNCTION art_idivmod_from_code
jeffhao174651d2012-04-19 15:27:22 -0700484 cmpl LITERAL(0x80000000), %eax
485 je check_arg2 // special case
486args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700487 cdq // edx:eax = sign extend eax
488 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700489 ret
jeffhao174651d2012-04-19 15:27:22 -0700490check_arg2:
491 cmpl LITERAL(-1), %ecx
492 jne args_ok
493 xorl %edx, %edx
494 ret // eax already holds min int
Ian Rogers7caad772012-03-30 01:07:54 -0700495
Ian Rogers55bd45f2012-04-04 17:31:20 -0700496DEFINE_FUNCTION art_ldiv_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700497 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700498 pushl %ebx // pass arg4 b.hi
499 pushl %edx // pass arg3 b.lo
500 pushl %ecx // pass arg2 a.hi
501 pushl %eax // pass arg1 a.lo
502 call SYMBOL(artLdivFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700503 addl LITERAL(28), %esp // pop arguments
504 ret
505
506DEFINE_FUNCTION art_ldivmod_from_code
Ian Rogers141d6222012-04-05 12:23:06 -0700507 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700508 pushl %ebx // pass arg4 b.hi
509 pushl %edx // pass arg3 b.lo
510 pushl %ecx // pass arg2 a.hi
511 pushl %eax // pass arg1 a.lo
512 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700513 addl LITERAL(28), %esp // pop arguments
514 ret
515
jeffhao644d5312012-05-03 19:04:49 -0700516DEFINE_FUNCTION art_lmul_from_code
517 subl LITERAL(12), %esp // alignment padding
jeffhao1395b1e2012-06-13 18:05:13 -0700518 pushl %ebx // pass arg4 b.hi
519 pushl %edx // pass arg3 b.lo
520 pushl %ecx // pass arg2 a.hi
521 pushl %eax // pass arg1 a.lo
522 call SYMBOL(artLmulFromCode) // (jlong a, jlong b)
jeffhao644d5312012-05-03 19:04:49 -0700523 addl LITERAL(28), %esp // pop arguments
524 ret
525
Ian Rogers141d6222012-04-05 12:23:06 -0700526DEFINE_FUNCTION art_lshl_from_code
jeffhao644d5312012-05-03 19:04:49 -0700527 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700528 xchg %edx, %ecx
529 shld %cl,%eax,%edx
530 shl %cl,%eax
531 test LITERAL(32), %cl
532 jz 1f
533 mov %eax, %edx
534 xor %eax, %eax
5351:
536 ret
537
538DEFINE_FUNCTION art_lshr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700539 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700540 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700541 shrd %cl,%edx,%eax
542 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700543 test LITERAL(32),%cl
544 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700545 mov %edx, %eax
546 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005471:
548 ret
549
550DEFINE_FUNCTION art_lushr_from_code
jeffhao644d5312012-05-03 19:04:49 -0700551 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700552 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700553 shrd %cl,%edx,%eax
554 shr %cl,%edx
555 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700556 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700557 mov %edx, %eax
558 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07005591:
560 ret
561
jeffhao9dbb23e2012-05-18 17:03:57 -0700562DEFINE_FUNCTION art_set32_instance_from_code
563 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
564 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700565 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700566 pushl %ebx // pass SP
567 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
568 mov 32(%ebx), %ebx // get referrer
569 pushl %ebx // pass referrer
570 pushl %edx // pass new_val
571 pushl %ecx // pass object
572 pushl %eax // pass field_idx
573 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700574 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700575 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
576 RETURN_IF_EAX_ZERO // return or deliver exception
577
578DEFINE_FUNCTION art_set64_instance_from_code
579 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700580 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700581 pushl %esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700582 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700583 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
584 pushl %ebx // pass high half of new_val
585 pushl %edx // pass low half of new_val
586 pushl %ecx // pass object
587 pushl %eax // pass field_idx
588 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700589 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700590 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
591 RETURN_IF_EAX_ZERO // return or deliver exception
592
593DEFINE_FUNCTION art_set_obj_instance_from_code
594 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
595 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700596 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700597 pushl %ebx // pass SP
598 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
599 mov 32(%ebx), %ebx // get referrer
600 pushl %ebx // pass referrer
601 pushl %edx // pass new_val
602 pushl %ecx // pass object
603 pushl %eax // pass field_idx
604 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700605 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700606 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
607 RETURN_IF_EAX_ZERO // return or deliver exception
608
609DEFINE_FUNCTION art_get32_instance_from_code
610 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
611 mov %esp, %ebx // remember SP
612 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700613 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700614 pushl %ebx // pass SP
615 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
616 pushl %edx // pass referrer
617 pushl %ecx // pass object
618 pushl %eax // pass field_idx
619 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700620 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700621 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700622 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700623
624DEFINE_FUNCTION art_get64_instance_from_code
625 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
626 mov %esp, %ebx // remember SP
627 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700628 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700629 pushl %ebx // pass SP
630 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
631 pushl %edx // pass referrer
632 pushl %ecx // pass object
633 pushl %eax // pass field_idx
634 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700635 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700636 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700637 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700638
639DEFINE_FUNCTION art_get_obj_instance_from_code
640 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
641 mov %esp, %ebx // remember SP
642 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700643 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700644 pushl %ebx // pass SP
645 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
646 pushl %edx // pass referrer
647 pushl %ecx // pass object
648 pushl %eax // pass field_idx
649 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700650 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700651 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700652 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700653
654DEFINE_FUNCTION art_set32_static_from_code
655 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
656 mov %esp, %ebx // remember SP
657 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700658 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700659 pushl %ebx // pass SP
660 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
661 pushl %edx // pass referrer
662 pushl %ecx // pass new_val
663 pushl %eax // pass field_idx
664 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700665 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700666 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
667 RETURN_IF_EAX_ZERO // return or deliver exception
668
669DEFINE_FUNCTION art_set64_static_from_code
670 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
671 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700672 subl LITERAL(8), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700673 pushl %ebx // pass SP
674 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
675 mov 32(%ebx), %ebx // get referrer
676 pushl %edx // pass high half of new_val
677 pushl %ecx // pass low half of new_val
678 pushl %ebx // pass referrer
679 pushl %eax // pass field_idx
680 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700681 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700682 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
683 RETURN_IF_EAX_ZERO // return or deliver exception
684
685DEFINE_FUNCTION art_set_obj_static_from_code
686 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
687 mov %esp, %ebx // remember SP
688 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700689 subl LITERAL(12), %esp // alignment padding
jeffhao9dbb23e2012-05-18 17:03:57 -0700690 pushl %ebx // pass SP
691 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
692 pushl %edx // pass referrer
693 pushl %ecx // pass new_val
694 pushl %eax // pass field_idx
695 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700696 addl LITERAL(32), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700697 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
698 RETURN_IF_EAX_ZERO // return or deliver exception
699
700DEFINE_FUNCTION art_get32_static_from_code
701 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
702 mov %esp, %edx // remember SP
703 mov 32(%esp), %ecx // get referrer
704 pushl %edx // pass SP
705 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
706 pushl %ecx // pass referrer
707 pushl %eax // pass field_idx
708 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700709 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700710 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700711 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700712
713DEFINE_FUNCTION art_get64_static_from_code
714 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
715 mov %esp, %edx // remember SP
716 mov 32(%esp), %ecx // get referrer
717 pushl %edx // pass SP
718 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
719 pushl %ecx // pass referrer
720 pushl %eax // pass field_idx
721 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700722 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700723 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700724 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700725
726DEFINE_FUNCTION art_get_obj_static_from_code
727 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
728 mov %esp, %edx // remember SP
729 mov 32(%esp), %ecx // get referrer
730 pushl %edx // pass SP
731 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
732 pushl %ecx // pass referrer
733 pushl %eax // pass field_idx
734 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700735 addl LITERAL(16), %esp // pop arguments
jeffhao9dbb23e2012-05-18 17:03:57 -0700736 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700737 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
738
739DEFINE_FUNCTION art_proxy_invoke_handler
740 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
741 lea 8(%esp), %ebx // pointer to r2/r3/LR/caller's Method**/out-args as second arg
742 pushl %ebx // pass args
743 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
744 pushl %ecx // pass receiver
745 pushl %eax // pass proxy method
746 call SYMBOL(artProxyInvokeHandler) // (proxy method, receiver, Thread*, args...)
747 mov 24(%esp), %eax // get ret0 which was written into r2 on the stack
748 mov 28(%esp), %edx // get ret1 which was written into r3 on the stack
jeffhao5d05c752012-05-23 10:57:48 -0700749 movsd 24(%esp), %xmm0 // get ret0/ret1 from stack for floating point
jeffhaod66a8752012-05-22 15:30:16 -0700750 addl LITERAL(44), %esp // pop arguments
751 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
jeffhao9dbb23e2012-05-18 17:03:57 -0700752
jeffhao7e4fcb82013-01-10 18:11:08 -0800753 /*
754 * Routine that intercepts method calls and returns.
755 */
jeffhao162fd332013-01-08 16:21:01 -0800756DEFINE_FUNCTION art_instrumentation_entry_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800757 xchgl %eax, (%esp) // place LR in eax, save eax
758 pushl %ecx // save ecx
759 pushl %edx // save edx
760 pushl %ebx // save ebx
761 lea 16(%esp), %edx // remember bottom of caller's frame
762 pushl %eax // pass LR
763 pushl %edx // pass SP
764 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
765 pushl 24(%esp) // pass Method*
766 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Thread*, SP, LR)
767 addl LITERAL(16), %esp // pop arguments
768 popl %ebx // restore ebx
769 popl %edx // restore edx
770 movl (%esp), %ecx // restore ecx (without popping)
771 movl %eax, (%esp) // place method's code pointer on stack
772 movl 4(%esp), %eax // restore eax (without popping)
773 movl LITERAL(SYMBOL(art_instrumentation_exit_from_code)), 4(%esp)
774 // place instrumentation exit as return pc
775 ret // call method (and pop)
jeffhao162fd332013-01-08 16:21:01 -0800776DEFINE_FUNCTION art_instrumentation_exit_from_code
jeffhao7e4fcb82013-01-10 18:11:08 -0800777 mov %esp, %ecx // remember bottom of caller's frame
778 pushl %edx // save return value
779 pushl %eax // save other half of return value
780 pushl %ecx // pass SP
781 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current
782 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP)
783 mov %eax, %ecx // move returned link register
784 // TODO: Set link register for deopt
785 addl LITERAL(8), %esp // pop arguments
786 popl %eax // restore return value
787 popl %edx // restore other half of return value
788 jmp *%ecx // return
jeffhao162fd332013-01-08 16:21:01 -0800789
jeffhao7e4fcb82013-01-10 18:11:08 -0800790 /*
791 * The thread's enter interpreter flag is set and so we should transition to the interpreter
792 * rather than allow execution to continue in the frame below. There may be live results in
793 * registers depending on how complete the operation is when we safepoint - for example, a
794 * set operation may have completed while a get operation needs writing back into the vregs.
795 */
jeffhao162fd332013-01-08 16:21:01 -0800796DEFINE_FUNCTION art_deoptimize
jeffhao7e4fcb82013-01-10 18:11:08 -0800797 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
798 pushl %esp // pass SP
799 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
800 pushl %edx // push half of return value
801 pushl %eax // push other half of return value
802 call SYMBOL(artDeoptimize) // artDeoptimize(return value, Thread*, SP)
803 // Returns caller method's frame size.
804 addl LITERAL(16), %esp // pop arguments
805 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
806 testl %eax, %eax // Was the caller an upcall?
807 jz 1f // Return if caller was upcall.
808 lea (%esp, %eax), %edx // edx == bottom of caller's frame.
809 mov %edx, %esp // Remove frame.
810 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
811 call SYMBOL(artEnterInterpreterFromDeoptimize) // Enter interpreter, callee-save ends stack fragment.
812 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
8131:
814 ret // Return to caller.
jeffhao162fd332013-01-08 16:21:01 -0800815
jeffhao86e46712012-08-08 17:30:59 -0700816 /*
817 * String's indexOf.
818 *
819 * On entry:
820 * eax: string object (known non-null)
821 * ecx: char to match (known <= 0xFFFF)
822 * edx: Starting offset in string data
823 */
824DEFINE_FUNCTION art_indexof
825 pushl %edi // push callee save reg
826 mov STRING_COUNT_OFFSET(%eax), %ebx
827 mov STRING_VALUE_OFFSET(%eax), %edi
828 mov STRING_OFFSET_OFFSET(%eax), %eax
829 testl %edx, %edx // check if start < 0
830 jl clamp_min
831clamp_done:
832 cmpl %ebx, %edx // check if start >= count
833 jge not_found
834 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
835 mov %edi, %eax // save a copy in eax to later compute result
836 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
837 subl %edx, %ebx // compute iteration count
838 /*
839 * At this point we have:
840 * eax: original start of string data
841 * ecx: char to compare
842 * ebx: length to compare
843 * edi: start of data to test
844 */
845 mov %eax, %edx
846 mov %ecx, %eax // put char to match in %eax
847 mov %ebx, %ecx // put length to compare in %ecx
848 repne scasw // find %ax, starting at [%edi], up to length %ecx
849 jne not_found
850 subl %edx, %edi
851 sar LITERAL(1), %edi
852 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
853 mov %edi, %eax
854 popl %edi // pop callee save reg
855 ret
856 .balign 16
857not_found:
858 mov LITERAL(-1), %eax // return -1 (not found)
859 popl %edi // pop callee save reg
860 ret
861clamp_min:
862 xor %edx, %edx // clamp start to 0
863 jmp clamp_done
864
865 /*
866 * String's compareTo.
867 *
868 * On entry:
869 * eax: this string object (known non-null)
870 * ecx: comp string object (known non-null)
871 */
872DEFINE_FUNCTION art_string_compareto
873 pushl %esi // push callee save reg
874 pushl %edi // push callee save reg
875 mov STRING_COUNT_OFFSET(%eax), %edx
876 mov STRING_COUNT_OFFSET(%ecx), %ebx
877 mov STRING_VALUE_OFFSET(%eax), %esi
878 mov STRING_VALUE_OFFSET(%ecx), %edi
879 mov STRING_OFFSET_OFFSET(%eax), %eax
880 mov STRING_OFFSET_OFFSET(%ecx), %ecx
881 /* Build pointers to the start of string data */
882 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
883 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
884 /* Calculate min length and count diff */
885 mov %edx, %ecx
886 mov %edx, %eax
887 subl %ebx, %eax
888 cmovg %ebx, %ecx
889 /*
890 * At this point we have:
891 * eax: value to return if first part of strings are equal
892 * ecx: minimum among the lengths of the two strings
893 * esi: pointer to this string data
894 * edi: pointer to comp string data
895 */
896 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
897 jne not_equal
898 popl %edi // pop callee save reg
899 popl %esi // pop callee save reg
900 ret
901 .balign 16
902not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -0700903 movzwl -2(%esi), %eax // get last compared char from this string
904 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -0700905 subl %ecx, %eax // return the difference
906 popl %edi // pop callee save reg
907 popl %esi // pop callee save reg
908 ret
909
Elliott Hughes787ec202012-03-29 17:14:15 -0700910MACRO1(UNIMPLEMENTED,name)
911 .globl VAR(name, 0)
912 ALIGN_FUNCTION_ENTRY
913VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700914 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700915END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700916
Elliott Hughes787ec202012-03-29 17:14:15 -0700917 // TODO: implement these!
Ian Rogers7caad772012-03-30 01:07:54 -0700918UNIMPLEMENTED art_memcmp16