Elliott Hughes | 0f3c553 | 2012-03-30 14:51:51 -0700 | [diff] [blame^] | 1 | /* |
| 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 Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 17 | #include "asm_support.h" |
| 18 | |
| 19 | #if defined(__APPLE__) |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 20 | // 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 Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 45 | #endif |
| 46 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 47 | /* Cache alignment for function entry */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 48 | MACRO0(ALIGN_FUNCTION_ENTRY) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 49 | .balign 16 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 50 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Macro that sets up the callee save frame to conform with |
| 54 | * Runtime::CreateCalleeSaveMethod(...) |
| 55 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 56 | MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 57 | pushl %edi // Save callee saves (ebx is saved/restored by the upcall) |
| 58 | pushl %esi |
| 59 | pushl %ebp |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 60 | subl LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method* |
| 61 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 62 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 63 | MACRO0(RESTORE_CALLEE_SAVE_FRAME) |
| 64 | addl LITERAL(16), %esp // Remove padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 65 | popl %ebp // Restore callee saves |
| 66 | popl %esi |
| 67 | popl %edi |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 68 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * Macro that sets up the callee save frame to conform with |
| 72 | * Runtime::CreateCalleeSaveMethod(...) |
| 73 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 74 | MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 75 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 82 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 83 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 84 | MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME) |
| 85 | addl LITERAL(16), %esp // Remove padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 86 | popl %ebp // Restore callee saves |
| 87 | popl %esi |
| 88 | popl %edi |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 89 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending |
| 93 | * exception is Thread::Current()->exception_. |
| 94 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 95 | MACRO0(DELIVER_PENDING_EXCEPTION) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 96 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw |
| 97 | mov %esp, %ecx |
| 98 | // Outgoing argument set up |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 99 | subl LITERAL(8), %esp // Alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 100 | pushl %ecx // pass SP |
| 101 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 102 | call artDeliverPendingExceptionFromCode // artDeliverExceptionFromCode(Thread*, SP) |
| 103 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 104 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 105 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 106 | MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 107 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 108 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 109 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 110 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 113 | subl LITERAL(8), %esp // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 114 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 115 | pushl %ecx // pass SP |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 116 | call VAR(cxx_name, 1) // cxx_name(Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 117 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 118 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 119 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 120 | MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 121 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 122 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 123 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 124 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 127 | pushl LITERAL(0) // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 128 | pushl %ecx // pass SP |
| 129 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 130 | pushl %eax // pass arg1 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 131 | call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 132 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 133 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 134 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 135 | MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 136 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 137 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 138 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 139 | 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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 146 | call VAR(cxx_name, 1) // cxx_name(arg2, arg1, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 147 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 148 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * Called by managed code to create and deliver a NullPointerException. |
| 152 | */ |
| 153 | NO_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 | */ |
| 158 | NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode |
| 159 | |
| 160 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 161 | * Called by managed code to create and deliver a StackOverflowError. |
| 162 | */ |
| 163 | NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode |
| 164 | |
| 165 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 166 | * 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 | */ |
| 169 | ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode |
| 170 | |
| 171 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 172 | * Called by managed code to create and deliver a NoSuchMethodError. |
| 173 | */ |
| 174 | ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode |
| 175 | |
| 176 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 177 | * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds |
| 178 | * index, arg2 holds limit. |
| 179 | */ |
| 180 | TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode |
| 181 | |
| 182 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 183 | * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref. |
| 184 | */ |
| 185 | TWO_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 Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 203 | MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name) |
| 204 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 205 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 206 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 207 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 208 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 209 | |
| 210 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline |
| 211 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck |
| 212 | |
| 213 | INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck |
| 214 | INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck |
| 215 | INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck |
| 216 | INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck |
| 217 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 218 | MACRO1(UNIMPLEMENTED,name) |
| 219 | .globl VAR(name, 0) |
| 220 | ALIGN_FUNCTION_ENTRY |
| 221 | VAR(name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 222 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 223 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 224 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 225 | // TODO: implement these! |
| 226 | UNIMPLEMENTED art_proxy_invoke_handler |
| 227 | UNIMPLEMENTED art_update_debugger |
| 228 | UNIMPLEMENTED art_test_suspend |
| 229 | UNIMPLEMENTED art_alloc_object_from_code |
| 230 | UNIMPLEMENTED art_alloc_object_from_code_with_access_check |
| 231 | UNIMPLEMENTED art_alloc_array_from_code |
| 232 | UNIMPLEMENTED art_alloc_array_from_code_with_access_check |
| 233 | UNIMPLEMENTED art_check_and_alloc_array_from_code |
| 234 | UNIMPLEMENTED art_check_and_alloc_array_from_code_with_access_check |
| 235 | UNIMPLEMENTED art_can_put_array_element_from_code |
| 236 | UNIMPLEMENTED art_check_cast_from_code |
| 237 | UNIMPLEMENTED art_initialize_static_storage_from_code |
| 238 | UNIMPLEMENTED art_initialize_type_and_verify_access_from_code |
| 239 | UNIMPLEMENTED art_initialize_type_from_code |
| 240 | UNIMPLEMENTED art_resolve_string_from_code |
| 241 | UNIMPLEMENTED art_set32_instance_from_code |
| 242 | UNIMPLEMENTED art_set64_instance_from_code |
| 243 | UNIMPLEMENTED art_set_obj_instance_from_code |
| 244 | UNIMPLEMENTED art_get32_instance_from_code |
| 245 | UNIMPLEMENTED art_get64_instance_from_code |
| 246 | UNIMPLEMENTED art_get_obj_instance_from_code |
| 247 | UNIMPLEMENTED art_set32_static_from_code |
| 248 | UNIMPLEMENTED art_set64_static_from_code |
| 249 | UNIMPLEMENTED art_set_obj_static_from_code |
| 250 | UNIMPLEMENTED art_get32_static_from_code |
| 251 | UNIMPLEMENTED art_get64_static_from_code |
| 252 | UNIMPLEMENTED art_get_obj_static_from_code |
| 253 | UNIMPLEMENTED art_handle_fill_data_from_code |
| 254 | UNIMPLEMENTED art_lock_object_from_code |
| 255 | UNIMPLEMENTED art_unlock_object_from_code |
| 256 | UNIMPLEMENTED art_indexof |
| 257 | UNIMPLEMENTED __memcmp16 |
| 258 | UNIMPLEMENTED art_string_compareto |