blob: 33334694e815bd0c1d13198c0cc5b5018c040771 [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.
29 #define VAR(name,index) _$index
30 #define LITERAL(value) $$value
31#else
32 // Regular gas(1) lets you name macro parameters.
33 #define MACRO0(macro_name) .macro macro_name
34 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
35 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
36 #define END_MACRO .endm
37
38 // Regular gas(1) uses \argument_name for macro arguments.
39 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
40 // will screw us by inserting a space between the \ and the name. Even in this mode there's
41 // no special meaning to $, so literals are still just $x.
42 .altmacro
43 #define VAR(name,index) name&
44 #define LITERAL(value) $value
Ian Rogers57b86d42012-03-27 16:05:41 -070045#endif
46
Ian Rogers57b86d42012-03-27 16:05:41 -070047 /* Cache alignment for function entry */
Elliott Hughes787ec202012-03-29 17:14:15 -070048MACRO0(ALIGN_FUNCTION_ENTRY)
Ian Rogers57b86d42012-03-27 16:05:41 -070049 .balign 16
Elliott Hughes787ec202012-03-29 17:14:15 -070050END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070051
52 /*
53 * Macro that sets up the callee save frame to conform with
54 * Runtime::CreateCalleeSaveMethod(...)
55 */
Elliott Hughes787ec202012-03-29 17:14:15 -070056MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070057 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
58 pushl %esi
59 pushl %ebp
Elliott Hughes787ec202012-03-29 17:14:15 -070060 subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
61END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070062
Elliott Hughes787ec202012-03-29 17:14:15 -070063MACRO0(RESTORE_CALLEE_SAVE_FRAME)
64 addl LITERAL(16), %esp // Remove padding
Ian Rogers57b86d42012-03-27 16:05:41 -070065 popl %ebp // Restore callee saves
66 popl %esi
67 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -070068END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070069
70 /*
71 * Macro that sets up the callee save frame to conform with
72 * Runtime::CreateCalleeSaveMethod(...)
73 */
Elliott Hughes787ec202012-03-29 17:14:15 -070074MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070075 pushl %edi // Save callee saves
76 pushl %esi
77 pushl %ebp
78 pushl %ebx // Save args
79 pushl %edx
80 pushl %ecx
81 pushl %eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -070082END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070083
Elliott Hughes787ec202012-03-29 17:14:15 -070084MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME)
85 addl LITERAL(16), %esp // Remove padding
Ian Rogers57b86d42012-03-27 16:05:41 -070086 popl %ebp // Restore callee saves
87 popl %esi
88 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -070089END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070090
91 /*
92 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
93 * exception is Thread::Current()->exception_.
94 */
Elliott Hughes787ec202012-03-29 17:14:15 -070095MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -070096 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
97 mov %esp, %ecx
98 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -070099 subl LITERAL(8), %esp // Alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700100 pushl %ecx // pass SP
101 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
102 call artDeliverPendingExceptionFromCode // artDeliverExceptionFromCode(Thread*, SP)
103 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700104END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700105
Elliott Hughes787ec202012-03-29 17:14:15 -0700106MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
107 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700108 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700109VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700110 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
111 mov %esp, %ecx
112 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -0700113 subl LITERAL(8), %esp // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700114 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
115 pushl %ecx // pass SP
Elliott Hughes787ec202012-03-29 17:14:15 -0700116 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700117 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700118END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700119
Elliott Hughes787ec202012-03-29 17:14:15 -0700120MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
121 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700122 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700123VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700124 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
125 mov %esp, %ecx
126 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -0700127 pushl LITERAL(0) // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700128 pushl %ecx // pass SP
129 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
130 pushl %eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700131 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700132 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700133END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700134
Elliott Hughes787ec202012-03-29 17:14:15 -0700135MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
136 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700137 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700138VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700139 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
140 mov %esp, %edx
141 // Outgoing argument set up
142 pushl %edx // pass SP
143 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
144 pushl %eax // pass arg1
145 pushl %ecx // pass arg2
Elliott Hughes787ec202012-03-29 17:14:15 -0700146 call VAR(cxx_name, 1) // cxx_name(arg2, arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700147 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700148END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700149
150 /*
151 * Called by managed code to create and deliver a NullPointerException.
152 */
153NO_ARG_RUNTIME_EXCEPTION art_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode
154
155 /*
156 * Called by managed code to create and deliver an ArithmeticException.
157 */
158NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode
159
160 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700161 * Called by managed code to create and deliver a StackOverflowError.
162 */
163NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode
164
165 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700166 * Called by managed code, saves callee saves and then calls artThrowException
167 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
168 */
169ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode
170
171 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700172 * Called by managed code to create and deliver a NoSuchMethodError.
173 */
174ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode
175
176 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700177 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
178 * index, arg2 holds limit.
179 */
180TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode
181
182 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700183 * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref.
184 */
185TWO_ARG_RUNTIME_EXCEPTION art_throw_verification_error_from_code, artThrowVerificationErrorFromCode
186
187 /*
188 * All generated callsites for interface invokes and invocation slow paths will load arguments
189 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
190 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
191 * stack and call the appropriate C helper.
192 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
193 *
194 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
195 * of the target Method* in r0 and method->code_ in r1.
196 *
197 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
198 * thread and we branch to another stub to deliver it.
199 *
200 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
201 * pointing back to the original caller.
202 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700203MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
204 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700205 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700206VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700207 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700208END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700209
210INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline
211INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
212
213INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
214INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
215INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
216INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
217
Elliott Hughes787ec202012-03-29 17:14:15 -0700218MACRO1(UNIMPLEMENTED,name)
219 .globl VAR(name, 0)
220 ALIGN_FUNCTION_ENTRY
221VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700222 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700223END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700224
Elliott Hughes787ec202012-03-29 17:14:15 -0700225 // TODO: implement these!
226UNIMPLEMENTED art_proxy_invoke_handler
227UNIMPLEMENTED art_update_debugger
228UNIMPLEMENTED art_test_suspend
229UNIMPLEMENTED art_alloc_object_from_code
230UNIMPLEMENTED art_alloc_object_from_code_with_access_check
231UNIMPLEMENTED art_alloc_array_from_code
232UNIMPLEMENTED art_alloc_array_from_code_with_access_check
233UNIMPLEMENTED art_check_and_alloc_array_from_code
234UNIMPLEMENTED art_check_and_alloc_array_from_code_with_access_check
235UNIMPLEMENTED art_can_put_array_element_from_code
236UNIMPLEMENTED art_check_cast_from_code
237UNIMPLEMENTED art_initialize_static_storage_from_code
238UNIMPLEMENTED art_initialize_type_and_verify_access_from_code
239UNIMPLEMENTED art_initialize_type_from_code
240UNIMPLEMENTED art_resolve_string_from_code
241UNIMPLEMENTED art_set32_instance_from_code
242UNIMPLEMENTED art_set64_instance_from_code
243UNIMPLEMENTED art_set_obj_instance_from_code
244UNIMPLEMENTED art_get32_instance_from_code
245UNIMPLEMENTED art_get64_instance_from_code
246UNIMPLEMENTED art_get_obj_instance_from_code
247UNIMPLEMENTED art_set32_static_from_code
248UNIMPLEMENTED art_set64_static_from_code
249UNIMPLEMENTED art_set_obj_static_from_code
250UNIMPLEMENTED art_get32_static_from_code
251UNIMPLEMENTED art_get64_static_from_code
252UNIMPLEMENTED art_get_obj_static_from_code
253UNIMPLEMENTED art_handle_fill_data_from_code
254UNIMPLEMENTED art_lock_object_from_code
255UNIMPLEMENTED art_unlock_object_from_code
256UNIMPLEMENTED art_indexof
257UNIMPLEMENTED __memcmp16
258UNIMPLEMENTED art_string_compareto