blob: c6a3aad8249817e8e640260cb7a99dcfe284e3c5 [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
24 #define END_MACRO .endmacro
25
26 // Mac OS' as(1) uses $0, $1, and so on for macro arguments, and function names
27 // are mangled with an extra underscore prefix. The use of $x for arguments
28 // mean that literals need to be represented with $$x in macros.
Elliott Hughes20a7a072012-04-04 12:54:00 -070029 #define SYMBOL(name) _ ## name
Elliott Hughesadc078a2012-04-04 11:39:05 -070030 #define VAR(name,index) SYMBOL($index)
Elliott Hughes787ec202012-03-29 17:14:15 -070031 #define LITERAL(value) $$value
32#else
33 // Regular gas(1) lets you name macro parameters.
34 #define MACRO0(macro_name) .macro macro_name
35 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
36 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
37 #define END_MACRO .endm
38
39 // Regular gas(1) uses \argument_name for macro arguments.
40 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
41 // will screw us by inserting a space between the \ and the name. Even in this mode there's
42 // no special meaning to $, so literals are still just $x.
43 .altmacro
Elliott Hughesadc078a2012-04-04 11:39:05 -070044 #define SYMBOL(name) name
Elliott Hughes787ec202012-03-29 17:14:15 -070045 #define VAR(name,index) name&
46 #define LITERAL(value) $value
Ian Rogers57b86d42012-03-27 16:05:41 -070047#endif
48
Ian Rogers57b86d42012-03-27 16:05:41 -070049 /* Cache alignment for function entry */
Elliott Hughes787ec202012-03-29 17:14:15 -070050MACRO0(ALIGN_FUNCTION_ENTRY)
Ian Rogers57b86d42012-03-27 16:05:41 -070051 .balign 16
Elliott Hughes787ec202012-03-29 17:14:15 -070052END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070053
Elliott Hughes5e284222012-04-04 13:38:03 -070054MACRO1(DEFINE_FUNCTION,c_name)
55 .globl VAR(c_name, 0)
56 ALIGN_FUNCTION_ENTRY
57VAR(c_name, 0):
58END_MACRO
59
Ian Rogers57b86d42012-03-27 16:05:41 -070060 /*
61 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070062 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070063 */
Elliott Hughes787ec202012-03-29 17:14:15 -070064MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070065 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
66 pushl %esi
67 pushl %ebp
Elliott Hughes787ec202012-03-29 17:14:15 -070068 subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
69END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070070
Ian Rogers7caad772012-03-30 01:07:54 -070071 /*
72 * Macro that sets up the callee save frame to conform with
73 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
74 */
75MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
76 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
77 pushl %esi
78 pushl %ebp
79 subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
80END_MACRO
81
82MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
83 addl LITERAL(28), %esp // Unwind stack up to return address
Elliott Hughes787ec202012-03-29 17:14:15 -070084END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070085
86 /*
87 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070088 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070089 */
Elliott Hughes787ec202012-03-29 17:14:15 -070090MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070091 pushl %edi // Save callee saves
92 pushl %esi
93 pushl %ebp
94 pushl %ebx // Save args
95 pushl %edx
96 pushl %ecx
97 pushl %eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -070098END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070099
Elliott Hughes787ec202012-03-29 17:14:15 -0700100MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME)
Ian Rogers7caad772012-03-30 01:07:54 -0700101 addl LITERAL(4), %esp // Remove padding
102 popl %ecx // Restore args except eax
103 popl %edx
104 popl %ebx
Ian Rogers57b86d42012-03-27 16:05:41 -0700105 popl %ebp // Restore callee saves
106 popl %esi
107 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700108END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700109
110 /*
111 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
112 * exception is Thread::Current()->exception_.
113 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700114MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700115 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
116 mov %esp, %ecx
117 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -0700118 subl LITERAL(8), %esp // Alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700119 pushl %ecx // pass SP
120 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Elliott Hughesadc078a2012-04-04 11:39:05 -0700121 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverExceptionFromCode(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700122 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700123END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700124
Elliott Hughes787ec202012-03-29 17:14:15 -0700125MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
126 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700127 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700128VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700129 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
130 mov %esp, %ecx
131 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -0700132 subl LITERAL(8), %esp // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700133 pushl %ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700134 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Elliott Hughes787ec202012-03-29 17:14:15 -0700135 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700136 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700137END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700138
Elliott Hughes787ec202012-03-29 17:14:15 -0700139MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
140 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700141 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700142VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700143 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
144 mov %esp, %ecx
145 // Outgoing argument set up
Ian Rogers55bd45f2012-04-04 17:31:20 -0700146 pushl %eax // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700147 pushl %ecx // pass SP
148 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
149 pushl %eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700150 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700151 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700152END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700153
Elliott Hughes787ec202012-03-29 17:14:15 -0700154MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
155 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700156 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700157VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700158 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
159 mov %esp, %edx
160 // Outgoing argument set up
161 pushl %edx // pass SP
162 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers57b86d42012-03-27 16:05:41 -0700163 pushl %ecx // pass arg2
Ian Rogers7caad772012-03-30 01:07:54 -0700164 pushl %eax // pass arg1
165 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700166 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700167END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700168
169 /*
170 * Called by managed code to create and deliver a NullPointerException.
171 */
172NO_ARG_RUNTIME_EXCEPTION art_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode
173
174 /*
175 * Called by managed code to create and deliver an ArithmeticException.
176 */
177NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode
178
179 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700180 * Called by managed code to create and deliver a StackOverflowError.
181 */
182NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode
183
184 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700185 * Called by managed code, saves callee saves and then calls artThrowException
186 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
187 */
188ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode
189
190 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700191 * Called by managed code to create and deliver a NoSuchMethodError.
192 */
193ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode
194
195 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700196 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
197 * index, arg2 holds limit.
198 */
199TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode
200
201 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700202 * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref.
203 */
204TWO_ARG_RUNTIME_EXCEPTION art_throw_verification_error_from_code, artThrowVerificationErrorFromCode
205
206 /*
207 * All generated callsites for interface invokes and invocation slow paths will load arguments
208 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
209 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
210 * stack and call the appropriate C helper.
211 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
212 *
213 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
214 * of the target Method* in r0 and method->code_ in r1.
215 *
216 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
217 * thread and we branch to another stub to deliver it.
218 *
219 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
220 * pointing back to the original caller.
221 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700222MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
223 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700224 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700225VAR(c_name, 0):
Ian Rogers7caad772012-03-30 01:07:54 -0700226 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
227 // return address
228 pushl %edi
229 pushl %esi
230 pushl %ebp
231 pushl %ebx
232 pushl %edx
233 pushl %ecx
234 pushl %eax // <-- callee save Method* to go here
235 movl %esp, %edx // remember SP
236 // Outgoing argument set up
237 subl LITERAL(12), %esp // alignment padding
238 pushl %edx // pass SP
239 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
240 pushl 32(%edx) // pass caller Method*
241 pushl %ecx // pass arg2
242 pushl %eax // pass arg1
243 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
244 movl %edx, %edi // save code pointer in EDI
245 addl LITERAL(36), %esp // Pop arguments skip eax
246 popl %ecx // Restore args
247 popl %edx
248 popl %ebx
249 popl %ebp // Restore callee saves.
250 popl %esi
251 // Swap EDI callee save with code pointer.
252 xchgl %edi, (%esp)
253 testl %eax, %eax // Branch forward if exception pending.
254 jz 1f
255 // Tail call to intended method.
256 ret
2571:
258 DELIVER_PENDING_EXCEPTION
Elliott Hughes787ec202012-03-29 17:14:15 -0700259END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700260
261INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline
262INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
263
264INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
265INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
266INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
267INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
268
Ian Rogers7caad772012-03-30 01:07:54 -0700269MACRO2(TWO_ARG_ALLOC, c_name, cxx_name)
270 .globl VAR(c_name, 0)
271 ALIGN_FUNCTION_ENTRY
272VAR(c_name, 0):
273 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
274 mov %esp, %edx // remember SP
275 // Outgoing argument set up
276 pushl %edx // pass SP
277 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
278 pushl %ecx // pass arg2
279 pushl %eax // pass arg1
280 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
281 addl LITERAL(16), %esp // pop arguments
282 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
283 testl %eax, %eax // eax == 0 ?
284 jz 1f
285 ret
2861:
287 DELIVER_PENDING_EXCEPTION
288END_MACRO
289
290MACRO2(THREE_ARG_ALLOC, c_name, cxx_name)
291 .globl VAR(c_name, 0)
292 ALIGN_FUNCTION_ENTRY
293VAR(c_name, 0):
294 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
295 mov %esp, %ebx // remember SP
296 // Outgoing argument set up
297 subl LITERAL(12), %esp // alignment padding
298 pushl %ebx // pass SP
299 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
300 pushl %edx // pass arg3
301 pushl %ecx // pass arg2
302 pushl %eax // pass arg1
303 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
304 addl LITERAL(32), %esp // pop arguments
305 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
306 testl %eax, %eax // eax == 0 ?
307 jz 1f
308 ret
3091:
310 DELIVER_PENDING_EXCEPTION
311END_MACRO
312
313TWO_ARG_ALLOC art_alloc_object_from_code, artAllocObjectFromCode
314TWO_ARG_ALLOC art_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck
315THREE_ARG_ALLOC art_alloc_array_from_code, artAllocArrayFromCode
316THREE_ARG_ALLOC art_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck
317THREE_ARG_ALLOC art_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode
318THREE_ARG_ALLOC art_check_and_alloc_array_from_code_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck
319
320TWO_ARG_ALLOC art_resolve_string_from_code, artResolveStringFromCode
321TWO_ARG_ALLOC art_initialize_static_storage_from_code, artInitializeStaticStorageFromCode
322
Elliott Hughes5e284222012-04-04 13:38:03 -0700323DEFINE_FUNCTION art_lock_object_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700324 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
325 mov %esp, %edx // remember SP
326 // Outgoing argument set up
327 pushl %eax // alignment padding
328 pushl %edx // pass SP
329 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
330 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700331 call SYMBOL(artLockObjectFromCode) // (Object*, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700332 addl LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700333 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
334 ret
335
Elliott Hughes5e284222012-04-04 13:38:03 -0700336DEFINE_FUNCTION art_unlock_object_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700337 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
338 mov %esp, %edx // remember SP
339 // Outgoing argument set up
340 pushl %eax // alignment padding
341 pushl %edx // pass SP
342 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
343 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700344 call SYMBOL(artUnlockObjectFromCode) // (Object*, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700345 addl LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700346 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes5e284222012-04-04 13:38:03 -0700347 testl %eax, %eax // eax == 0 ?
Ian Rogers7caad772012-03-30 01:07:54 -0700348 jnz 1f
349 ret
3501:
351 DELIVER_PENDING_EXCEPTION
352
Elliott Hughes5e284222012-04-04 13:38:03 -0700353DEFINE_FUNCTION art_handle_fill_data_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700354 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
355 mov %esp, %edx // remember SP
356 // Outgoing argument set up
357 pushl %edx // pass SP
358 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
359 pushl %ecx // pass arg2
360 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700361 call SYMBOL(artHandleFillArrayDataFromCode) // (Array* array, const uint16_t* table, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700362 addl LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700363 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogers55bd45f2012-04-04 17:31:20 -0700364 testl %eax, %eax // eax == 0 ?
Ian Rogers7caad772012-03-30 01:07:54 -0700365 jnz 1f
366 ret
3671:
368 DELIVER_PENDING_EXCEPTION
369
Elliott Hughes5e284222012-04-04 13:38:03 -0700370DEFINE_FUNCTION art_is_assignable_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700371 pushl %eax // alignment padding
372 pushl %ecx // pass arg2
373 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700374 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700375 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700376 ret
377
Elliott Hughes5e284222012-04-04 13:38:03 -0700378DEFINE_FUNCTION art_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700379 pushl %edx // pass arg3
380 pushl %ecx // pass arg2
381 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700382 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700383 addl LITERAL(12), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700384 ret
385
Elliott Hughes5e284222012-04-04 13:38:03 -0700386DEFINE_FUNCTION art_check_cast_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700387 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
388 mov %esp, %edx // remember SP
389 // Outgoing argument set up
390 pushl %edx // pass SP
391 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
392 pushl %ecx // pass arg2
393 pushl %eax // pass arg1
Elliott Hughes5e284222012-04-04 13:38:03 -0700394 call SYMBOL(artCheckCastFromCode) // (Class* a, Class* b, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700395 addl LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700396 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes5e284222012-04-04 13:38:03 -0700397 testl %eax, %eax // eax == 0 ?
Ian Rogers7caad772012-03-30 01:07:54 -0700398 jnz 1f
399 ret
4001:
401 DELIVER_PENDING_EXCEPTION
402
Elliott Hughes5e284222012-04-04 13:38:03 -0700403DEFINE_FUNCTION art_idiv_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700404 cdq // edx:eax = sign extend eax
405 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
406 ret
407
Elliott Hughes5e284222012-04-04 13:38:03 -0700408DEFINE_FUNCTION art_idivmod_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700409 cdq // edx:eax = sign extend eax
410 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
411 movl %eax, %edx
412 ret
413
Ian Rogers55bd45f2012-04-04 17:31:20 -0700414DEFINE_FUNCTION art_ldiv_from_code
415 addl LITERAL(12), %esp // alignment padding
416 pushl %ebx // pass arg4
417 pushl %edx // pass arg3
418 pushl %ecx // pass arg2
419 pushl %eax // pass arg1
420 call SYMBOL(artLdivFromCode) // (jlong a, jlong b, Thread*, SP)
421 addl LITERAL(28), %esp // pop arguments
422 ret
423
424DEFINE_FUNCTION art_ldivmod_from_code
425 addl LITERAL(12), %esp // alignment padding
426 pushl %ebx // pass arg4
427 pushl %edx // pass arg3
428 pushl %ecx // pass arg2
429 pushl %eax // pass arg1
430 call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b, Thread*, SP)
431 addl LITERAL(28), %esp // pop arguments
432 ret
433
Elliott Hughes5e284222012-04-04 13:38:03 -0700434DEFINE_FUNCTION art_can_put_array_element_from_code
Ian Rogers7caad772012-03-30 01:07:54 -0700435 test %eax, %eax // Null is trivially storable
436 jz 1f
437 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
438 mov %esp, %edx // remember SP
439 // Outgoing argument set up
440 pushl %edx // pass SP
441 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
442 pushl %ecx // pass arg2
443 pushl %eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700444 call SYMBOL(artCanPutArrayElementFromCode) // (Object* element, Class* array_class, Thread*, SP)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700445 addl LITERAL(16), %esp // pop arguments
Ian Rogers7caad772012-03-30 01:07:54 -0700446 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes5e284222012-04-04 13:38:03 -0700447 testl %eax, %eax // eax == 0 ?
Ian Rogers7caad772012-03-30 01:07:54 -0700448 jnz 2f
4491:
450 ret
4512:
452 DELIVER_PENDING_EXCEPTION
453
Elliott Hughes787ec202012-03-29 17:14:15 -0700454MACRO1(UNIMPLEMENTED,name)
455 .globl VAR(name, 0)
456 ALIGN_FUNCTION_ENTRY
457VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700458 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700459END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700460
Elliott Hughes787ec202012-03-29 17:14:15 -0700461 // TODO: implement these!
462UNIMPLEMENTED art_proxy_invoke_handler
463UNIMPLEMENTED art_update_debugger
464UNIMPLEMENTED art_test_suspend
Elliott Hughes787ec202012-03-29 17:14:15 -0700465UNIMPLEMENTED art_initialize_type_and_verify_access_from_code
466UNIMPLEMENTED art_initialize_type_from_code
Elliott Hughes787ec202012-03-29 17:14:15 -0700467UNIMPLEMENTED art_set32_instance_from_code
468UNIMPLEMENTED art_set64_instance_from_code
469UNIMPLEMENTED art_set_obj_instance_from_code
470UNIMPLEMENTED art_get32_instance_from_code
471UNIMPLEMENTED art_get64_instance_from_code
472UNIMPLEMENTED art_get_obj_instance_from_code
473UNIMPLEMENTED art_set32_static_from_code
474UNIMPLEMENTED art_set64_static_from_code
475UNIMPLEMENTED art_set_obj_static_from_code
476UNIMPLEMENTED art_get32_static_from_code
477UNIMPLEMENTED art_get64_static_from_code
478UNIMPLEMENTED art_get_obj_static_from_code
Elliott Hughes787ec202012-03-29 17:14:15 -0700479UNIMPLEMENTED art_indexof
Ian Rogers7caad772012-03-30 01:07:54 -0700480UNIMPLEMENTED art_memcmp16
Elliott Hughes787ec202012-03-29 17:14:15 -0700481UNIMPLEMENTED art_string_compareto