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