blob: 8f7177c2aec15996abeeed5a8ba369c16cc12709 [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001#include "asm_support.h"
2
3#if defined(__APPLE__)
Elliott Hughes787ec202012-03-29 17:14:15 -07004 // Mac OS' as(1) doesn't let you name macro parameters.
5 #define MACRO0(macro_name) .macro macro_name
6 #define MACRO1(macro_name, macro_arg1) .macro macro_name
7 #define MACRO2(macro_name, macro_arg1, macro_args2) .macro macro_name
8 #define END_MACRO .endmacro
9
10 // Mac OS' as(1) uses $0, $1, and so on for macro arguments, and function names
11 // are mangled with an extra underscore prefix. The use of $x for arguments
12 // mean that literals need to be represented with $$x in macros.
13 #define VAR(name,index) _$index
14 #define LITERAL(value) $$value
15#else
16 // Regular gas(1) lets you name macro parameters.
17 #define MACRO0(macro_name) .macro macro_name
18 #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1
19 #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2
20 #define END_MACRO .endm
21
22 // Regular gas(1) uses \argument_name for macro arguments.
23 // We need to turn on alternate macro syntax so we can use & instead or the preprocessor
24 // will screw us by inserting a space between the \ and the name. Even in this mode there's
25 // no special meaning to $, so literals are still just $x.
26 .altmacro
27 #define VAR(name,index) name&
28 #define LITERAL(value) $value
Ian Rogers57b86d42012-03-27 16:05:41 -070029#endif
30
Ian Rogers57b86d42012-03-27 16:05:41 -070031 /* Cache alignment for function entry */
Elliott Hughes787ec202012-03-29 17:14:15 -070032MACRO0(ALIGN_FUNCTION_ENTRY)
Ian Rogers57b86d42012-03-27 16:05:41 -070033 .balign 16
Elliott Hughes787ec202012-03-29 17:14:15 -070034END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070035
36 /*
37 * Macro that sets up the callee save frame to conform with
38 * Runtime::CreateCalleeSaveMethod(...)
39 */
Elliott Hughes787ec202012-03-29 17:14:15 -070040MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070041 pushl %edi // Save callee saves (ebx is saved/restored by the upcall)
42 pushl %esi
43 pushl %ebp
Elliott Hughes787ec202012-03-29 17:14:15 -070044 subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
45END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070046
Elliott Hughes787ec202012-03-29 17:14:15 -070047MACRO0(RESTORE_CALLEE_SAVE_FRAME)
48 addl LITERAL(16), %esp // Remove padding
Ian Rogers57b86d42012-03-27 16:05:41 -070049 popl %ebp // Restore callee saves
50 popl %esi
51 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -070052END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070053
54 /*
55 * Macro that sets up the callee save frame to conform with
56 * Runtime::CreateCalleeSaveMethod(...)
57 */
Elliott Hughes787ec202012-03-29 17:14:15 -070058MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME)
Ian Rogers57b86d42012-03-27 16:05:41 -070059 pushl %edi // Save callee saves
60 pushl %esi
61 pushl %ebp
62 pushl %ebx // Save args
63 pushl %edx
64 pushl %ecx
65 pushl %eax // Align stack, eax will be clobbered by Method*
Elliott Hughes787ec202012-03-29 17:14:15 -070066END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070067
Elliott Hughes787ec202012-03-29 17:14:15 -070068MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME)
69 addl LITERAL(16), %esp // Remove padding
Ian Rogers57b86d42012-03-27 16:05:41 -070070 popl %ebp // Restore callee saves
71 popl %esi
72 popl %edi
Elliott Hughes787ec202012-03-29 17:14:15 -070073END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070074
75 /*
76 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
77 * exception is Thread::Current()->exception_.
78 */
Elliott Hughes787ec202012-03-29 17:14:15 -070079MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -070080 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
81 mov %esp, %ecx
82 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -070083 subl LITERAL(8), %esp // Alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -070084 pushl %ecx // pass SP
85 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
86 call artDeliverPendingExceptionFromCode // artDeliverExceptionFromCode(Thread*, SP)
87 int3
Elliott Hughes787ec202012-03-29 17:14:15 -070088END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070089
Elliott Hughes787ec202012-03-29 17:14:15 -070090MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
91 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -070092 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -070093VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -070094 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
95 mov %esp, %ecx
96 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -070097 subl LITERAL(8), %esp // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -070098 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
99 pushl %ecx // pass SP
Elliott Hughes787ec202012-03-29 17:14:15 -0700100 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700101 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700102END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700103
Elliott Hughes787ec202012-03-29 17:14:15 -0700104MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
105 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700106 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700107VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700108 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
109 mov %esp, %ecx
110 // Outgoing argument set up
Elliott Hughes787ec202012-03-29 17:14:15 -0700111 pushl LITERAL(0) // alignment padding
Ian Rogers57b86d42012-03-27 16:05:41 -0700112 pushl %ecx // pass SP
113 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
114 pushl %eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700115 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700116 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700117END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700118
Elliott Hughes787ec202012-03-29 17:14:15 -0700119MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
120 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700121 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700122VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700123 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
124 mov %esp, %edx
125 // Outgoing argument set up
126 pushl %edx // pass SP
127 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
128 pushl %eax // pass arg1
129 pushl %ecx // pass arg2
Elliott Hughes787ec202012-03-29 17:14:15 -0700130 call VAR(cxx_name, 1) // cxx_name(arg2, arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700131 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700132END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700133
134 /*
135 * Called by managed code to create and deliver a NullPointerException.
136 */
137NO_ARG_RUNTIME_EXCEPTION art_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode
138
139 /*
140 * Called by managed code to create and deliver an ArithmeticException.
141 */
142NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode
143
144 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700145 * Called by managed code to create and deliver a StackOverflowError.
146 */
147NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode
148
149 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700150 * Called by managed code, saves callee saves and then calls artThrowException
151 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
152 */
153ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode
154
155 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700156 * Called by managed code to create and deliver a NoSuchMethodError.
157 */
158ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode
159
160 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700161 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
162 * index, arg2 holds limit.
163 */
164TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode
165
166 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700167 * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref.
168 */
169TWO_ARG_RUNTIME_EXCEPTION art_throw_verification_error_from_code, artThrowVerificationErrorFromCode
170
171 /*
172 * All generated callsites for interface invokes and invocation slow paths will load arguments
173 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
174 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
175 * stack and call the appropriate C helper.
176 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
177 *
178 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
179 * of the target Method* in r0 and method->code_ in r1.
180 *
181 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
182 * thread and we branch to another stub to deliver it.
183 *
184 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
185 * pointing back to the original caller.
186 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700187MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
188 .globl VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700189 ALIGN_FUNCTION_ENTRY
Elliott Hughes787ec202012-03-29 17:14:15 -0700190VAR(c_name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700191 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700192END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700193
194INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline
195INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
196
197INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
198INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
199INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
200INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
201
Elliott Hughes787ec202012-03-29 17:14:15 -0700202MACRO1(UNIMPLEMENTED,name)
203 .globl VAR(name, 0)
204 ALIGN_FUNCTION_ENTRY
205VAR(name, 0):
Ian Rogers57b86d42012-03-27 16:05:41 -0700206 int3
Elliott Hughes787ec202012-03-29 17:14:15 -0700207END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700208
Elliott Hughes787ec202012-03-29 17:14:15 -0700209 // TODO: implement these!
210UNIMPLEMENTED art_proxy_invoke_handler
211UNIMPLEMENTED art_update_debugger
212UNIMPLEMENTED art_test_suspend
213UNIMPLEMENTED art_alloc_object_from_code
214UNIMPLEMENTED art_alloc_object_from_code_with_access_check
215UNIMPLEMENTED art_alloc_array_from_code
216UNIMPLEMENTED art_alloc_array_from_code_with_access_check
217UNIMPLEMENTED art_check_and_alloc_array_from_code
218UNIMPLEMENTED art_check_and_alloc_array_from_code_with_access_check
219UNIMPLEMENTED art_can_put_array_element_from_code
220UNIMPLEMENTED art_check_cast_from_code
221UNIMPLEMENTED art_initialize_static_storage_from_code
222UNIMPLEMENTED art_initialize_type_and_verify_access_from_code
223UNIMPLEMENTED art_initialize_type_from_code
224UNIMPLEMENTED art_resolve_string_from_code
225UNIMPLEMENTED art_set32_instance_from_code
226UNIMPLEMENTED art_set64_instance_from_code
227UNIMPLEMENTED art_set_obj_instance_from_code
228UNIMPLEMENTED art_get32_instance_from_code
229UNIMPLEMENTED art_get64_instance_from_code
230UNIMPLEMENTED art_get_obj_instance_from_code
231UNIMPLEMENTED art_set32_static_from_code
232UNIMPLEMENTED art_set64_static_from_code
233UNIMPLEMENTED art_set_obj_static_from_code
234UNIMPLEMENTED art_get32_static_from_code
235UNIMPLEMENTED art_get64_static_from_code
236UNIMPLEMENTED art_get_obj_static_from_code
237UNIMPLEMENTED art_handle_fill_data_from_code
238UNIMPLEMENTED art_lock_object_from_code
239UNIMPLEMENTED art_unlock_object_from_code
240UNIMPLEMENTED art_indexof
241UNIMPLEMENTED __memcmp16
242UNIMPLEMENTED art_string_compareto