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. |
Elliott Hughes | 20a7a07 | 2012-04-04 12:54:00 -0700 | [diff] [blame] | 29 | #define SYMBOL(name) _ ## name |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 30 | #define VAR(name,index) SYMBOL($index) |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 31 | #define LITERAL(value) $value |
| 32 | #define MACRO_LITERAL(value) $$value |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 33 | #else |
| 34 | // Regular gas(1) lets you name macro parameters. |
| 35 | #define MACRO0(macro_name) .macro macro_name |
| 36 | #define MACRO1(macro_name, macro_arg1) .macro macro_name macro_arg1 |
| 37 | #define MACRO2(macro_name, macro_arg1, macro_arg2) .macro macro_name macro_arg1, macro_arg2 |
| 38 | #define END_MACRO .endm |
| 39 | |
| 40 | // Regular gas(1) uses \argument_name for macro arguments. |
| 41 | // We need to turn on alternate macro syntax so we can use & instead or the preprocessor |
| 42 | // will screw us by inserting a space between the \ and the name. Even in this mode there's |
| 43 | // no special meaning to $, so literals are still just $x. |
| 44 | .altmacro |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 45 | #define SYMBOL(name) name |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 46 | #define VAR(name,index) name& |
| 47 | #define LITERAL(value) $value |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 48 | #define MACRO_LITERAL(value) $value |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 51 | /* Cache alignment for function entry */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 52 | MACRO0(ALIGN_FUNCTION_ENTRY) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 53 | .balign 16 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 54 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 55 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 56 | MACRO1(DEFINE_FUNCTION,c_name) |
| 57 | .globl VAR(c_name, 0) |
| 58 | ALIGN_FUNCTION_ENTRY |
| 59 | VAR(c_name, 0): |
| 60 | END_MACRO |
| 61 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 62 | /* |
| 63 | * Macro that sets up the callee save frame to conform with |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 64 | * Runtime::CreateCalleeSaveMethod(kSaveAll) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 65 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 66 | MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 67 | pushl %edi // Save callee saves (ebx is saved/restored by the upcall) |
| 68 | pushl %esi |
| 69 | pushl %ebp |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 70 | subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 71 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 72 | |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 73 | /* |
| 74 | * Macro that sets up the callee save frame to conform with |
| 75 | * Runtime::CreateCalleeSaveMethod(kRefsOnly) |
| 76 | */ |
| 77 | MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME) |
| 78 | pushl %edi // Save callee saves (ebx is saved/restored by the upcall) |
| 79 | pushl %esi |
| 80 | pushl %ebp |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 81 | subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method* |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 82 | END_MACRO |
| 83 | |
| 84 | MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME) |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 85 | addl MACRO_LITERAL(28), %esp // Unwind stack up to return address |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 86 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Macro that sets up the callee save frame to conform with |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 90 | * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 91 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 92 | MACRO0(SETUP_REF_AND_ARG_CALLEE_SAVE_FRAME) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 93 | pushl %edi // Save callee saves |
| 94 | pushl %esi |
| 95 | pushl %ebp |
| 96 | pushl %ebx // Save args |
| 97 | pushl %edx |
| 98 | pushl %ecx |
| 99 | pushl %eax // Align stack, eax will be clobbered by Method* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 100 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 101 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 102 | MACRO0(RESTORE_REF_AND_ARG_CALLEE_SAVE_FRAME) |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 103 | addl MACRO_LITERAL(4), %esp // Remove padding |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 104 | popl %ecx // Restore args except eax |
| 105 | popl %edx |
| 106 | popl %ebx |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 107 | popl %ebp // Restore callee saves |
| 108 | popl %esi |
| 109 | popl %edi |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 110 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 111 | |
| 112 | /* |
| 113 | * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending |
| 114 | * exception is Thread::Current()->exception_. |
| 115 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 116 | MACRO0(DELIVER_PENDING_EXCEPTION) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 117 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw |
| 118 | mov %esp, %ecx |
| 119 | // Outgoing argument set up |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 120 | subl MACRO_LITERAL(8), %esp // Alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 121 | pushl %ecx // pass SP |
| 122 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 123 | call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverExceptionFromCode(Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 124 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 125 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 126 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 127 | MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 128 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 129 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 130 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 131 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
| 132 | mov %esp, %ecx |
| 133 | // Outgoing argument set up |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 134 | subl MACRO_LITERAL(8), %esp // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 135 | pushl %ecx // pass SP |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 136 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 137 | call VAR(cxx_name, 1) // cxx_name(Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 138 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 139 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 140 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 141 | MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 142 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 143 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 144 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 145 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
| 146 | mov %esp, %ecx |
| 147 | // Outgoing argument set up |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 148 | pushl %eax // alignment padding |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 149 | pushl %ecx // pass SP |
| 150 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 151 | pushl %eax // pass arg1 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 152 | call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 153 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 154 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 155 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 156 | MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name) |
| 157 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 158 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 159 | VAR(c_name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 160 | SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context |
| 161 | mov %esp, %edx |
| 162 | // Outgoing argument set up |
| 163 | pushl %edx // pass SP |
| 164 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 165 | pushl %ecx // pass arg2 |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 166 | pushl %eax // pass arg1 |
| 167 | call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 168 | int3 // unreached |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 169 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 170 | |
| 171 | /* |
| 172 | * Called by managed code to create and deliver a NullPointerException. |
| 173 | */ |
| 174 | NO_ARG_RUNTIME_EXCEPTION art_throw_null_pointer_exception_from_code, artThrowNullPointerExceptionFromCode |
| 175 | |
| 176 | /* |
| 177 | * Called by managed code to create and deliver an ArithmeticException. |
| 178 | */ |
| 179 | NO_ARG_RUNTIME_EXCEPTION art_throw_div_zero_from_code, artThrowDivZeroFromCode |
| 180 | |
| 181 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 182 | * Called by managed code to create and deliver a StackOverflowError. |
| 183 | */ |
| 184 | NO_ARG_RUNTIME_EXCEPTION art_throw_stack_overflow_from_code, artThrowStackOverflowFromCode |
| 185 | |
| 186 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 187 | * Called by managed code, saves callee saves and then calls artThrowException |
| 188 | * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. |
| 189 | */ |
| 190 | ONE_ARG_RUNTIME_EXCEPTION art_deliver_exception_from_code, artDeliverExceptionFromCode |
| 191 | |
| 192 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 193 | * Called by managed code to create and deliver a NoSuchMethodError. |
| 194 | */ |
| 195 | ONE_ARG_RUNTIME_EXCEPTION art_throw_no_such_method_from_code, artThrowNoSuchMethodFromCode |
| 196 | |
| 197 | /* |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 198 | * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds |
| 199 | * index, arg2 holds limit. |
| 200 | */ |
| 201 | TWO_ARG_RUNTIME_EXCEPTION art_throw_array_bounds_from_code, artThrowArrayBoundsFromCode |
| 202 | |
| 203 | /* |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 204 | * Called by managed code to create and deliver verification errors. Arg1 is kind, arg2 is ref. |
| 205 | */ |
| 206 | TWO_ARG_RUNTIME_EXCEPTION art_throw_verification_error_from_code, artThrowVerificationErrorFromCode |
| 207 | |
| 208 | /* |
| 209 | * All generated callsites for interface invokes and invocation slow paths will load arguments |
| 210 | * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain |
| 211 | * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the |
| 212 | * stack and call the appropriate C helper. |
| 213 | * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1. |
| 214 | * |
| 215 | * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting |
| 216 | * of the target Method* in r0 and method->code_ in r1. |
| 217 | * |
| 218 | * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the |
| 219 | * thread and we branch to another stub to deliver it. |
| 220 | * |
| 221 | * On success this wrapper will restore arguments and *jump* to the target, leaving the lr |
| 222 | * pointing back to the original caller. |
| 223 | */ |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 224 | MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name) |
| 225 | .globl VAR(c_name, 0) |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 226 | ALIGN_FUNCTION_ENTRY |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 227 | VAR(c_name, 0): |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 228 | // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs) |
| 229 | // return address |
| 230 | pushl %edi |
| 231 | pushl %esi |
| 232 | pushl %ebp |
| 233 | pushl %ebx |
| 234 | pushl %edx |
| 235 | pushl %ecx |
| 236 | pushl %eax // <-- callee save Method* to go here |
| 237 | movl %esp, %edx // remember SP |
| 238 | // Outgoing argument set up |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 239 | subl MACRO_LITERAL(12), %esp // alignment padding |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 240 | pushl %edx // pass SP |
| 241 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 242 | pushl 32(%edx) // pass caller Method* |
| 243 | pushl %ecx // pass arg2 |
| 244 | pushl %eax // pass arg1 |
| 245 | call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP) |
| 246 | movl %edx, %edi // save code pointer in EDI |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 247 | addl MACRO_LITERAL(36), %esp // Pop arguments skip eax |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 248 | popl %ecx // Restore args |
| 249 | popl %edx |
| 250 | popl %ebx |
| 251 | popl %ebp // Restore callee saves. |
| 252 | popl %esi |
| 253 | // Swap EDI callee save with code pointer. |
| 254 | xchgl %edi, (%esp) |
| 255 | testl %eax, %eax // Branch forward if exception pending. |
| 256 | jz 1f |
| 257 | // Tail call to intended method. |
| 258 | ret |
| 259 | 1: |
| 260 | DELIVER_PENDING_EXCEPTION |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 261 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 262 | |
| 263 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline, artInvokeInterfaceTrampoline |
| 264 | INVOKE_TRAMPOLINE art_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck |
| 265 | |
| 266 | INVOKE_TRAMPOLINE art_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck |
| 267 | INVOKE_TRAMPOLINE art_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck |
| 268 | INVOKE_TRAMPOLINE art_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck |
| 269 | INVOKE_TRAMPOLINE art_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck |
| 270 | |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 271 | MACRO2(TWO_ARG_ALLOC, c_name, cxx_name) |
| 272 | .globl VAR(c_name, 0) |
| 273 | ALIGN_FUNCTION_ENTRY |
| 274 | VAR(c_name, 0): |
| 275 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 276 | mov %esp, %edx // remember SP |
| 277 | // Outgoing argument set up |
| 278 | pushl %edx // pass SP |
| 279 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 280 | pushl %ecx // pass arg2 |
| 281 | pushl %eax // pass arg1 |
| 282 | call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP) |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 283 | addl MACRO_LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 284 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 285 | testl %eax, %eax // eax == 0 ? |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 286 | jz 1f |
| 287 | ret |
| 288 | 1: |
| 289 | DELIVER_PENDING_EXCEPTION |
| 290 | END_MACRO |
| 291 | |
| 292 | MACRO2(THREE_ARG_ALLOC, c_name, cxx_name) |
| 293 | .globl VAR(c_name, 0) |
| 294 | ALIGN_FUNCTION_ENTRY |
| 295 | VAR(c_name, 0): |
| 296 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 297 | mov %esp, %ebx // remember SP |
| 298 | // Outgoing argument set up |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 299 | subl MACRO_LITERAL(12), %esp // alignment padding |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 300 | pushl %ebx // pass SP |
| 301 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 302 | pushl %edx // pass arg3 |
| 303 | pushl %ecx // pass arg2 |
| 304 | pushl %eax // pass arg1 |
| 305 | call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP) |
Elliott Hughes | ea94421 | 2012-04-05 13:11:53 -0700 | [diff] [blame] | 306 | addl MACRO_LITERAL(32), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 307 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
| 308 | testl %eax, %eax // eax == 0 ? |
| 309 | jz 1f |
| 310 | ret |
| 311 | 1: |
| 312 | DELIVER_PENDING_EXCEPTION |
| 313 | END_MACRO |
| 314 | |
| 315 | TWO_ARG_ALLOC art_alloc_object_from_code, artAllocObjectFromCode |
| 316 | TWO_ARG_ALLOC art_alloc_object_from_code_with_access_check, artAllocObjectFromCodeWithAccessCheck |
| 317 | THREE_ARG_ALLOC art_alloc_array_from_code, artAllocArrayFromCode |
| 318 | THREE_ARG_ALLOC art_alloc_array_from_code_with_access_check, artAllocArrayFromCodeWithAccessCheck |
| 319 | THREE_ARG_ALLOC art_check_and_alloc_array_from_code, artCheckAndAllocArrayFromCode |
| 320 | THREE_ARG_ALLOC art_check_and_alloc_array_from_code_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck |
| 321 | |
| 322 | TWO_ARG_ALLOC art_resolve_string_from_code, artResolveStringFromCode |
| 323 | TWO_ARG_ALLOC art_initialize_static_storage_from_code, artInitializeStaticStorageFromCode |
| 324 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 325 | DEFINE_FUNCTION art_lock_object_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 326 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 327 | mov %esp, %edx // remember SP |
| 328 | // Outgoing argument set up |
| 329 | pushl %eax // alignment padding |
| 330 | pushl %edx // pass SP |
| 331 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 332 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 333 | call SYMBOL(artLockObjectFromCode) // (Object*, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 334 | addl LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 335 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
| 336 | ret |
| 337 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 338 | DEFINE_FUNCTION art_unlock_object_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 339 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 340 | mov %esp, %edx // remember SP |
| 341 | // Outgoing argument set up |
| 342 | pushl %eax // alignment padding |
| 343 | pushl %edx // pass SP |
| 344 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 345 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 346 | call SYMBOL(artUnlockObjectFromCode) // (Object*, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 347 | addl LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 348 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 349 | testl %eax, %eax // eax == 0 ? |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 350 | jnz 1f |
| 351 | ret |
| 352 | 1: |
| 353 | DELIVER_PENDING_EXCEPTION |
| 354 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 355 | DEFINE_FUNCTION art_handle_fill_data_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 356 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 357 | mov %esp, %edx // remember SP |
| 358 | // Outgoing argument set up |
| 359 | pushl %edx // pass SP |
| 360 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 361 | pushl %ecx // pass arg2 |
| 362 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 363 | call SYMBOL(artHandleFillArrayDataFromCode) // (Array* array, const uint16_t* table, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 364 | addl LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 365 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 366 | testl %eax, %eax // eax == 0 ? |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 367 | jnz 1f |
| 368 | ret |
| 369 | 1: |
| 370 | DELIVER_PENDING_EXCEPTION |
| 371 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 372 | DEFINE_FUNCTION art_is_assignable_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 373 | pushl %eax // alignment padding |
| 374 | pushl %ecx // pass arg2 |
| 375 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 376 | call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 377 | addl LITERAL(12), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 378 | ret |
| 379 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 380 | DEFINE_FUNCTION art_memcpy |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 381 | pushl %edx // pass arg3 |
| 382 | pushl %ecx // pass arg2 |
| 383 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 384 | call SYMBOL(memcpy) // (void*, const void*, size_t) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 385 | addl LITERAL(12), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 386 | ret |
| 387 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 388 | DEFINE_FUNCTION art_check_cast_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 389 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 390 | mov %esp, %edx // remember SP |
| 391 | // Outgoing argument set up |
| 392 | pushl %edx // pass SP |
| 393 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 394 | pushl %ecx // pass arg2 |
| 395 | pushl %eax // pass arg1 |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 396 | call SYMBOL(artCheckCastFromCode) // (Class* a, Class* b, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 397 | addl LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 398 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 399 | testl %eax, %eax // eax == 0 ? |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 400 | jnz 1f |
| 401 | ret |
| 402 | 1: |
| 403 | DELIVER_PENDING_EXCEPTION |
| 404 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 405 | DEFINE_FUNCTION art_idiv_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 406 | cdq // edx:eax = sign extend eax |
| 407 | idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx) |
| 408 | ret |
| 409 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 410 | DEFINE_FUNCTION art_idivmod_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 411 | cdq // edx:eax = sign extend eax |
| 412 | idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx) |
| 413 | movl %eax, %edx |
| 414 | ret |
| 415 | |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 416 | DEFINE_FUNCTION art_ldiv_from_code |
Ian Rogers | 141d622 | 2012-04-05 12:23:06 -0700 | [diff] [blame^] | 417 | subl LITERAL(12), %esp // alignment padding |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 418 | pushl %ebx // pass arg4 |
| 419 | pushl %edx // pass arg3 |
| 420 | pushl %ecx // pass arg2 |
| 421 | pushl %eax // pass arg1 |
| 422 | call SYMBOL(artLdivFromCode) // (jlong a, jlong b, Thread*, SP) |
| 423 | addl LITERAL(28), %esp // pop arguments |
| 424 | ret |
| 425 | |
| 426 | DEFINE_FUNCTION art_ldivmod_from_code |
Ian Rogers | 141d622 | 2012-04-05 12:23:06 -0700 | [diff] [blame^] | 427 | subl LITERAL(12), %esp // alignment padding |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 428 | pushl %ebx // pass arg4 |
| 429 | pushl %edx // pass arg3 |
| 430 | pushl %ecx // pass arg2 |
| 431 | pushl %eax // pass arg1 |
| 432 | call SYMBOL(artLdivmodFromCode) // (jlong a, jlong b, Thread*, SP) |
| 433 | addl LITERAL(28), %esp // pop arguments |
| 434 | ret |
| 435 | |
Ian Rogers | 141d622 | 2012-04-05 12:23:06 -0700 | [diff] [blame^] | 436 | DEFINE_FUNCTION art_lshl_from_code |
| 437 | // eax:ecx << edx |
| 438 | xchg %edx, %ecx |
| 439 | shld %cl,%eax,%edx |
| 440 | shl %cl,%eax |
| 441 | test LITERAL(32), %cl |
| 442 | jz 1f |
| 443 | mov %eax, %edx |
| 444 | xor %eax, %eax |
| 445 | 1: |
| 446 | ret |
| 447 | |
| 448 | DEFINE_FUNCTION art_lshr_from_code |
| 449 | // eax:ecx >> edx |
| 450 | xchg %edx, %ecx |
| 451 | shrd %cl,%eax,%edx |
| 452 | sar %cl,%eax |
| 453 | test LITERAL(32),%cl |
| 454 | jz 1f |
| 455 | mov %edx, %eax |
| 456 | sar LITERAL(31), %edx |
| 457 | 1: |
| 458 | ret |
| 459 | |
| 460 | DEFINE_FUNCTION art_lushr_from_code |
| 461 | // eax:ecx >>> edx |
| 462 | xchg %edx, %ecx |
| 463 | shrd %cl,%eax,%edx |
| 464 | shr %cl,%eax |
| 465 | test $0x20,%cl |
| 466 | jz 1f |
| 467 | mov %edx, %eax |
| 468 | xor %edx, %edx |
| 469 | 1: |
| 470 | ret |
| 471 | |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 472 | DEFINE_FUNCTION art_can_put_array_element_from_code |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 473 | test %eax, %eax // Null is trivially storable |
| 474 | jz 1f |
| 475 | SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC |
| 476 | mov %esp, %edx // remember SP |
| 477 | // Outgoing argument set up |
| 478 | pushl %edx // pass SP |
| 479 | pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current() |
| 480 | pushl %ecx // pass arg2 |
| 481 | pushl %eax // pass arg1 |
Elliott Hughes | adc078a | 2012-04-04 11:39:05 -0700 | [diff] [blame] | 482 | call SYMBOL(artCanPutArrayElementFromCode) // (Object* element, Class* array_class, Thread*, SP) |
Ian Rogers | 55bd45f | 2012-04-04 17:31:20 -0700 | [diff] [blame] | 483 | addl LITERAL(16), %esp // pop arguments |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 484 | RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address |
Elliott Hughes | 5e28422 | 2012-04-04 13:38:03 -0700 | [diff] [blame] | 485 | testl %eax, %eax // eax == 0 ? |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 486 | jnz 2f |
| 487 | 1: |
| 488 | ret |
| 489 | 2: |
| 490 | DELIVER_PENDING_EXCEPTION |
| 491 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 492 | MACRO1(UNIMPLEMENTED,name) |
| 493 | .globl VAR(name, 0) |
| 494 | ALIGN_FUNCTION_ENTRY |
| 495 | VAR(name, 0): |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 496 | int3 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 497 | END_MACRO |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 498 | |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 499 | // TODO: implement these! |
| 500 | UNIMPLEMENTED art_proxy_invoke_handler |
| 501 | UNIMPLEMENTED art_update_debugger |
| 502 | UNIMPLEMENTED art_test_suspend |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 503 | UNIMPLEMENTED art_initialize_type_and_verify_access_from_code |
| 504 | UNIMPLEMENTED art_initialize_type_from_code |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 505 | UNIMPLEMENTED art_set32_instance_from_code |
| 506 | UNIMPLEMENTED art_set64_instance_from_code |
| 507 | UNIMPLEMENTED art_set_obj_instance_from_code |
| 508 | UNIMPLEMENTED art_get32_instance_from_code |
| 509 | UNIMPLEMENTED art_get64_instance_from_code |
| 510 | UNIMPLEMENTED art_get_obj_instance_from_code |
| 511 | UNIMPLEMENTED art_set32_static_from_code |
| 512 | UNIMPLEMENTED art_set64_static_from_code |
| 513 | UNIMPLEMENTED art_set_obj_static_from_code |
| 514 | UNIMPLEMENTED art_get32_static_from_code |
| 515 | UNIMPLEMENTED art_get64_static_from_code |
| 516 | UNIMPLEMENTED art_get_obj_static_from_code |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 517 | UNIMPLEMENTED art_indexof |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 518 | UNIMPLEMENTED art_memcmp16 |
Elliott Hughes | 787ec20 | 2012-03-29 17:14:15 -0700 | [diff] [blame] | 519 | UNIMPLEMENTED art_string_compareto |