blob: ee78d45793568cc53f85caa61bdc04189b6f6ba3 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
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 Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_x86.S"
Elliott Hughes5e284222012-04-04 13:38:03 -070018
Dave Allisonbbb32c22013-11-05 18:25:18 -080019// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
20
Ian Rogers57b86d42012-03-27 16:05:41 -070021 /*
22 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070023 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070024 */
Elliott Hughes787ec202012-03-29 17:14:15 -070025MACRO0(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080026 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080027 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080028 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080029 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080030 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080031 .cfi_rel_offset ebp, -16
Elliott Hughesea944212012-04-05 13:11:53 -070032 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080033 .cfi_adjust_cfa_offset 16
Elliott Hughes787ec202012-03-29 17:14:15 -070034END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070035
Ian Rogers7caad772012-03-30 01:07:54 -070036 /*
37 * Macro that sets up the callee save frame to conform with
38 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
39 */
40MACRO0(SETUP_REF_ONLY_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080041 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080042 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080043 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080044 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080045 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080046 .cfi_rel_offset ebp, -16
Elliott Hughesea944212012-04-05 13:11:53 -070047 subl MACRO_LITERAL(16), %esp // Grow stack by 4 words, bottom word will hold Method*
Ian Rogersaeeada42013-02-13 11:28:34 -080048 .cfi_adjust_cfa_offset 16
Ian Rogers7caad772012-03-30 01:07:54 -070049END_MACRO
50
51MACRO0(RESTORE_REF_ONLY_CALLEE_SAVE_FRAME)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070052 addl MACRO_LITERAL(16), %esp // Unwind stack up to return address
53 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
Dave Allisonbbb32c22013-11-05 18:25:18 -080054 .cfi_restore ebp
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070055 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080056 .cfi_restore esi
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070057 POP edi
Dave Allisonbbb32c22013-11-05 18:25:18 -080058 .cfi_restore edi
Ian Rogersaeeada42013-02-13 11:28:34 -080059 .cfi_adjust_cfa_offset -28
Elliott Hughes787ec202012-03-29 17:14:15 -070060END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070061
62 /*
63 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070064 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070065 */
jeffhao9dbb23e2012-05-18 17:03:57 -070066MACRO0(SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Ian Rogersaeeada42013-02-13 11:28:34 -080067 PUSH edi // Save callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080068 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -080069 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080070 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -080071 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -080072 .cfi_rel_offset ebp, -16
Ian Rogersaeeada42013-02-13 11:28:34 -080073 PUSH ebx // Save args
Dave Allisonbbb32c22013-11-05 18:25:18 -080074 .cfi_rel_offset ebx, -20
Ian Rogersaeeada42013-02-13 11:28:34 -080075 PUSH edx
Dave Allisonbbb32c22013-11-05 18:25:18 -080076 .cfi_rel_offset edx, -24
Ian Rogersaeeada42013-02-13 11:28:34 -080077 PUSH ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -080078 .cfi_rel_offset ecx, -28
Ian Rogersaeeada42013-02-13 11:28:34 -080079 PUSH eax // Align stack, eax will be clobbered by Method*
Dave Allisonbbb32c22013-11-05 18:25:18 -080080 .cfi_rel_offset eax, -28
Elliott Hughes787ec202012-03-29 17:14:15 -070081END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070082
jeffhao9dbb23e2012-05-18 17:03:57 -070083MACRO0(RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME)
Elliott Hughesea944212012-04-05 13:11:53 -070084 addl MACRO_LITERAL(4), %esp // Remove padding
Ian Rogersaeeada42013-02-13 11:28:34 -080085 .cfi_adjust_cfa_offset -4
86 POP ecx // Restore args except eax
Dave Allisonbbb32c22013-11-05 18:25:18 -080087 .cfi_restore ecx
Ian Rogersaeeada42013-02-13 11:28:34 -080088 POP edx
Dave Allisonbbb32c22013-11-05 18:25:18 -080089 .cfi_restore edx
Ian Rogersaeeada42013-02-13 11:28:34 -080090 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -080091 .cfi_restore ebx
Ian Rogersaeeada42013-02-13 11:28:34 -080092 POP ebp // Restore callee saves
Dave Allisonbbb32c22013-11-05 18:25:18 -080093 .cfi_restore ebp
Ian Rogersaeeada42013-02-13 11:28:34 -080094 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -080095 .cfi_restore esi
Ian Rogersaeeada42013-02-13 11:28:34 -080096 POP edi
Dave Allisonbbb32c22013-11-05 18:25:18 -080097 .cfi_restore edi
Elliott Hughes787ec202012-03-29 17:14:15 -070098END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070099
100 /*
101 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
102 * exception is Thread::Current()->exception_.
103 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700104MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers57b86d42012-03-27 16:05:41 -0700105 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save callee saves for throw
106 mov %esp, %ecx
107 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700108 subl MACRO_LITERAL(8), %esp // Alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800109 .cfi_adjust_cfa_offset 8
110 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700111 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800112 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700113 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*, SP)
114 int3 // unreached
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
Elliott Hughes787ec202012-03-29 17:14:15 -0700117MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800118 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700119 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
120 mov %esp, %ecx
121 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700122 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800123 .cfi_adjust_cfa_offset 8
124 PUSH ecx // pass SP
Ian Rogers55bd45f2012-04-04 17:31:20 -0700125 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800126 .cfi_adjust_cfa_offset 4
Elliott Hughes787ec202012-03-29 17:14:15 -0700127 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700128 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800129 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700130END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700131
Elliott Hughes787ec202012-03-29 17:14:15 -0700132MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800133 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700134 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
135 mov %esp, %ecx
136 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800137 PUSH eax // alignment padding
138 PUSH ecx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700139 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800140 .cfi_adjust_cfa_offset 4
141 PUSH eax // pass arg1
Elliott Hughes787ec202012-03-29 17:14:15 -0700142 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700143 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800144 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700145END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700146
Elliott Hughes787ec202012-03-29 17:14:15 -0700147MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800148 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers57b86d42012-03-27 16:05:41 -0700149 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
150 mov %esp, %edx
151 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800152 PUSH edx // pass SP
Ian Rogers57b86d42012-03-27 16:05:41 -0700153 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800154 .cfi_adjust_cfa_offset 4
155 PUSH ecx // pass arg2
156 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700157 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers57b86d42012-03-27 16:05:41 -0700158 int3 // unreached
Ian Rogersaeeada42013-02-13 11:28:34 -0800159 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700160END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700161
162 /*
163 * Called by managed code to create and deliver a NullPointerException.
164 */
Ian Rogers468532e2013-08-05 10:56:33 -0700165NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
167 /*
168 * Called by managed code to create and deliver an ArithmeticException.
169 */
Ian Rogers468532e2013-08-05 10:56:33 -0700170NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700171
172 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700173 * Called by managed code to create and deliver a StackOverflowError.
174 */
Ian Rogers468532e2013-08-05 10:56:33 -0700175NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700176
177 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700178 * Called by managed code, saves callee saves and then calls artThrowException
179 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
180 */
Ian Rogers468532e2013-08-05 10:56:33 -0700181ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700182
183 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700184 * Called by managed code to create and deliver a NoSuchMethodError.
185 */
Ian Rogers468532e2013-08-05 10:56:33 -0700186ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700187
188 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700189 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
190 * index, arg2 holds limit.
191 */
Ian Rogers468532e2013-08-05 10:56:33 -0700192TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700193
194 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700195 * All generated callsites for interface invokes and invocation slow paths will load arguments
196 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
197 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
198 * stack and call the appropriate C helper.
199 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
200 *
201 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
202 * of the target Method* in r0 and method->code_ in r1.
203 *
204 * If unsuccessful, the helper will return NULL/NULL. There will bea pending exception in the
205 * thread and we branch to another stub to deliver it.
206 *
207 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
208 * pointing back to the original caller.
209 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700210MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Ian Rogersaeeada42013-02-13 11:28:34 -0800211 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700212 // Set up the callee save frame to conform with Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
213 // return address
Ian Rogersaeeada42013-02-13 11:28:34 -0800214 PUSH edi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800215 .cfi_rel_offset edi, -8
Ian Rogersaeeada42013-02-13 11:28:34 -0800216 PUSH esi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800217 .cfi_rel_offset esi, -12
Ian Rogersaeeada42013-02-13 11:28:34 -0800218 PUSH ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800219 .cfi_rel_offset ebp, -16
220 PUSH ebx // Save args
221 .cfi_rel_offset ebx, -20
Ian Rogersaeeada42013-02-13 11:28:34 -0800222 PUSH edx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800223 .cfi_rel_offset edx, -24
Ian Rogersaeeada42013-02-13 11:28:34 -0800224 PUSH ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800225 .cfi_rel_offset ecx, -28
226 PUSH eax // <-- callee save Method* to go here
227 .cfi_rel_offset eax, -32
Ian Rogers7caad772012-03-30 01:07:54 -0700228 movl %esp, %edx // remember SP
229 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700230 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800231 .cfi_adjust_cfa_offset 12
232 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700233 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800234 .cfi_adjust_cfa_offset 4
Ian Rogers7caad772012-03-30 01:07:54 -0700235 pushl 32(%edx) // pass caller Method*
Ian Rogersaeeada42013-02-13 11:28:34 -0800236 .cfi_adjust_cfa_offset 4
237 PUSH ecx // pass arg2
238 PUSH eax // pass arg1
Ian Rogers7caad772012-03-30 01:07:54 -0700239 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
240 movl %edx, %edi // save code pointer in EDI
Elliott Hughesea944212012-04-05 13:11:53 -0700241 addl MACRO_LITERAL(36), %esp // Pop arguments skip eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800242 .cfi_adjust_cfa_offset -36
Dave Allisonbbb32c22013-11-05 18:25:18 -0800243 POP ecx // Restore args except eax
244 .cfi_restore ecx
Ian Rogersaeeada42013-02-13 11:28:34 -0800245 POP edx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800246 .cfi_restore edx
Ian Rogersaeeada42013-02-13 11:28:34 -0800247 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800248 .cfi_restore ebx
249 POP ebp // Restore callee saves
250 .cfi_restore ebp
Ian Rogersaeeada42013-02-13 11:28:34 -0800251 POP esi
Dave Allisonbbb32c22013-11-05 18:25:18 -0800252 .cfi_restore esi
Ian Rogers7caad772012-03-30 01:07:54 -0700253 // 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
2591:
jeffhao20b5c6c2012-05-21 14:15:18 -0700260 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Ian Rogers5793fea2013-02-14 13:33:34 -0800261 .cfi_adjust_cfa_offset -4
Ian Rogers7caad772012-03-30 01:07:54 -0700262 DELIVER_PENDING_EXCEPTION
Ian Rogersaeeada42013-02-13 11:28:34 -0800263 END_FUNCTION VAR(c_name, 0)
Elliott Hughes787ec202012-03-29 17:14:15 -0700264END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700265
Logan Chien8dbb7082013-01-25 20:31:17 +0800266INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
267INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700268
Logan Chien8dbb7082013-01-25 20:31:17 +0800269INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
270INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
271INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
272INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700273
Jeff Hao5d917302013-02-27 17:57:33 -0800274 /*
Jeff Hao6474d192013-03-26 14:08:09 -0700275 * Quick invocation stub.
276 * On entry:
277 * [sp] = return address
278 * [sp + 4] = method pointer
279 * [sp + 8] = argument array or NULL for no argument methods
280 * [sp + 12] = size of argument array in bytes
281 * [sp + 16] = (managed) thread pointer
282 * [sp + 20] = JValue* result
283 * [sp + 24] = result type char
Jeff Hao5d917302013-02-27 17:57:33 -0800284 */
285DEFINE_FUNCTION art_quick_invoke_stub
286 PUSH ebp // save ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800287 .cfi_rel_offset ebp, -8
Jeff Hao5d917302013-02-27 17:57:33 -0800288 PUSH ebx // save ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800289 .cfi_rel_offset ebx, -12
Jeff Hao5d917302013-02-27 17:57:33 -0800290 mov %esp, %ebp // copy value of stack pointer into base pointer
291 .cfi_def_cfa_register ebp
292 mov 20(%ebp), %ebx // get arg array size
293 addl LITERAL(28), %ebx // reserve space for return addr, method*, ebx, and ebp in frame
Jeff Hao6474d192013-03-26 14:08:09 -0700294 andl LITERAL(0xFFFFFFF0), %ebx // align frame size to 16 bytes
Jeff Hao5d917302013-02-27 17:57:33 -0800295 subl LITERAL(12), %ebx // remove space for return address, ebx, and ebp
296 subl %ebx, %esp // reserve stack space for argument array
297 lea 4(%esp), %eax // use stack pointer + method ptr as dest for memcpy
298 pushl 20(%ebp) // push size of region to memcpy
299 pushl 16(%ebp) // push arg array as source of memcpy
300 pushl %eax // push stack pointer as destination of memcpy
301 call SYMBOL(memcpy) // (void*, const void*, size_t)
302 addl LITERAL(12), %esp // pop arguments to memcpy
303 movl LITERAL(0), (%esp) // store NULL for method*
304 mov 12(%ebp), %eax // move method pointer into eax
305 mov 4(%esp), %ecx // copy arg1 into ecx
306 mov 8(%esp), %edx // copy arg2 into edx
307 mov 12(%esp), %ebx // copy arg3 into ebx
Ian Rogers225ade22013-03-18 17:45:44 -0700308 call *METHOD_CODE_OFFSET(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800309 mov %ebp, %esp // restore stack pointer
Dave Allisonbbb32c22013-11-05 18:25:18 -0800310 .cfi_def_cfa_register esp
Jeff Hao5d917302013-02-27 17:57:33 -0800311 POP ebx // pop ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800312 .cfi_restore ebx
Jeff Hao5d917302013-02-27 17:57:33 -0800313 POP ebp // pop ebp
Dave Allisonbbb32c22013-11-05 18:25:18 -0800314 .cfi_restore ebp
Jeff Hao5d917302013-02-27 17:57:33 -0800315 mov 20(%esp), %ecx // get result pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700316 cmpl LITERAL(68), 24(%esp) // test if result type char == 'D'
317 je return_double_quick
318 cmpl LITERAL(70), 24(%esp) // test if result type char == 'F'
319 je return_float_quick
Jeff Hao5d917302013-02-27 17:57:33 -0800320 mov %eax, (%ecx) // store the result
321 mov %edx, 4(%ecx) // store the other half of the result
Jeff Hao6474d192013-03-26 14:08:09 -0700322 ret
323return_double_quick:
324return_float_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800325 movsd %xmm0, (%ecx) // store the floating point result
326 ret
327END_FUNCTION art_quick_invoke_stub
328
Ian Rogersd36c52e2012-04-09 16:29:25 -0700329MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800330 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700331 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
332 mov %esp, %edx // remember SP
333 // Outgoing argument set up
334 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800335 .cfi_adjust_cfa_offset 8
336 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700337 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800338 .cfi_adjust_cfa_offset 4
Ian Rogersd36c52e2012-04-09 16:29:25 -0700339 call VAR(cxx_name, 1) // cxx_name(Thread*, SP)
340 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800341 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700342 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700343 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800344 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700345END_MACRO
346
347MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800348 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700349 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
350 mov %esp, %edx // remember SP
351 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800352 PUSH eax // push padding
353 PUSH edx // pass SP
Ian Rogersd36c52e2012-04-09 16:29:25 -0700354 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800355 .cfi_adjust_cfa_offset 4
356 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700357 call VAR(cxx_name, 1) // cxx_name(arg1, Thread*, SP)
358 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800359 .cfi_adjust_cfa_offset -16
Ian Rogersd36c52e2012-04-09 16:29:25 -0700360 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700361 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800362 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700363END_MACRO
364
365MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800366 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700367 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
368 mov %esp, %edx // remember SP
369 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800370 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700371 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800372 .cfi_adjust_cfa_offset 4
373 PUSH ecx // pass arg2
374 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700375 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700376 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800377 .cfi_adjust_cfa_offset -16
Ian Rogers7caad772012-03-30 01:07:54 -0700378 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700379 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800380 END_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700381END_MACRO
382
Ian Rogersd36c52e2012-04-09 16:29:25 -0700383MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Ian Rogersaeeada42013-02-13 11:28:34 -0800384 DEFINE_FUNCTION VAR(c_name, 0)
Ian Rogers7caad772012-03-30 01:07:54 -0700385 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
386 mov %esp, %ebx // remember SP
387 // Outgoing argument set up
Elliott Hughesea944212012-04-05 13:11:53 -0700388 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800389 .cfi_adjust_cfa_offset 12
390 PUSH ebx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700391 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800392 .cfi_adjust_cfa_offset 4
393 PUSH edx // pass arg3
394 PUSH ecx // pass arg2
395 PUSH eax // pass arg1
Ian Rogersd36c52e2012-04-09 16:29:25 -0700396 call VAR(cxx_name, 1) // cxx_name(arg1, arg2, arg3, Thread*, SP)
Elliott Hughesea944212012-04-05 13:11:53 -0700397 addl MACRO_LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800398 .cfi_adjust_cfa_offset -32
Ian Rogers7caad772012-03-30 01:07:54 -0700399 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Elliott Hughes754caaa2012-04-10 10:57:36 -0700400 CALL_MACRO(return_macro, 2) // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -0800401 END_FUNCTION VAR(c_name, 0)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700402END_MACRO
403
404MACRO0(RETURN_IF_EAX_NOT_ZERO)
Ian Rogers7caad772012-03-30 01:07:54 -0700405 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700406 jz 1f // if eax == 0 goto 1
407 ret // return
4081: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700409 DELIVER_PENDING_EXCEPTION
410END_MACRO
411
Ian Rogersd36c52e2012-04-09 16:29:25 -0700412MACRO0(RETURN_IF_EAX_ZERO)
413 testl %eax, %eax // eax == 0 ?
414 jnz 1f // if eax != 0 goto 1
415 ret // return
4161: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700417 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700418END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700419
jeffhaod66a8752012-05-22 15:30:16 -0700420MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
421 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx // get exception field
422 testl %ebx, %ebx // ebx == 0 ?
423 jnz 1f // if ebx != 0 goto 1
424 ret // return
4251: // deliver exception on current thread
426 DELIVER_PENDING_EXCEPTION
427END_MACRO
428
Ian Rogers468532e2013-08-05 10:56:33 -0700429TWO_ARG_DOWNCALL art_quick_alloc_object, artAllocObjectFromCode, RETURN_IF_EAX_NOT_ZERO
430TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check, artAllocObjectFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
431THREE_ARG_DOWNCALL art_quick_alloc_array, artAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
432THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check, artAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
433THREE_ARG_DOWNCALL art_quick_check_and_alloc_array, artCheckAndAllocArrayFromCode, RETURN_IF_EAX_NOT_ZERO
434THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check, artCheckAndAllocArrayFromCodeWithAccessCheck, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700435
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700436TWO_ARG_DOWNCALL art_quick_alloc_object_instrumented, artAllocObjectFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
437TWO_ARG_DOWNCALL art_quick_alloc_object_with_access_check_instrumented, artAllocObjectFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
438THREE_ARG_DOWNCALL art_quick_alloc_array_instrumented, artAllocArrayFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
439THREE_ARG_DOWNCALL art_quick_alloc_array_with_access_check_instrumented, artAllocArrayFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
440THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_instrumented, artCheckAndAllocArrayFromCodeInstrumented, RETURN_IF_EAX_NOT_ZERO
441THREE_ARG_DOWNCALL art_quick_check_and_alloc_array_with_access_check_instrumented, artCheckAndAllocArrayFromCodeWithAccessCheckInstrumented, RETURN_IF_EAX_NOT_ZERO
442
Ian Rogers468532e2013-08-05 10:56:33 -0700443TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_EAX_NOT_ZERO
444TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_EAX_NOT_ZERO
445TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_EAX_NOT_ZERO
446TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_EAX_NOT_ZERO
Ian Rogersd36c52e2012-04-09 16:29:25 -0700447
Ian Rogers468532e2013-08-05 10:56:33 -0700448TWO_ARG_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700449
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700450DEFINE_FUNCTION art_quick_lock_object
451 testl %eax, %eax // null check object/eax
452 jz slow_lock
453retry_lock:
454 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700455 test LITERAL(0xC0000000), %ecx // test the 2 high bits.
456 jne slow_lock // slow path if either of the two high bits are set.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700457 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
458 test %ecx, %ecx
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700459 jnz already_thin // lock word contains a thin lock
460 // unlocked case - %edx holds thread id with count of 0
461 movl %eax, %ecx // remember object in case of retry
462 xor %eax, %eax // eax == 0 for comparison with lock word in cmpxchg
463 lock cmpxchg %edx, LOCK_WORD_OFFSET(%ecx)
464 jnz cmpxchg_fail // cmpxchg failed retry
465 ret
466cmpxchg_fail:
467 movl %ecx, %eax // restore eax
468 jmp retry_lock
469already_thin:
470 cmpw %ax, %dx // do we hold the lock already?
471 jne slow_lock
472 addl LITERAL(65536), %eax // increment recursion count
Mathieu Chartierad2541a2013-10-25 10:05:23 -0700473 test LITERAL(0xC0000000), %eax // overflowed if either of top two bits are set
474 jne slow_lock // count overflowed so go slow
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700475 movl %eax, LOCK_WORD_OFFSET(%ecx) // update lockword, cmpxchg not necessary as we hold lock
476 ret
477slow_lock:
478 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
479 mov %esp, %edx // remember SP
480 // Outgoing argument set up
481 PUSH eax // push padding
482 PUSH edx // pass SP
483 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
484 .cfi_adjust_cfa_offset 4
485 PUSH eax // pass object
486 call artLockObjectFromCode // artLockObjectFromCode(object, Thread*, SP)
487 addl MACRO_LITERAL(16), %esp // pop arguments
488 .cfi_adjust_cfa_offset -16
489 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
490 RETURN_IF_EAX_ZERO
491END_FUNCTION art_quick_lock_object
492
493DEFINE_FUNCTION art_quick_unlock_object
494 testl %eax, %eax // null check object/eax
495 jz slow_unlock
496 movl LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
497 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
498 test %ecx, %ecx
499 jb slow_unlock // lock word contains a monitor
500 cmpw %cx, %dx // does the thread id match?
501 jne slow_unlock
502 cmpl LITERAL(65536), %ecx
503 jae recursive_thin_unlock
504 movl LITERAL(0), LOCK_WORD_OFFSET(%eax)
505 ret
506recursive_thin_unlock:
507 subl LITERAL(65536), %ecx
508 mov %ecx, LOCK_WORD_OFFSET(%eax)
509 ret
510slow_unlock:
511 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
512 mov %esp, %edx // remember SP
513 // Outgoing argument set up
514 PUSH eax // push padding
515 PUSH edx // pass SP
516 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
517 .cfi_adjust_cfa_offset 4
518 PUSH eax // pass object
519 call artUnlockObjectFromCode // artUnlockObjectFromCode(object, Thread*, SP)
520 addl MACRO_LITERAL(16), %esp // pop arguments
521 .cfi_adjust_cfa_offset -16
522 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
523 RETURN_IF_EAX_ZERO
524END_FUNCTION art_quick_unlock_object
525
Ian Rogers468532e2013-08-05 10:56:33 -0700526DEFINE_FUNCTION art_quick_is_assignable
Ian Rogersaeeada42013-02-13 11:28:34 -0800527 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -0700528 PUSH ecx // pass arg2 - obj->klass
529 PUSH eax // pass arg1 - checked class
530 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700531 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800532 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700533 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700534END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -0700535
Ian Rogersa9a82542013-10-04 11:17:26 -0700536DEFINE_FUNCTION art_quick_check_cast
537 PUSH eax // alignment padding
538 PUSH ecx // pass arg2 - obj->klass
Dave Allisonbbb32c22013-11-05 18:25:18 -0800539 .cfi_rel_offset ecx, -12
Ian Rogersa9a82542013-10-04 11:17:26 -0700540 PUSH eax // pass arg1 - checked class
Dave Allisonbbb32c22013-11-05 18:25:18 -0800541 .cfi_rel_offset eax, -16
Ian Rogersa9a82542013-10-04 11:17:26 -0700542 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
543 testl %eax, %eax
544 jz 1f // jump forward if not assignable
545 addl LITERAL(12), %esp // pop arguments
546 .cfi_adjust_cfa_offset -12
547 ret
5481:
549 POP eax // pop arguments
Dave Allisonbbb32c22013-11-05 18:25:18 -0800550 .cfi_restore eax
Ian Rogersa9a82542013-10-04 11:17:26 -0700551 POP ecx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800552 .cfi_restore ecx
Ian Rogersa9a82542013-10-04 11:17:26 -0700553 addl LITERAL(4), %esp
554 .cfi_adjust_cfa_offset -12
555 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
556 mov %esp, %edx
557 // Outgoing argument set up
558 PUSH edx // pass SP
559 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
560 .cfi_adjust_cfa_offset 4
561 PUSH ecx // pass arg2
562 PUSH eax // pass arg1
563 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*, SP)
564 int3 // unreached
565END_FUNCTION art_quick_check_cast
566
567 /*
568 * Entry from managed code for array put operations of objects where the value being stored
569 * needs to be checked for compatibility.
570 * eax = array, ecx = index, edx = value
571 */
572DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
573 testl %eax, %eax
574 jnz art_quick_aput_obj_with_bound_check
575 jmp art_quick_throw_null_pointer_exception
576END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
577
578DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
579 movl ARRAY_LENGTH_OFFSET(%eax), %ebx
580 cmpl %ebx, %ecx
581 jb art_quick_aput_obj
582 mov %ecx, %eax
583 mov %ebx, %ecx
584 jmp art_quick_throw_array_bounds
585END_FUNCTION art_quick_aput_obj_with_bound_check
586
587DEFINE_FUNCTION art_quick_aput_obj
588 test %edx, %edx // store of null
589 jz do_aput_null
590 movl CLASS_OFFSET(%eax), %ebx
591 movl CLASS_COMPONENT_TYPE_OFFSET(%ebx), %ebx
592 cmpl CLASS_OFFSET(%edx), %ebx // value's type == array's component type - trivial assignability
593 jne check_assignability
594do_aput:
595 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
596 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
597 shrl LITERAL(7), %eax
598 movb %dl, (%edx, %eax)
599 ret
600do_aput_null:
601 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
602 ret
603check_assignability:
604 PUSH eax // save arguments
605 PUSH ecx
606 PUSH edx
607 subl LITERAL(8), %esp // alignment padding
608 .cfi_adjust_cfa_offset 8
609 pushl CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
610 .cfi_adjust_cfa_offset 4
611 PUSH ebx // pass arg1 - component type of the array
612 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
613 addl LITERAL(16), %esp // pop arguments
614 .cfi_adjust_cfa_offset -16
615 testl %eax, %eax
616 jz throw_array_store_exception
617 POP edx
618 POP ecx
619 POP eax
620 movl %edx, OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
621 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
622 shrl LITERAL(7), %eax
623 movb %dl, (%edx, %eax)
624 ret
625throw_array_store_exception:
626 POP edx
627 POP ecx
628 POP eax
629 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
630 mov %esp, %ecx
631 // Outgoing argument set up
632 PUSH ecx // pass SP
633 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
634 .cfi_adjust_cfa_offset 4
635 PUSH edx // pass arg2 - value
636 PUSH eax // pass arg1 - array
637 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*, SP)
638 int3 // unreached
639END_FUNCTION art_quick_aput_obj
640
Logan Chien8dbb7082013-01-25 20:31:17 +0800641DEFINE_FUNCTION art_quick_memcpy
Ian Rogersaeeada42013-02-13 11:28:34 -0800642 PUSH edx // pass arg3
643 PUSH ecx // pass arg2
644 PUSH eax // pass arg1
Elliott Hughesadc078a2012-04-04 11:39:05 -0700645 call SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -0700646 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800647 .cfi_adjust_cfa_offset -12
Ian Rogers7caad772012-03-30 01:07:54 -0700648 ret
Ian Rogersaeeada42013-02-13 11:28:34 -0800649END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -0700650
Logan Chien8dbb7082013-01-25 20:31:17 +0800651NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -0700652
Ian Rogers468532e2013-08-05 10:56:33 -0700653DEFINE_FUNCTION art_quick_fmod
jeffhao1395b1e2012-06-13 18:05:13 -0700654 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800655 .cfi_adjust_cfa_offset 12
656 PUSH ebx // pass arg4 b.hi
657 PUSH edx // pass arg3 b.lo
658 PUSH ecx // pass arg2 a.hi
659 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700660 call SYMBOL(fmod) // (jdouble a, jdouble b)
661 fstpl (%esp) // pop return value off fp stack
662 movsd (%esp), %xmm0 // place into %xmm0
663 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800664 .cfi_adjust_cfa_offset -28
jeffhao292188d2012-05-17 15:45:04 -0700665 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700666END_FUNCTION art_quick_fmod
jeffhao292188d2012-05-17 15:45:04 -0700667
Ian Rogers468532e2013-08-05 10:56:33 -0700668DEFINE_FUNCTION art_quick_fmodf
Ian Rogersaeeada42013-02-13 11:28:34 -0800669 PUSH eax // alignment padding
670 PUSH ecx // pass arg2 b
671 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700672 call SYMBOL(fmodf) // (jfloat a, jfloat b)
Ian Rogers1b09b092012-08-20 15:35:52 -0700673 fstps (%esp) // pop return value off fp stack
jeffhao1395b1e2012-06-13 18:05:13 -0700674 movss (%esp), %xmm0 // place into %xmm0
675 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800676 .cfi_adjust_cfa_offset -12
jeffhao292188d2012-05-17 15:45:04 -0700677 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700678END_FUNCTION art_quick_fmodf
jeffhao292188d2012-05-17 15:45:04 -0700679
Ian Rogers468532e2013-08-05 10:56:33 -0700680DEFINE_FUNCTION art_quick_l2d
Ian Rogers5793fea2013-02-14 13:33:34 -0800681 PUSH ecx // push arg2 a.hi
682 PUSH eax // push arg1 a.lo
683 fildll (%esp) // load as integer and push into st0
684 fstpl (%esp) // pop value off fp stack as double
jeffhao41005dd2012-05-09 17:58:52 -0700685 movsd (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800686 addl LITERAL(8), %esp // pop arguments
687 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700688 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700689END_FUNCTION art_quick_l2d
jeffhao41005dd2012-05-09 17:58:52 -0700690
Ian Rogers468532e2013-08-05 10:56:33 -0700691DEFINE_FUNCTION art_quick_l2f
Ian Rogers5793fea2013-02-14 13:33:34 -0800692 PUSH ecx // push arg2 a.hi
693 PUSH eax // push arg1 a.lo
694 fildll (%esp) // load as integer and push into st0
695 fstps (%esp) // pop value off fp stack as a single
jeffhao41005dd2012-05-09 17:58:52 -0700696 movss (%esp), %xmm0 // place into %xmm0
Ian Rogers5793fea2013-02-14 13:33:34 -0800697 addl LITERAL(8), %esp // pop argument
698 .cfi_adjust_cfa_offset -8
jeffhao41005dd2012-05-09 17:58:52 -0700699 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700700END_FUNCTION art_quick_l2f
jeffhao41005dd2012-05-09 17:58:52 -0700701
Ian Rogers468532e2013-08-05 10:56:33 -0700702DEFINE_FUNCTION art_quick_d2l
Ian Rogersaeeada42013-02-13 11:28:34 -0800703 PUSH eax // alignment padding
704 PUSH ecx // pass arg2 a.hi
705 PUSH eax // pass arg1 a.lo
jeffhao1395b1e2012-06-13 18:05:13 -0700706 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -0700707 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800708 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700709 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700710END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -0700711
Ian Rogers468532e2013-08-05 10:56:33 -0700712DEFINE_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700713 subl LITERAL(8), %esp // alignment padding
Ian Rogers5793fea2013-02-14 13:33:34 -0800714 .cfi_adjust_cfa_offset 8
Ian Rogersaeeada42013-02-13 11:28:34 -0800715 PUSH eax // pass arg1 a
jeffhao1395b1e2012-06-13 18:05:13 -0700716 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -0700717 addl LITERAL(12), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800718 .cfi_adjust_cfa_offset -12
jeffhao41005dd2012-05-09 17:58:52 -0700719 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700720END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -0700721
Ian Rogers468532e2013-08-05 10:56:33 -0700722DEFINE_FUNCTION art_quick_idivmod
jeffhao174651d2012-04-19 15:27:22 -0700723 cmpl LITERAL(0x80000000), %eax
724 je check_arg2 // special case
725args_ok:
Ian Rogers7caad772012-03-30 01:07:54 -0700726 cdq // edx:eax = sign extend eax
727 idiv %ecx // (edx,eax) = (edx:eax % ecx, edx:eax / ecx)
Ian Rogers7caad772012-03-30 01:07:54 -0700728 ret
jeffhao174651d2012-04-19 15:27:22 -0700729check_arg2:
730 cmpl LITERAL(-1), %ecx
731 jne args_ok
732 xorl %edx, %edx
733 ret // eax already holds min int
Ian Rogers468532e2013-08-05 10:56:33 -0700734END_FUNCTION art_quick_idivmod
Ian Rogers7caad772012-03-30 01:07:54 -0700735
Ian Rogers468532e2013-08-05 10:56:33 -0700736DEFINE_FUNCTION art_quick_ldiv
Ian Rogersa9a82542013-10-04 11:17:26 -0700737 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800738 .cfi_adjust_cfa_offset 12
739 PUSH ebx // pass arg4 b.hi
740 PUSH edx // pass arg3 b.lo
741 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700742 PUSH eax // pass arg1 a.lo
743 call SYMBOL(artLdiv) // (jlong a, jlong b)
744 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800745 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700746 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700747END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -0700748
Ian Rogersa9a82542013-10-04 11:17:26 -0700749DEFINE_FUNCTION art_quick_lmod
750 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800751 .cfi_adjust_cfa_offset 12
752 PUSH ebx // pass arg4 b.hi
753 PUSH edx // pass arg3 b.lo
754 PUSH ecx // pass arg2 a.hi
Ian Rogersa9a82542013-10-04 11:17:26 -0700755 PUSH eax // pass arg1 a.lo
756 call SYMBOL(artLmod) // (jlong a, jlong b)
757 addl LITERAL(28), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800758 .cfi_adjust_cfa_offset -28
Ian Rogers55bd45f2012-04-04 17:31:20 -0700759 ret
Ian Rogersa9a82542013-10-04 11:17:26 -0700760END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -0700761
Ian Rogers468532e2013-08-05 10:56:33 -0700762DEFINE_FUNCTION art_quick_lmul
Ian Rogers5793fea2013-02-14 13:33:34 -0800763 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
764 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
765 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
766 add %ebx, %ecx
767 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -0700768 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700769END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -0700770
Ian Rogers468532e2013-08-05 10:56:33 -0700771DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -0700772 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -0700773 xchg %edx, %ecx
774 shld %cl,%eax,%edx
775 shl %cl,%eax
776 test LITERAL(32), %cl
777 jz 1f
778 mov %eax, %edx
779 xor %eax, %eax
7801:
781 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700782END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -0700783
Ian Rogers468532e2013-08-05 10:56:33 -0700784DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -0700785 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700786 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700787 shrd %cl,%edx,%eax
788 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -0700789 test LITERAL(32),%cl
790 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700791 mov %edx, %eax
792 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -07007931:
794 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700795END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -0700796
Ian Rogers468532e2013-08-05 10:56:33 -0700797DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -0700798 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -0700799 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -0700800 shrd %cl,%edx,%eax
801 shr %cl,%edx
802 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -0700803 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -0700804 mov %edx, %eax
805 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -07008061:
807 ret
Ian Rogers468532e2013-08-05 10:56:33 -0700808END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -0700809
Ian Rogers468532e2013-08-05 10:56:33 -0700810DEFINE_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700811 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
812 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700813 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800814 .cfi_adjust_cfa_offset 8
815 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700816 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800817 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700818 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800819 PUSH ebx // pass referrer
820 PUSH edx // pass new_val
821 PUSH ecx // pass object
822 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700823 call SYMBOL(artSet32InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700824 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800825 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700826 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
827 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700828END_FUNCTION art_quick_set32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700829
Ian Rogers468532e2013-08-05 10:56:33 -0700830DEFINE_FUNCTION art_quick_set64_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800831 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao1ff4cd72012-05-21 11:17:48 -0700832 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800833 .cfi_adjust_cfa_offset 8
834 PUSH esp // pass SP-8
jeffhao1ff4cd72012-05-21 11:17:48 -0700835 addl LITERAL(8), (%esp) // fix SP on stack by adding 8
jeffhao9dbb23e2012-05-18 17:03:57 -0700836 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800837 .cfi_adjust_cfa_offset 4
838 PUSH ebx // pass high half of new_val
839 PUSH edx // pass low half of new_val
840 PUSH ecx // pass object
841 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700842 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700843 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800844 .cfi_adjust_cfa_offset -32
845 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700846 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700847END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700848
Ian Rogers468532e2013-08-05 10:56:33 -0700849DEFINE_FUNCTION art_quick_set_obj_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800850 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700851 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700852 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800853 .cfi_adjust_cfa_offset 8
854 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700855 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800856 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700857 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800858 PUSH ebx // pass referrer
859 PUSH edx // pass new_val
860 PUSH ecx // pass object
861 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700862 call SYMBOL(artSetObjInstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700863 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800864 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700865 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
866 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700867END_FUNCTION art_quick_set_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700868
Ian Rogers468532e2013-08-05 10:56:33 -0700869DEFINE_FUNCTION art_quick_get32_instance
Ian Rogersaeeada42013-02-13 11:28:34 -0800870 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700871 mov %esp, %ebx // remember SP
872 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700873 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800874 .cfi_adjust_cfa_offset 12
875 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700876 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800877 .cfi_adjust_cfa_offset 4
878 PUSH edx // pass referrer
879 PUSH ecx // pass object
880 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700881 call SYMBOL(artGet32InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700882 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800883 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700884 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700885 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700886END_FUNCTION art_quick_get32_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700887
Ian Rogers468532e2013-08-05 10:56:33 -0700888DEFINE_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700889 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
890 mov %esp, %ebx // remember SP
891 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700892 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800893 .cfi_adjust_cfa_offset 12
894 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700895 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800896 .cfi_adjust_cfa_offset 4
897 PUSH edx // pass referrer
898 PUSH ecx // pass object
899 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700900 call SYMBOL(artGet64InstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700901 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800902 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700903 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700904 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700905END_FUNCTION art_quick_get64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700906
Ian Rogers468532e2013-08-05 10:56:33 -0700907DEFINE_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700908 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
909 mov %esp, %ebx // remember SP
910 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700911 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800912 .cfi_adjust_cfa_offset 12
913 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700914 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800915 .cfi_adjust_cfa_offset 4
916 PUSH edx // pass referrer
917 PUSH ecx // pass object
918 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700919 call SYMBOL(artGetObjInstanceFromCode) // (field_idx, Object*, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700920 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800921 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700922 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700923 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700924END_FUNCTION art_quick_get_obj_instance
jeffhao9dbb23e2012-05-18 17:03:57 -0700925
Ian Rogers468532e2013-08-05 10:56:33 -0700926DEFINE_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700927 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
928 mov %esp, %ebx // remember SP
929 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700930 subl LITERAL(12), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800931 .cfi_adjust_cfa_offset 12
932 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700933 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800934 .cfi_adjust_cfa_offset 4
935 PUSH edx // pass referrer
936 PUSH ecx // pass new_val
937 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700938 call SYMBOL(artSet32StaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700939 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800940 .cfi_adjust_cfa_offset -32
jeffhao9dbb23e2012-05-18 17:03:57 -0700941 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
942 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700943END_FUNCTION art_quick_set32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700944
Ian Rogers468532e2013-08-05 10:56:33 -0700945DEFINE_FUNCTION art_quick_set64_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800946 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700947 mov %esp, %ebx // remember SP
jeffhao1ff4cd72012-05-21 11:17:48 -0700948 subl LITERAL(8), %esp // alignment padding
Ian Rogersaeeada42013-02-13 11:28:34 -0800949 .cfi_adjust_cfa_offset 8
950 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700951 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800952 .cfi_adjust_cfa_offset 4
jeffhao9dbb23e2012-05-18 17:03:57 -0700953 mov 32(%ebx), %ebx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800954 PUSH edx // pass high half of new_val
955 PUSH ecx // pass low half of new_val
956 PUSH ebx // pass referrer
957 PUSH eax // pass field_idx
958 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700959 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800960 .cfi_adjust_cfa_offset -32
961 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700962 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700963END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700964
Ian Rogers468532e2013-08-05 10:56:33 -0700965DEFINE_FUNCTION art_quick_set_obj_static
Ian Rogersaeeada42013-02-13 11:28:34 -0800966 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -0700967 mov %esp, %ebx // remember SP
968 mov 32(%esp), %edx // get referrer
jeffhao1ff4cd72012-05-21 11:17:48 -0700969 subl LITERAL(12), %esp // alignment padding
Ian Rogers62d6c772013-02-27 08:32:07 -0800970 .cfi_adjust_cfa_offset 12
Ian Rogersaeeada42013-02-13 11:28:34 -0800971 PUSH ebx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700972 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800973 .cfi_adjust_cfa_offset 4
974 PUSH edx // pass referrer
975 PUSH ecx // pass new_val
976 PUSH eax // pass field_idx
977 call SYMBOL(artSetObjStaticFromCode) // (field_idx, new_val, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700978 addl LITERAL(32), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800979 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -0700980 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700981END_FUNCTION art_quick_set_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700982
Ian Rogers468532e2013-08-05 10:56:33 -0700983DEFINE_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700984 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
985 mov %esp, %edx // remember SP
986 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -0800987 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -0700988 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -0800989 .cfi_adjust_cfa_offset 4
990 PUSH ecx // pass referrer
991 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -0700992 call SYMBOL(artGet32StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -0700993 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -0800994 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -0700995 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -0700996 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -0700997END_FUNCTION art_quick_get32_static
jeffhao9dbb23e2012-05-18 17:03:57 -0700998
Ian Rogers468532e2013-08-05 10:56:33 -0700999DEFINE_FUNCTION art_quick_get64_static
Ian Rogersaeeada42013-02-13 11:28:34 -08001000 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
jeffhao9dbb23e2012-05-18 17:03:57 -07001001 mov %esp, %edx // remember SP
1002 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001003 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -07001004 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001005 .cfi_adjust_cfa_offset 4
1006 PUSH ecx // pass referrer
1007 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -07001008 call SYMBOL(artGet64StaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001009 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001010 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -07001011 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001012 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001013END_FUNCTION art_quick_get64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001014
Ian Rogers468532e2013-08-05 10:56:33 -07001015DEFINE_FUNCTION art_quick_get_obj_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001016 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save ref containing registers for GC
1017 mov %esp, %edx // remember SP
1018 mov 32(%esp), %ecx // get referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001019 PUSH edx // pass SP
jeffhao9dbb23e2012-05-18 17:03:57 -07001020 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001021 .cfi_adjust_cfa_offset 4
1022 PUSH ecx // pass referrer
1023 PUSH eax // pass field_idx
jeffhao9dbb23e2012-05-18 17:03:57 -07001024 call SYMBOL(artGetObjStaticFromCode) // (field_idx, referrer, Thread*, SP)
jeffhao1ff4cd72012-05-21 11:17:48 -07001025 addl LITERAL(16), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001026 .cfi_adjust_cfa_offset -16
jeffhao9dbb23e2012-05-18 17:03:57 -07001027 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhaod66a8752012-05-22 15:30:16 -07001028 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001029END_FUNCTION art_quick_get_obj_static
jeffhaod66a8752012-05-22 15:30:16 -07001030
Logan Chien8dbb7082013-01-25 20:31:17 +08001031DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers7db619b2013-01-16 18:35:48 -08001032 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame and Method*
Ian Rogersaeeada42013-02-13 11:28:34 -08001033 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001034 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001035 .cfi_adjust_cfa_offset 4
1036 PUSH ecx // pass receiver
1037 PUSH eax // pass proxy method
Jeff Hao5fa60c32013-04-04 17:57:01 -07001038 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001039 movd %eax, %xmm0 // place return value also into floating point return value
1040 movd %edx, %xmm1
1041 punpckldq %xmm1, %xmm0
jeffhaod66a8752012-05-22 15:30:16 -07001042 addl LITERAL(44), %esp // pop arguments
Ian Rogersaeeada42013-02-13 11:28:34 -08001043 .cfi_adjust_cfa_offset -44
jeffhaod66a8752012-05-22 15:30:16 -07001044 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001045END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001046
Jeff Hao88474b42013-10-23 16:24:40 -07001047 /*
1048 * Called to resolve an imt conflict. xmm0 is a hidden argument that holds the target method's
1049 * dex method index.
1050 */
1051DEFINE_FUNCTION art_quick_imt_conflict_trampoline
1052 PUSH ecx
1053 movl 8(%esp), %eax // load caller Method*
1054 movl METHOD_DEX_CACHE_METHODS_OFFSET(%eax), %eax // load dex_cache_resolved_methods
1055 movd %xmm0, %ecx // get target method index stored in xmm0
1056 movl OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4), %eax // load the target method
1057 POP ecx
1058 jmp art_quick_invoke_interface_trampoline
1059END_FUNCTION art_quick_imt_conflict_trampoline
1060
Ian Rogers468532e2013-08-05 10:56:33 -07001061DEFINE_FUNCTION art_quick_resolution_trampoline
1062 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1063 PUSH esp // pass SP
1064 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1065 .cfi_adjust_cfa_offset 4
1066 PUSH ecx // pass receiver
1067 PUSH eax // pass method
1068 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
1069 movl %eax, %edi // remember code pointer in EDI
1070 addl LITERAL(16), %esp // pop arguments
1071 test %eax, %eax // if code pointer is NULL goto deliver pending exception
1072 jz 1f
1073 POP eax // called method
1074 POP ecx // restore args
1075 POP edx
1076 POP ebx
1077 POP ebp // restore callee saves except EDI
1078 POP esi
1079 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
1080 ret // tail call into method
10811:
1082 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1083 DELIVER_PENDING_EXCEPTION
1084END_FUNCTION art_quick_resolution_trampoline
1085
1086DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers62d6c772013-02-27 08:32:07 -08001087 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001088 mov %esp, %edx // remember SP
1089 PUSH eax // alignment padding
1090 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001091 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogersaeeada42013-02-13 11:28:34 -08001092 .cfi_adjust_cfa_offset 4
1093 PUSH eax // pass method
Ian Rogers468532e2013-08-05 10:56:33 -07001094 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Ian Rogers7db619b2013-01-16 18:35:48 -08001095 movd %eax, %xmm0 // place return value also into floating point return value
1096 movd %edx, %xmm1
1097 punpckldq %xmm1, %xmm0
Mathieu Chartier19841522013-10-22 11:29:00 -07001098 addl LITERAL(16), %esp // pop arguments
1099 .cfi_adjust_cfa_offset -16
1100 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08001101 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001102END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001103
jeffhao7e4fcb82013-01-10 18:11:08 -08001104 /*
1105 * Routine that intercepts method calls and returns.
1106 */
Ian Rogers468532e2013-08-05 10:56:33 -07001107DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001108 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1109 movl %esp, %edx // Save SP.
1110 PUSH eax // Save eax which will be clobbered by the callee-save method.
1111 subl LITERAL(8), %esp // Align stack.
1112 .cfi_adjust_cfa_offset 8
1113 pushl 40(%esp) // Pass LR.
Ian Rogersaeeada42013-02-13 11:28:34 -08001114 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001115 PUSH edx // Pass SP.
1116 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001117 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001118 PUSH ecx // Pass receiver.
1119 PUSH eax // Pass Method*.
1120 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, SP, LR)
1121 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
1122 movl 28(%esp), %edi // Restore edi.
1123 movl %eax, 28(%esp) // Place code* over edi, just under return pc.
Ian Rogers468532e2013-08-05 10:56:33 -07001124 movl LITERAL(SYMBOL(art_quick_instrumentation_exit)), 32(%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001125 // Place instrumentation exit as return pc.
1126 movl (%esp), %eax // Restore eax.
1127 movl 8(%esp), %ecx // Restore ecx.
1128 movl 12(%esp), %edx // Restore edx.
1129 movl 16(%esp), %ebx // Restore ebx.
1130 movl 20(%esp), %ebp // Restore ebp.
1131 movl 24(%esp), %esi // Restore esi.
1132 addl LITERAL(28), %esp // Wind stack back upto code*.
1133 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001134END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001135
Ian Rogers468532e2013-08-05 10:56:33 -07001136DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001137 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
1138 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1139 mov %esp, %ecx // Remember SP
1140 subl LITERAL(8), %esp // Save float return value.
1141 .cfi_adjust_cfa_offset 8
1142 movd %xmm0, (%esp)
1143 PUSH edx // Save gpr return value.
1144 PUSH eax
1145 subl LITERAL(8), %esp // Align stack
1146 movd %xmm0, (%esp)
1147 subl LITERAL(8), %esp // Pass float return value.
1148 .cfi_adjust_cfa_offset 8
1149 movd %xmm0, (%esp)
1150 PUSH edx // Pass gpr return value.
1151 PUSH eax
1152 PUSH ecx // Pass SP.
1153 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Ian Rogersaeeada42013-02-13 11:28:34 -08001154 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001155 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
1156 mov %eax, %ecx // Move returned link register.
1157 addl LITERAL(32), %esp // Pop arguments.
1158 .cfi_adjust_cfa_offset -32
1159 movl %edx, %ebx // Move returned link register for deopt
1160 // (ebx is pretending to be our LR).
1161 POP eax // Restore gpr return value.
1162 POP edx
1163 movd (%esp), %xmm0 // Restore fpr return value.
1164 addl LITERAL(8), %esp
Ian Rogers5793fea2013-02-14 13:33:34 -08001165 .cfi_adjust_cfa_offset -8
Ian Rogers62d6c772013-02-27 08:32:07 -08001166 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1167 addl LITERAL(4), %esp // Remove fake return pc.
1168 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001169END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001170
jeffhao7e4fcb82013-01-10 18:11:08 -08001171 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001172 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1173 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001174 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001175DEFINE_FUNCTION art_quick_deoptimize
Ian Rogers62d6c772013-02-27 08:32:07 -08001176 pushl %ebx // Fake that we were called.
Jeff Haoc1fcdf12013-04-11 13:34:01 -07001177 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001178 mov %esp, %ecx // Remember SP.
1179 subl LITERAL(8), %esp // Align stack.
1180 .cfi_adjust_cfa_offset 8
1181 PUSH ecx // Pass SP.
1182 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Ian Rogersaeeada42013-02-13 11:28:34 -08001183 .cfi_adjust_cfa_offset 4
Ian Rogers62d6c772013-02-27 08:32:07 -08001184 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*, SP)
1185 int3 // Unreachable.
Ian Rogersaeeada42013-02-13 11:28:34 -08001186END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001187
jeffhao86e46712012-08-08 17:30:59 -07001188 /*
1189 * String's indexOf.
1190 *
1191 * On entry:
1192 * eax: string object (known non-null)
1193 * ecx: char to match (known <= 0xFFFF)
1194 * edx: Starting offset in string data
1195 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001196DEFINE_FUNCTION art_quick_indexof
Ian Rogersaeeada42013-02-13 11:28:34 -08001197 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001198 mov STRING_COUNT_OFFSET(%eax), %ebx
1199 mov STRING_VALUE_OFFSET(%eax), %edi
1200 mov STRING_OFFSET_OFFSET(%eax), %eax
1201 testl %edx, %edx // check if start < 0
1202 jl clamp_min
1203clamp_done:
1204 cmpl %ebx, %edx // check if start >= count
1205 jge not_found
1206 lea STRING_DATA_OFFSET(%edi, %eax, 2), %edi // build a pointer to the start of string data
1207 mov %edi, %eax // save a copy in eax to later compute result
1208 lea (%edi, %edx, 2), %edi // build pointer to start of data to compare
1209 subl %edx, %ebx // compute iteration count
1210 /*
1211 * At this point we have:
1212 * eax: original start of string data
1213 * ecx: char to compare
1214 * ebx: length to compare
1215 * edi: start of data to test
1216 */
1217 mov %eax, %edx
1218 mov %ecx, %eax // put char to match in %eax
1219 mov %ebx, %ecx // put length to compare in %ecx
1220 repne scasw // find %ax, starting at [%edi], up to length %ecx
1221 jne not_found
1222 subl %edx, %edi
1223 sar LITERAL(1), %edi
1224 decl %edi // index = ((curr_ptr - orig_ptr) / 2) - 1
1225 mov %edi, %eax
Ian Rogersaeeada42013-02-13 11:28:34 -08001226 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001227 ret
1228 .balign 16
1229not_found:
1230 mov LITERAL(-1), %eax // return -1 (not found)
Ian Rogersaeeada42013-02-13 11:28:34 -08001231 POP edi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001232 ret
1233clamp_min:
1234 xor %edx, %edx // clamp start to 0
1235 jmp clamp_done
Ian Rogersaeeada42013-02-13 11:28:34 -08001236END_FUNCTION art_quick_indexof
jeffhao86e46712012-08-08 17:30:59 -07001237
1238 /*
1239 * String's compareTo.
1240 *
1241 * On entry:
1242 * eax: this string object (known non-null)
1243 * ecx: comp string object (known non-null)
1244 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001245DEFINE_FUNCTION art_quick_string_compareto
Ian Rogersaeeada42013-02-13 11:28:34 -08001246 PUSH esi // push callee save reg
1247 PUSH edi // push callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001248 mov STRING_COUNT_OFFSET(%eax), %edx
1249 mov STRING_COUNT_OFFSET(%ecx), %ebx
1250 mov STRING_VALUE_OFFSET(%eax), %esi
1251 mov STRING_VALUE_OFFSET(%ecx), %edi
1252 mov STRING_OFFSET_OFFSET(%eax), %eax
1253 mov STRING_OFFSET_OFFSET(%ecx), %ecx
1254 /* Build pointers to the start of string data */
1255 lea STRING_DATA_OFFSET(%esi, %eax, 2), %esi
1256 lea STRING_DATA_OFFSET(%edi, %ecx, 2), %edi
1257 /* Calculate min length and count diff */
1258 mov %edx, %ecx
1259 mov %edx, %eax
1260 subl %ebx, %eax
1261 cmovg %ebx, %ecx
1262 /*
1263 * At this point we have:
1264 * eax: value to return if first part of strings are equal
1265 * ecx: minimum among the lengths of the two strings
1266 * esi: pointer to this string data
1267 * edi: pointer to comp string data
1268 */
1269 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
1270 jne not_equal
Ian Rogersaeeada42013-02-13 11:28:34 -08001271 POP edi // pop callee save reg
1272 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001273 ret
1274 .balign 16
1275not_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001276 movzwl -2(%esi), %eax // get last compared char from this string
1277 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001278 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001279 POP edi // pop callee save reg
1280 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001281 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001282END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001283
Elliott Hughes787ec202012-03-29 17:14:15 -07001284 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001285UNIMPLEMENTED art_quick_memcmp16