Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 1 | #include "asm_support.h" |
| 2 | |
| 3 | #if defined(__APPLE__) |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 4 | // 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 Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 29 | #endif |
| 30 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 31 | /* Cache alignment for function entry */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 32 | MACRO0(ALIGN_FUNCTION_ENTRY) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 33 | .balign 16 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 34 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Macro that sets up the callee save frame to conform with |
| 38 | * Runtime::CreateCalleeSaveMethod(...) |
| 39 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 40 | MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 41 | pushl %edi // Save callee saves (ebx is saved/restored by the upcall) |
| 42 | pushl %esi |
| 43 | pushl %ebp |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 44 | subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method* |
| 45 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 46 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 47 | MACRO0(RESTORE_CALLEE_SAVE_FRAME) |
| 48 | addl LITERAL(16), %esp // Remove padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 49 | popl %ebp // Restore callee saves |
| 50 | popl %esi |
| 51 | popl %edi |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 52 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Macro that sets up the callee save frame to conform with |
| 56 | * Runtime::CreateCalleeSaveMethod(...) |
| 57 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 58 | MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 59 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 66 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 68 | MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME) |
| 69 | addl LITERAL(16), %esp // Remove padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 70 | popl %ebp // Restore callee saves |
| 71 | popl %esi |
| 72 | popl %edi |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 73 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending |
| 77 | * exception is Thread::Current()->exception_. |
| 78 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 79 | MACRO0(DELIVER_PENDING_EXCEPTION) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 80 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw |
| 81 | mov %esp, %ecx |
| 82 | // Outgoing argument set up |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 83 | subl LITERAL(8), %esp // Alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 84 | pushl %ecx // pass SP |
| 85 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 86 | call artDeliverPendingExceptionFromCode // artDeliverExceptionFromCode(Thread*, SP) |
| 87 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 88 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 89 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 90 | MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 91 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 92 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 93 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 94 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 97 | subl LITERAL(8), %esp // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 98 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 99 | pushl %ecx // pass SP |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 100 | call VAR(cxx_name, 1) // cxx_name(Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 101 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 102 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 103 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 104 | MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 105 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 106 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 107 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 108 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 111 | pushl LITERAL(0) // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 112 | pushl %ecx // pass SP |
| 113 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 114 | pushl %eax // pass arg1 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 115 | call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 116 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 117 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 118 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 119 | MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 120 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 121 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 122 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 123 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 130 | call VAR(cxx_name, 1) // cxx_name(arg2, arg1, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 131 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 132 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * Called by managed code to create and deliver a NullPointerException. |
| 136 | */ |
| 137 | NO_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 | */ |
| 142 | NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode |
| 143 | |
| 144 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 145 | * Called by managed code to create and deliver a StackOverflowError. |
| 146 | */ |
| 147 | NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode |
| 148 | |
| 149 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 150 | * 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 | */ |
| 153 | ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode |
| 154 | |
| 155 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 156 | * Called by managed code to create and deliver a NoSuchMethodError. |
| 157 | */ |
| 158 | ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode |
| 159 | |
| 160 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 161 | * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds |
| 162 | * index, arg2 holds limit. |
| 163 | */ |
| 164 | TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode |
| 165 | |
| 166 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 167 | * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref. |
| 168 | */ |
| 169 | TWO_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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 187 | MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name) |
| 188 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 189 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 190 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 191 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 192 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 193 | |
| 194 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline |
| 195 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck |
| 196 | |
| 197 | INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck |
| 198 | INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck |
| 199 | INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck |
| 200 | INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck |
| 201 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 202 | MACRO1(UNIMPLEMENTED,name) |
| 203 | .globl VAR(name, 0) |
| 204 | ALIGN_FUNCTION_ENTRY |
| 205 | VAR(name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 206 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 207 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 208 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame^] | 209 | // TODO: implement these! |
| 210 | UNIMPLEMENTED art_proxy_invoke_handler |
| 211 | UNIMPLEMENTED art_update_debugger |
| 212 | UNIMPLEMENTED art_test_suspend |
| 213 | UNIMPLEMENTED art_alloc_object_from_code |
| 214 | UNIMPLEMENTED art_alloc_object_from_code_with_access_check |
| 215 | UNIMPLEMENTED art_alloc_array_from_code |
| 216 | UNIMPLEMENTED art_alloc_array_from_code_with_access_check |
| 217 | UNIMPLEMENTED art_check_and_alloc_array_from_code |
| 218 | UNIMPLEMENTED art_check_and_alloc_array_from_code_with_access_check |
| 219 | UNIMPLEMENTED art_can_put_array_element_from_code |
| 220 | UNIMPLEMENTED art_check_cast_from_code |
| 221 | UNIMPLEMENTED art_initialize_static_storage_from_code |
| 222 | UNIMPLEMENTED art_initialize_type_and_verify_access_from_code |
| 223 | UNIMPLEMENTED art_initialize_type_from_code |
| 224 | UNIMPLEMENTED art_resolve_string_from_code |
| 225 | UNIMPLEMENTED art_set32_instance_from_code |
| 226 | UNIMPLEMENTED art_set64_instance_from_code |
| 227 | UNIMPLEMENTED art_set_obj_instance_from_code |
| 228 | UNIMPLEMENTED art_get32_instance_from_code |
| 229 | UNIMPLEMENTED art_get64_instance_from_code |
| 230 | UNIMPLEMENTED art_get_obj_instance_from_code |
| 231 | UNIMPLEMENTED art_set32_static_from_code |
| 232 | UNIMPLEMENTED art_set64_static_from_code |
| 233 | UNIMPLEMENTED art_set_obj_static_from_code |
| 234 | UNIMPLEMENTED art_get32_static_from_code |
| 235 | UNIMPLEMENTED art_get64_static_from_code |
| 236 | UNIMPLEMENTED art_get_obj_static_from_code |
| 237 | UNIMPLEMENTED art_handle_fill_data_from_code |
| 238 | UNIMPLEMENTED art_lock_object_from_code |
| 239 | UNIMPLEMENTED art_unlock_object_from_code |
| 240 | UNIMPLEMENTED art_indexof |
| 241 | UNIMPLEMENTED __memcmp16 |
| 242 | UNIMPLEMENTED art_string_compareto |