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