blob: 4fb6119ac105c3cf41f894fb418f9b8a46af815c [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
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -070019#include "arch/quick_alloc_entrypoints.S"
20
Dave Allisonbbb32c22013-11-05 18:25:18 -080021// For x86, the CFA is esp+4, the address above the pushed return address on the stack.
22
Ian Rogers57b86d42012-03-27 16:05:41 -070023 /*
24 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070025 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Ian Rogers57b86d42012-03-27 16:05:41 -070026 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070027MACRO2(SETUP_SAVE_ALL_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080028 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
29 PUSH esi
30 PUSH ebp
Andreas Gampe4360be22015-07-14 23:34:44 -070031 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070032 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -070033 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070034 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -070035 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
36 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070037 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -070038 pushl RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070039 CFI_ADJUST_CFA_OFFSET(4)
40 // Store esp as the top quick frame.
41 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -070042 // Ugly compile-time check, but we only have the preprocessor.
43 // Last +4: implicit return address pushed on stack when caller made call.
44#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 3*4 + 16 + 4)
45#error "SAVE_ALL_CALLEE_SAVE_FRAME(X86) size not as expected."
46#endif
Elliott Hughes787ec202012-03-29 17:14:15 -070047END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070048
Ian Rogers7caad772012-03-30 01:07:54 -070049 /*
50 * Macro that sets up the callee save frame to conform with
51 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
52 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070053MACRO2(SETUP_REFS_ONLY_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080054 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
55 PUSH esi
56 PUSH ebp
Andreas Gampe4360be22015-07-14 23:34:44 -070057 subl MACRO_LITERAL(12), %esp // Grow stack by 3 words.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070058 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -070059 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070060 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -070061 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
62 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070063 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -070064 pushl RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070065 CFI_ADJUST_CFA_OFFSET(4)
66 // Store esp as the top quick frame.
67 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -070068
69 // Ugly compile-time check, but we only have the preprocessor.
70 // Last +4: implicit return address pushed on stack when caller made call.
71#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
72#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
73#endif
Ian Rogers7caad772012-03-30 01:07:54 -070074END_MACRO
75
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070076MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -070077 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -080078 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -070079 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
80 POP esi
81 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -070082END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -070083
84 /*
85 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -070086 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -070087 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070088MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -080089 PUSH edi // Save callee saves
90 PUSH esi
91 PUSH ebp
92 PUSH ebx // Save args
93 PUSH edx
94 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +000095 // Create space for FPR args.
96 subl MACRO_LITERAL(4 * 8), %esp
97 CFI_ADJUST_CFA_OFFSET(4 * 8)
98 // Save FPRs.
99 movsd %xmm0, 0(%esp)
100 movsd %xmm1, 8(%esp)
101 movsd %xmm2, 16(%esp)
102 movsd %xmm3, 24(%esp)
103
Andreas Gampe4360be22015-07-14 23:34:44 -0700104 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700105 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700106 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
107 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700108 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -0700109 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700110 CFI_ADJUST_CFA_OFFSET(4)
111 // Store esp as the stop quick frame.
112 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700113
114 // Ugly compile-time check, but we only have the preprocessor.
115 // Last +4: implicit return address pushed on stack when caller made call.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000116#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4*8 + 4)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700117#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
118#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700119END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700120
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700121 /*
122 * Macro that sets up the callee save frame to conform with
123 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX.
124 */
125MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000126 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700127 PUSH edi // Save callee saves
128 PUSH esi
129 PUSH ebp
130 PUSH ebx // Save args
131 PUSH edx
132 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000133
134 // Create space for FPR args.
135 subl MACRO_LITERAL(32), %esp
136 CFI_ADJUST_CFA_OFFSET(32)
137
138 // Save FPRs.
139 movsd %xmm0, 0(%esp)
140 movsd %xmm1, 8(%esp)
141 movsd %xmm2, 16(%esp)
142 movsd %xmm3, 24(%esp)
143
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700144 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
145 // Store esp as the stop quick frame.
146 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
147END_MACRO
148
149MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000150 // Restore FPRs. EAX is still on the stack.
151 movsd 4(%esp), %xmm0
152 movsd 12(%esp), %xmm1
153 movsd 20(%esp), %xmm2
154 movsd 28(%esp), %xmm3
155
156 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
157 CFI_ADJUST_CFA_OFFSET(-36)
158
Andreas Gampe4360be22015-07-14 23:34:44 -0700159 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800160 POP edx
161 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700162 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800163 POP esi
164 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700165END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700166
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000167// Restore register and jump to routine
168// Inputs: EDI contains pointer to code.
169// Notes: Need to pop EAX too (restores Method*)
170MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP)
171 POP eax // Restore Method*
172
173 // Restore FPRs.
174 movsd 0(%esp), %xmm0
175 movsd 8(%esp), %xmm1
176 movsd 16(%esp), %xmm2
177 movsd 24(%esp), %xmm3
178
179 addl MACRO_LITERAL(32), %esp // Remove FPRs.
180 CFI_ADJUST_CFA_OFFSET(-32)
181
182 POP ecx // Restore args except eax
183 POP edx
184 POP ebx
185 POP ebp // Restore callee saves
186 POP esi
187 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
188 ret
189END_MACRO
190
Ian Rogers57b86d42012-03-27 16:05:41 -0700191 /*
192 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
193 * exception is Thread::Current()->exception_.
194 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700195MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700196 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700197 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700198 subl MACRO_LITERAL(12), %esp // Alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700199 CFI_ADJUST_CFA_OFFSET(12)
200 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800201 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700202 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700203 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700204END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700205
Elliott Hughes787ec202012-03-29 17:14:15 -0700206MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700207 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700208 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700209 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700210 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700211 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700212 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800213 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700214 call CALLVAR(cxx_name) // cxx_name(Thread*)
215 UNREACHABLE
216 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700217END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700218
Elliott Hughes787ec202012-03-29 17:14:15 -0700219MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700220 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700221 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700222 mov %esp, %ecx
223 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700224 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700225 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700226 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800227 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700228 PUSH eax // pass arg1
229 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
230 UNREACHABLE
231 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700232END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700233
Elliott Hughes787ec202012-03-29 17:14:15 -0700234MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700235 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700236 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700237 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700238 PUSH eax // alignment padding
239 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800240 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700241 PUSH ecx // pass arg2
242 PUSH eax // pass arg1
243 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
244 UNREACHABLE
245 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700246END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700247
248 /*
249 * Called by managed code to create and deliver a NullPointerException.
250 */
Ian Rogers468532e2013-08-05 10:56:33 -0700251NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700252
253 /*
254 * Called by managed code to create and deliver an ArithmeticException.
255 */
Ian Rogers468532e2013-08-05 10:56:33 -0700256NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700257
258 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700259 * Called by managed code to create and deliver a StackOverflowError.
260 */
Ian Rogers468532e2013-08-05 10:56:33 -0700261NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700262
263 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700264 * Called by managed code, saves callee saves and then calls artThrowException
265 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
266 */
Ian Rogers468532e2013-08-05 10:56:33 -0700267ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700268
269 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700270 * Called by managed code to create and deliver a NoSuchMethodError.
271 */
Ian Rogers468532e2013-08-05 10:56:33 -0700272ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700273
274 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700275 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
276 * index, arg2 holds limit.
277 */
Ian Rogers468532e2013-08-05 10:56:33 -0700278TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700279
280 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700281 * All generated callsites for interface invokes and invocation slow paths will load arguments
282 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100283 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700284 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
285 *
286 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
287 * of the target Method* in r0 and method->code_ in r1.
288 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700289 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700290 * thread and we branch to another stub to deliver it.
291 *
292 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
293 * pointing back to the original caller.
294 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700295MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700296 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700297 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000298
Ian Rogers7caad772012-03-30 01:07:54 -0700299 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800300 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700301 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800302 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800303 PUSH ecx // pass arg2
304 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700305 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700306 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100307 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
308 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000309
310 // Restore FPRs.
311 movsd 0(%esp), %xmm0
312 movsd 8(%esp), %xmm1
313 movsd 16(%esp), %xmm2
314 movsd 24(%esp), %xmm3
315
316 // Remove space for FPR args.
317 addl MACRO_LITERAL(4 * 8), %esp
318 CFI_ADJUST_CFA_OFFSET(-4 * 8)
319
Dave Allisonbbb32c22013-11-05 18:25:18 -0800320 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800321 POP edx
322 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800323 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800324 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700325 // Swap EDI callee save with code pointer.
326 xchgl %edi, (%esp)
327 testl %eax, %eax // Branch forward if exception pending.
328 jz 1f
329 // Tail call to intended method.
330 ret
3311:
jeffhao20b5c6c2012-05-21 14:15:18 -0700332 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800333 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700334 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700335END_MACRO
336MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700337 DEFINE_FUNCTION VAR(c_name)
338 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
339 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700340END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700341
Logan Chien8dbb7082013-01-25 20:31:17 +0800342INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700343
Logan Chien8dbb7082013-01-25 20:31:17 +0800344INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
345INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
346INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
347INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700348
Jeff Hao5d917302013-02-27 17:57:33 -0800349 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000350 * Helper for quick invocation stub to set up XMM registers.
351 * Increments shorty and arg_array and clobbers temp_char.
352 * Branches to finished if it encounters the end of the shorty.
353 */
354MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3551: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700356 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
357 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
358 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
359 je VAR(finished) // goto finished
360 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
361 je 2f // goto FOUND_DOUBLE
362 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
363 je 3f // goto FOUND_FLOAT
364 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000365 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700366 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
367 jne 1b // goto LOOP
368 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
369 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003702: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700371 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
372 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000373 jmp 4f
3743: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700375 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
376 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003774:
378END_MACRO
379
380 /*
381 * Helper for quick invocation stub to set up GPR registers.
382 * Increments shorty and arg_array, and returns the current short character in
383 * temp_char. Branches to finished if it encounters the end of the shorty.
384 */
385MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
3861: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700387 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
388 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
389 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
390 je VAR(finished) // goto finished
391 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
392 je 3f // goto SKIP_FLOAT
393 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
394 je 4f // goto SKIP_DOUBLE
395 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003963: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700397 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
398 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00003994: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700400 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
401 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004025:
403END_MACRO
404
405 /*
406 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700407 * On entry:
408 * [sp] = return address
409 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700410 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700411 * [sp + 12] = size of argument array in bytes
412 * [sp + 16] = (managed) thread pointer
413 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800414 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800415 */
416DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000417 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800418 PUSH ebp // save ebp
419 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000420 PUSH esi // save esi
421 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000422 // Set up argument XMM registers.
423 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
424 addl LITERAL(1), %esi
425 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
426 addl LITERAL(4), %edi
427 // Clobbers ESI, EDI, EAX.
428 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
429 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
430 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
431 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
432 .balign 16
433.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800434 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800435 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000436 mov 28(%ebp), %ebx // get arg array size
437 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
438 addl LITERAL(36), %ebx
439 // align frame size to 16 bytes
440 andl LITERAL(0xFFFFFFF0), %ebx
441 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800442 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000443
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700444 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000445
446 // Copy arg array into stack.
447 movl 28(%ebp), %ecx // ECX = size of args
448 movl 24(%ebp), %esi // ESI = argument array
449 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
450 rep movsb // while (ecx--) { *edi++ = *esi++ }
451
452 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
453 addl LITERAL(1), %esi
454 mov 24(%ebp), %edi // EDI := arg_array
455 mov 0(%edi), %ecx // ECX := this pointer
456 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
457
458 // Enumerate the possible cases for loading GPRS.
459 // edx (and maybe ebx):
460 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
461 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
462 je .LfirstLong
463 // Must be an integer value.
464 movl (%edi), %edx
465 addl LITERAL(4), %edi // arg_array++
466
467 // Now check ebx
468 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500469 // Must be first word of a long, or an integer. First word of long doesn't
470 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000471 movl (%edi), %ebx
472 jmp .Lgpr_setup_finished
473.LfirstLong:
474 movl (%edi), %edx
475 movl 4(%edi), %ebx
476 // Nothing left to load.
477.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000478 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700479 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800480 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800481 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000482 POP edi // pop edi
483 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800484 POP ebx // pop ebx
485 POP ebp // pop ebp
486 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800487 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800488 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800489 mov 24(%esp), %edx // get the shorty
490 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800491 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800492 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800493 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700494 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800495.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800496 movsd %xmm0, (%ecx) // store the floating point result
497 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800498.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800499 movss %xmm0, (%ecx) // store the floating point result
500 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800501END_FUNCTION art_quick_invoke_stub
502
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000503 /*
504 * Quick invocation stub (static).
505 * On entry:
506 * [sp] = return address
507 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700508 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000509 * [sp + 12] = size of argument array in bytes
510 * [sp + 16] = (managed) thread pointer
511 * [sp + 20] = JValue* result
512 * [sp + 24] = shorty
513 */
514DEFINE_FUNCTION art_quick_invoke_static_stub
515 // Save the non-volatiles.
516 PUSH ebp // save ebp
517 PUSH ebx // save ebx
518 PUSH esi // save esi
519 PUSH edi // save edi
520 // Set up argument XMM registers.
521 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
522 addl LITERAL(1), %esi
523 mov 8+16(%esp), %edi // EDI := arg_array
524 // Clobbers ESI, EDI, EAX.
525 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
526 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
527 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
528 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
529 .balign 16
530.Lxmm_setup_finished2:
531 mov %esp, %ebp // copy value of stack pointer into base pointer
532 CFI_DEF_CFA_REGISTER(ebp)
533 mov 28(%ebp), %ebx // get arg array size
534 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
535 addl LITERAL(36), %ebx
536 // align frame size to 16 bytes
537 andl LITERAL(0xFFFFFFF0), %ebx
538 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
539 subl %ebx, %esp // reserve stack space for argument array
540
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700541 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000542
543 // Copy arg array into stack.
544 movl 28(%ebp), %ecx // ECX = size of args
545 movl 24(%ebp), %esi // ESI = argument array
546 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
547 rep movsb // while (ecx--) { *edi++ = *esi++ }
548
549 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
550 addl LITERAL(1), %esi
551 mov 24(%ebp), %edi // EDI := arg_array
552
553 // Enumerate the possible cases for loading GPRS.
554 // ecx (and maybe edx)
555 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
556 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
557 je .LfirstLong2
558 // Must be an integer value. Load into ECX.
559 movl (%edi), %ecx
560 addl LITERAL(4), %edi // arg_array++
561
562 // Now check edx (and maybe ebx).
563 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
564 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
565 je .LSecondLong2
566 // Must be an integer. Load into EDX.
567 movl (%edi), %edx
568 addl LITERAL(4), %edi // arg_array++
569
570 // Is there anything for ebx?
571 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500572 // Must be first word of a long, or an integer. First word of long doesn't
573 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000574 movl (%edi), %ebx
575 jmp .Lgpr_setup_finished2
576.LSecondLong2:
577 // EDX:EBX is long. That is all.
578 movl (%edi), %edx
579 movl 4(%edi), %ebx
580 jmp .Lgpr_setup_finished2
581.LfirstLong2:
582 // ECX:EDX is a long
583 movl (%edi), %ecx
584 movl 4(%edi), %edx
585 addl LITERAL(8), %edi // arg_array += 2
586
587 // Anything for EBX?
588 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500589 // Must be first word of a long, or an integer. First word of long doesn't
590 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000591 movl (%edi), %ebx
592 jmp .Lgpr_setup_finished2
593 // Nothing left to load.
594.Lgpr_setup_finished2:
595 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700596 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000597 mov %ebp, %esp // restore stack pointer
598 CFI_DEF_CFA_REGISTER(esp)
599 POP edi // pop edi
600 POP esi // pop esi
601 POP ebx // pop ebx
602 POP ebp // pop ebp
603 mov 20(%esp), %ecx // get result pointer
604 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
605 mov %edx, 4(%ecx) // store the other half of the result
606 mov 24(%esp), %edx // get the shorty
607 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
608 je .Lreturn_double_quick2
609 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
610 je .Lreturn_float_quick2
611 ret
612.Lreturn_double_quick2:
613 movsd %xmm0, (%ecx) // store the floating point result
614 ret
615.Lreturn_float_quick2:
616 movss %xmm0, (%ecx) // store the floating point result
617 ret
618END_FUNCTION art_quick_invoke_static_stub
619
Ian Rogersd36c52e2012-04-09 16:29:25 -0700620MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700621 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700622 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700623 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700624 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700625 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700626 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800627 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700628 call CALLVAR(cxx_name) // cxx_name(Thread*)
629 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800630 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700631 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
632 CALL_MACRO(return_macro) // return or deliver exception
633 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700634END_MACRO
635
636MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700637 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700638 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700639 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700640 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700641 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700642 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800643 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700644 PUSH eax // pass arg1
645 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
646 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800647 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700648 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
649 CALL_MACRO(return_macro) // return or deliver exception
650 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700651END_MACRO
652
653MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700654 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700655 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700656 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700657 PUSH eax // push padding
658 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800659 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700660 PUSH ecx // pass arg2
661 PUSH eax // pass arg1
662 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
663 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800664 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700665 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
666 CALL_MACRO(return_macro) // return or deliver exception
667 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700668END_MACRO
669
Ian Rogersd36c52e2012-04-09 16:29:25 -0700670MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700671 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700672 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700673 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700674 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800675 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700676 PUSH edx // pass arg3
677 PUSH ecx // pass arg2
678 PUSH eax // pass arg1
679 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
680 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700681 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700682 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
683 CALL_MACRO(return_macro) // return or deliver exception
684 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700685END_MACRO
686
Jeff Hao848f70a2014-01-15 13:49:50 -0800687MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700688 DEFINE_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800689 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
690 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700691 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800692 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700693 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800694 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700695 PUSH ebx // pass arg4
696 PUSH edx // pass arg3
697 PUSH ecx // pass arg2
698 PUSH eax // pass arg1
699 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
700 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800701 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700702 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
703 CALL_MACRO(return_macro) // return or deliver exception
704 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800705END_MACRO
706
Fred Shih37f05ef2014-07-16 18:38:08 -0700707MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700708 DEFINE_FUNCTION VAR(c_name)
709 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700710 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700711 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700712 PUSH eax // push padding
713 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700714 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700715 PUSH ecx // pass referrer
716 PUSH eax // pass arg1
717 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
718 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700719 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700720 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
721 CALL_MACRO(return_macro) // return or deliver exception
722 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700723END_MACRO
724
725MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700726 DEFINE_FUNCTION VAR(c_name)
727 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700728 // Outgoing argument set up
729 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700730 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700731 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700732 PUSH edx // pass referrer
733 PUSH ecx // pass arg2
734 PUSH eax // pass arg1
735 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
736 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700737 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700738 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
739 CALL_MACRO(return_macro) // return or deliver exception
740 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700741END_MACRO
742
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700743MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700744 DEFINE_FUNCTION VAR(c_name)
745 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700746 // Outgoing argument set up
747 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700748 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700749 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700750 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700751 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700752 PUSH ebx // pass referrer
753 PUSH edx // pass arg3
754 PUSH ecx // pass arg2
755 PUSH eax // pass arg1
756 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
757 // Thread*)
758 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700759 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700760 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
761 CALL_MACRO(return_macro) // return or deliver exception
762 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700763END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700764
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700765MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700766 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700767 jz 1f // if eax == 0 goto 1
768 ret // return
7691: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700770 DELIVER_PENDING_EXCEPTION
771END_MACRO
772
Ian Rogersd36c52e2012-04-09 16:29:25 -0700773MACRO0(RETURN_IF_EAX_ZERO)
774 testl %eax, %eax // eax == 0 ?
775 jnz 1f // if eax != 0 goto 1
776 ret // return
7771: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700778 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700779END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700780
jeffhaod66a8752012-05-22 15:30:16 -0700781MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700782 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700783 jne 1f // if exception field != 0 goto 1
784 ret // return
7851: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700786 DELIVER_PENDING_EXCEPTION
787END_MACRO
788
Mathieu Chartier7410f292013-11-24 13:17:35 -0800789// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700790GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800791
792// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
793DEFINE_FUNCTION art_quick_alloc_object_rosalloc
794 // Fast path rosalloc allocation.
795 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
796 // ebx, edx: free
797 PUSH edi
798 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
799 // Load the class (edx)
800 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
801 testl %edx, %edx // Check null class
802 jz .Lart_quick_alloc_object_rosalloc_slow_path
803 // Check class status
804 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
805 jne .Lart_quick_alloc_object_rosalloc_slow_path
806 // No fake dependence needed on x86
807 // between status and flags load,
808 // since each load is a load-acquire,
809 // no loads reordering.
810 // Check access flags has
811 // kAccClassIsFinalizable
812 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
813 jnz .Lart_quick_alloc_object_rosalloc_slow_path
814
815 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
816 // Check if the thread local allocation
817 // stack has room
818 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
819 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
820 jae .Lart_quick_alloc_object_rosalloc_slow_path
821
822 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
823 // Check if the size is for a thread
824 // local allocation
825 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
826 ja .Lart_quick_alloc_object_rosalloc_slow_path
827 decl %edi
828 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
829 // from object size.
830 // Align up the size by the rosalloc
831 // bracket quantum size and divide
832 // by the quantum size and subtract
833 // by 1. This code is a shorter but
834 // equivalent version.
835 // Load thread local rosalloc run (ebx)
836 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
837 // Load free_list head (edi),
838 // this will be the return value.
839 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
840 test %edi, %edi
841 jz .Lart_quick_alloc_object_rosalloc_slow_path
842 // Point of no slow path. Won't go to
843 // the slow path from here on. Ok to
844 // clobber eax and ecx.
845 movl %edi, %eax
846 // Load the next pointer of the head
847 // and update head of free list with
848 // next pointer
849 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
850 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
851 // Decrement size of free list by 1
852 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
853 // Store the class pointer in the
854 // header. This also overwrites the
855 // next pointer. The offsets are
856 // asserted to match.
857#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
858#error "Class pointer needs to overwrite next pointer."
859#endif
860 POISON_HEAP_REF edx
861 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
862 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
863 // Push the new object onto the thread
864 // local allocation stack and
865 // increment the thread local
866 // allocation stack top.
867 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
868 movl %eax, (%edi)
869 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
870 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
871 // No fence needed for x86.
872 POP edi
873 ret
874.Lart_quick_alloc_object_rosalloc_slow_path:
875 POP edi
876 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
877 // Outgoing argument set up
878 PUSH eax // alignment padding
879 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
880 CFI_ADJUST_CFA_OFFSET(4)
881 PUSH ecx
882 PUSH eax
883 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
884 addl LITERAL(16), %esp // pop arguments
885 CFI_ADJUST_CFA_OFFSET(-16)
886 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
887 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
888END_FUNCTION art_quick_alloc_object_rosalloc
889
890
Mark Mendell3f2d0312014-01-20 17:20:27 -0800891GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
Mark Mendell3f2d0312014-01-20 17:20:27 -0800892
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700893ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
894ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
895ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
896ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogersd36c52e2012-04-09 16:29:25 -0700897
Ian Rogers832336b2014-10-08 15:35:22 -0700898TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -0700899
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700900DEFINE_FUNCTION art_quick_lock_object
901 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -0800902 jz .Lslow_lock
903.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700904 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800905 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -0800906 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800907 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
908 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700909 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -0800910 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800911 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700912 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800913 movl %edx, %eax // eax: lock word zero except for read barrier bits.
914 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
915 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
916 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
917 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700918 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800919.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
920 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +0700921 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -0800922 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800923 movl %edx, %ecx // copy the lock word to check count overflow.
924 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
925 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
926 test LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // overflowed if either of the upper two bits (28-29) are set.
Ian Rogers8016a122014-02-21 20:37:21 -0800927 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800928 movl %eax, %ecx // save obj to use eax for cmpxchg.
929 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
930 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
931 // update lockword, cmpxchg necessary for read barrier bits.
932 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
933 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700934 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800935.Llock_cmpxchg_fail:
936 movl %ecx, %eax // restore eax
937 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -0800938.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700939 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700940 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700941 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700942 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700943 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800944 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700945 PUSH eax // pass object
946 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
947 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800948 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700949 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700950 RETURN_IF_EAX_ZERO
951END_FUNCTION art_quick_lock_object
952
953DEFINE_FUNCTION art_quick_unlock_object
954 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -0800955 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800956.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700957 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700958 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800959 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +0700960 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700961 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -0800962 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800963 movl %ecx, %edx // copy the lock word to detect new count of 0.
964 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
965 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -0800966 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800967 // update lockword, cmpxchg necessary for read barrier bits.
968 movl %eax, %edx // edx: obj
969 movl %ecx, %eax // eax: old lock word.
970 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
971#ifndef USE_READ_BARRIER
972 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
973#else
974 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
975 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
976#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700977 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800978.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
979 // update lockword, cmpxchg necessary for read barrier bits.
980 movl %eax, %edx // edx: obj
981 movl %ecx, %eax // eax: old lock word.
982 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
983#ifndef USE_READ_BARRIER
984 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
985#else
986 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
987 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
988#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700989 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800990.Lunlock_cmpxchg_fail: // edx: obj
991 movl %edx, %eax // restore eax
992 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -0800993.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700994 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700995 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700996 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700997 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700998 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800999 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001000 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001001 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001002 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001003 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001004 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001005 RETURN_IF_EAX_ZERO
1006END_FUNCTION art_quick_unlock_object
1007
Ian Rogers468532e2013-08-05 10:56:33 -07001008DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001009 PUSH eax // alignment padding
1010 PUSH ecx // pass arg2 - obj->klass
1011 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001012 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001013 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001014 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001015 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001016END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001017
Ian Rogersa9a82542013-10-04 11:17:26 -07001018DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001019 PUSH eax // alignment padding
1020 PUSH ecx // pass arg2 - obj->klass
1021 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001022 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001023 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001024 jz 1f // jump forward if not assignable
1025 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001026 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001027 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001028
Andreas Gampe4360be22015-07-14 23:34:44 -07001029 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070010301:
Andreas Gampe4360be22015-07-14 23:34:44 -07001031 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001032 POP ecx
1033 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001034 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001035 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001036 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001037 PUSH eax // alignment padding
1038 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001039 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001040 PUSH ecx // pass arg2
1041 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001042 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001043 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001044END_FUNCTION art_quick_check_cast
1045
Man Cao1aee9002015-07-14 22:31:42 -07001046// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1047MACRO2(POP_REG_NE, reg, exclude_reg)
1048 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1049 addl MACRO_LITERAL(4), %esp
1050 CFI_ADJUST_CFA_OFFSET(-4)
1051 .else
1052 POP RAW_VAR(reg)
1053 .endif
1054END_MACRO
1055
1056 /*
1057 * Macro to insert read barrier, only used in art_quick_aput_obj.
1058 * obj_reg and dest_reg are registers, offset is a defined literal such as
1059 * MIRROR_OBJECT_CLASS_OFFSET.
1060 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1061 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1062 */
1063MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1064#ifdef USE_READ_BARRIER
1065 PUSH eax // save registers used in art_quick_aput_obj
1066 PUSH ebx
1067 PUSH edx
1068 PUSH ecx
1069 // Outgoing argument set up
1070 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1071 CFI_ADJUST_CFA_OFFSET(4)
1072 PUSH RAW_VAR(obj_reg) // pass obj_reg
1073 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1074 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1075 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1076 .ifnc RAW_VAR(dest_reg), eax
1077 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1078 .endif
1079 addl MACRO_LITERAL(12), %esp // pop arguments
1080 CFI_ADJUST_CFA_OFFSET(-12)
1081 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1082 POP_REG_NE edx, RAW_VAR(dest_reg)
1083 POP_REG_NE ebx, RAW_VAR(dest_reg)
1084 .ifc RAW_VAR(pop_eax), true
1085 POP_REG_NE eax, RAW_VAR(dest_reg)
1086 .endif
1087#else
1088 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1089 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1090#endif // USE_READ_BARRIER
1091END_MACRO
1092
Ian Rogersa9a82542013-10-04 11:17:26 -07001093 /*
1094 * Entry from managed code for array put operations of objects where the value being stored
1095 * needs to be checked for compatibility.
1096 * eax = array, ecx = index, edx = value
1097 */
1098DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1099 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001100 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1101 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001102END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1103
1104DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001105 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001106 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001107 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001108 mov %ecx, %eax
1109 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001110 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001111END_FUNCTION art_quick_aput_obj_with_bound_check
1112
1113DEFINE_FUNCTION art_quick_aput_obj
1114 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001115 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001116 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1117 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001118 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001119#if defined(USE_READ_BARRIER)
1120 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1121 cmpl %eax, %ebx
1122 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001123 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001124#elif defined(USE_HEAP_POISONING)
1125 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001126 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1127 UNPOISON_HEAP_REF eax
1128 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001129 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001130#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001131 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001132#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001133 jne .Lcheck_assignability
1134.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001135 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001136 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001137 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1138 shrl LITERAL(7), %eax
1139 movb %dl, (%edx, %eax)
1140 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001141.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001142 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001143 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001144.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001145 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001146 PUSH ecx
1147 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001148#if defined(USE_READ_BARRIER)
1149 subl LITERAL(4), %esp // alignment padding
1150 CFI_ADJUST_CFA_OFFSET(4)
1151 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1152 subl LITERAL(4), %esp // alignment padding
1153 CFI_ADJUST_CFA_OFFSET(4)
1154 PUSH eax // pass arg2 - type of the value to be stored
1155#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001156 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001157 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001158 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001159 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001160 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001161#else
Man Cao63069212015-08-21 15:51:39 -07001162 subl LITERAL(8), %esp // alignment padding
1163 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001164 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001165 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001166#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001167 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001168 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001169 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001170 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001171 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001172 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001173 POP edx
1174 POP ecx
1175 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001176 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001177 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001178 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1179 shrl LITERAL(7), %eax
1180 movb %dl, (%edx, %eax)
1181 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001182 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001183.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001184 POP edx
1185 POP ecx
1186 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001187 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001188 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001189 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001190 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001191 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001192 PUSH edx // pass arg2 - value
1193 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001194 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001195 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001196END_FUNCTION art_quick_aput_obj
1197
Logan Chien8dbb7082013-01-25 20:31:17 +08001198DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001199 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001200 PUSH edx // pass arg3
1201 PUSH ecx // pass arg2
1202 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001203 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001204 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001205 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001206 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001207END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001208
Logan Chien8dbb7082013-01-25 20:31:17 +08001209NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001210
Ian Rogers468532e2013-08-05 10:56:33 -07001211DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001212 subl LITERAL(12), %esp // alignment padding, room for argument
1213 CFI_ADJUST_CFA_OFFSET(12)
1214 movsd %xmm0, 0(%esp) // arg a
1215 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001216 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001217 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001218 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001219END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001220
Ian Rogers468532e2013-08-05 10:56:33 -07001221DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001222 subl LITERAL(12), %esp // alignment padding
1223 CFI_ADJUST_CFA_OFFSET(12)
1224 movss %xmm0, 0(%esp) // arg a
1225 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001226 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001227 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001228 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001229END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001230
Ian Rogers468532e2013-08-05 10:56:33 -07001231DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001232 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001233 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001234 PUSH ebx // pass arg4 b.hi
1235 PUSH edx // pass arg3 b.lo
1236 PUSH ecx // pass arg2 a.hi
1237 PUSH eax // pass arg1 a.lo
1238 call SYMBOL(artLdiv) // (jlong a, jlong b)
1239 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001240 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001241 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001242END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001243
Ian Rogersa9a82542013-10-04 11:17:26 -07001244DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001245 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001246 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001247 PUSH ebx // pass arg4 b.hi
1248 PUSH edx // pass arg3 b.lo
1249 PUSH ecx // pass arg2 a.hi
1250 PUSH eax // pass arg1 a.lo
1251 call SYMBOL(artLmod) // (jlong a, jlong b)
1252 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001253 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001254 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001255END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001256
Ian Rogers468532e2013-08-05 10:56:33 -07001257DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001258 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1259 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1260 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001261 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001262 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001263 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001264END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001265
Ian Rogers468532e2013-08-05 10:56:33 -07001266DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001267 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001268 xchg %edx, %ecx
1269 shld %cl,%eax,%edx
1270 shl %cl,%eax
1271 test LITERAL(32), %cl
1272 jz 1f
1273 mov %eax, %edx
1274 xor %eax, %eax
12751:
1276 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001277END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001278
Ian Rogers468532e2013-08-05 10:56:33 -07001279DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001280 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001281 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001282 shrd %cl,%edx,%eax
1283 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001284 test LITERAL(32),%cl
1285 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001286 mov %edx, %eax
1287 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070012881:
1289 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001290END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001291
Ian Rogers468532e2013-08-05 10:56:33 -07001292DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001293 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001294 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001295 shrd %cl,%edx,%eax
1296 shr %cl,%edx
1297 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001298 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001299 mov %edx, %eax
1300 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070013011:
1302 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001303END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001304
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001305ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1306ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1307ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1308ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1309ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1310ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1311ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001312
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001313TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1314TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1315TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1316TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1317TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1318TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1319TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001320
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001321TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1322TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1323TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1324TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001325
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001326THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1327THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1328THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1329THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1330
1331// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001332DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001333 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001334 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001335 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001336 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001337 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001338 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001339 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001340 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001341 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1342 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001343 PUSH ebx // pass high half of new_val
1344 PUSH edx // pass low half of new_val
1345 PUSH ecx // pass object
1346 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001347 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001348 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001349 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001350 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001351 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001352END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001353
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001354// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1355// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001356DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001357 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1358 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001359 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001360 movd %xmm0, %ebx
1361 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001362 subl LITERAL(12), %esp // alignment padding
1363 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001364 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001365 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001366 PUSH ebx // pass high half of new_val
1367 PUSH edx // pass low half of new_val
1368 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001369 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001370 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001371 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001372 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001373 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001374 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001375END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001376
Logan Chien8dbb7082013-01-25 20:31:17 +08001377DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001378 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001379 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001380 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001381 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001382 PUSH ecx // pass receiver
1383 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001384 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001385 movd %eax, %xmm0 // place return value also into floating point return value
1386 movd %edx, %xmm1
1387 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001388 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1389 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1390 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001391 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001392END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001393
Igor Murashkin457e8742015-10-22 17:37:50 -07001394#if LAMBDA_INVOKE_USES_LONG
1395#undef LAMBDA_PROXY_SETUP_FRAME
1396// We need to always do a 'pop' to readjust the stack, so we have to use the slower call instruction.
1397#define LAMBDA_PROXY_SETUP_FRAME 1
1398#define LAMBDA_INVOKE_REALIGN_STACK_FRAME 1
1399#else
1400#define LAMBDA_INVOKE_REALIGN_STACK_FRAME 0
1401#endif
1402
1403#define LAMBDA_INVOKE_CALLS_INTO_RUNTIME LAMBDA_INVOKE_REALIGN_STACK_FRAME
1404
1405// Forward call from boxed innate lambda to the underlying lambda closure's target method.
1406DEFINE_FUNCTION art_quick_lambda_proxy_invoke_handler
1407 // This function is always called when the lambda is innate.
1408 // Therefore we can assume the box is to an innate lambda.
1409 // TODO: perhaps there should be a DCHECK to make sure it's innate?
1410
1411#if LAMBDA_PROXY_SETUP_FRAME
1412 // Set up a quick frame when debugging so we can see that it's going through a stub.
1413 // An invoke-virtual + a stub invocation is enough of a hint that we *could* be
1414 // going through a lambda proxy.
1415 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
1416#endif
1417
1418#if !LAMBDA_INVOKE_CALLS_INTO_RUNTIME
1419 // Rewrite the following 2 arguments, stored on stack frame:
1420 //
1421 // |--------|
1422 // |receiver| <- esp-4
1423 // |--------|
1424 // | method | <- esp
1425 // |--------|
1426
1427 // Set up the new correct method receiver (swap object with closure).
1428 // -- The original object is no longer available after this.
1429 //
1430 // (Before)
1431 // ecx == mirror::Object* boxed_lambda; // lambda proxy object.
1432 movl MIRROR_OBJECT_BOXED_INNATE_LAMBDA_CLOSURE_POINTER_OFFSET(%ecx), %ecx
1433 // (After)
1434 // lambda::Closure* closure = boxed_lambda->closure_;
1435 // boxed_lambda = closure; // Overwrite lambda proxy object
1436 // ecx == closure
1437
1438 // Look up the new correct method target.
1439 // -- The original method target is no longer available after this.
1440 //
1441 // (Before)
1442 // eax == ArtMethod* old_receiver_method;
1443 movl LAMBDA_CLOSURE_METHOD_OFFSET(%ecx), %eax
1444 // (After)
1445 // ArtLambdaMethod* lambda_method_target = closure->lambda_info_;
1446 // eax = lambda_method_target
1447 //
1448 // Set up the correct method target from the lambda info.
1449 movl ART_LAMBDA_METHOD_ART_METHOD_OFFSET(%eax), %eax // Load new receiver method
1450 // (After)
1451 // ArtMethod* target_method = lambda_method_target->target_
1452 // eax = target_method
1453#endif
1454
1455#if LAMBDA_INVOKE_CALLS_INTO_RUNTIME
1456 PUSH esp // pass SP
1457 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1458 CFI_ADJUST_CFA_OFFSET(4)
1459 PUSH ecx // pass receiver
1460 PUSH eax // pass proxy method
1461 call SYMBOL(artQuickLambdaProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
1462 movd %eax, %xmm0 // place return value also into floating point return value
1463 movd %edx, %xmm1
1464 punpckldq %xmm1, %xmm0
1465 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1466 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1467 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1468 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
1469#endif
1470
1471#if LAMBDA_INVOKE_USES_LONG && !LAMBDA_INVOKE_REALIGN_STACK_FRAME
1472 // As a temporary workaround, lambda functions look like
1473 // (J[Arg2][Arg3][Arg4]...)
1474 // This means that we can't just pass in the lambda as a 32-bit pointer
1475 // We pad the arguments with an extra 32-bit "0" where Arg2 used to be instead.
1476
1477 // Required arguments for a lambda method:
1478 //
1479 // Arg0 = eax = method
1480 // Arg1 = ecx = closure (hi)
1481 // Arg2 = edx = closure (lo)
1482 // Arg3 = ebx = <?> (first user-defined argument)
1483
1484 // Transformation diagram:
1485 //
1486 // Arg0 Arg1 Arg2 Arg3 ... ArgN
1487 // | | \ \ \
1488 // | | \ \ \
1489 // Arg0 Arg1 0x00 Arg2 Arg3 ... ArgN
1490 // /\
1491 // (inserted)
1492 PUSH ebx // Move out Arg3 into Arg4, and also for all K>3 ArgK into ArgK+1
1493 mov %edx, %ebx // Move out Arg2 into Arg3
1494 xor %edx, %edx // Clear closure 32-bit low register
1495
1496 // XX: Does this work at all ? This probably breaks the visitors (*and* its unaligned).
1497
1498 // FIXME: call into the runtime and do a proxy-like-invoke
1499 // using a ShadowFrame quick visitor, and then use ArtMethod::Invoke
1500 // to call into the actual method (which will take care of fixing up alignment).
1501 // Trying to realign in the assembly itself won't actually work
1502 // since then the visitor will unwind incorrectly (unless we also fixed up the ManagedStack).
1503#endif
1504
1505 // TODO: avoid extra indirect load by subclass ArtLambdaMethod from ArtMethod.
1506
1507 // Forward the call to the overwritten receiver method.
1508 // -- Arguments [2,N] are left completely untouched since the signature is otherwise identical.
1509#if LAMBDA_PROXY_SETUP_FRAME
1510 #if LAMBDA_INVOKE_CALLS_INTO_RUNTIME
1511 // Have to call into runtime in order to re-align the stack frame to 16 bytes.
1512 int3
1513 #else
1514 // Just call into the method directly. Don't worry about realigning.
1515 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // (new method, new receiver, old args...)
1516
1517 // The stack frame was manually adjusted, so make sure we have a pop here to fix it back.
1518 #if LAMBDA_INVOKE_USES_LONG && !LAMBDA_INVOKE_REALIGN_STACK_FRAME
1519
1520 POP ecx // OK: ecx is scratch register after the call.
1521 // XX: use 'add esp, 4' instead if we need to keep the register? This way we get cleaner CFI.
1522 #endif
1523 #endif
1524 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1525
1526#else
1527 // Do not use 'call' here since the stack visitors wouldn't know how to visit this frame.
1528 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // tailcall (new method, new receiver, old args...)
1529#endif
1530
1531#if LAMBDA_PROXY_SETUP_FRAME
1532 ret
1533#endif
1534
1535END_FUNCTION art_quick_lambda_proxy_invoke_handler
1536
Jeff Hao88474b42013-10-23 16:24:40 -07001537 /*
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001538 * Called to resolve an imt conflict. xmm7 is a hidden argument that holds the target method's
Jeff Hao88474b42013-10-23 16:24:40 -07001539 * dex method index.
1540 */
1541DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001542 movd %xmm7, %eax // get target method index stored in xmm7
Andreas Gampe55978b82015-07-14 17:57:43 -07001543 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001544END_FUNCTION art_quick_imt_conflict_trampoline
1545
Ian Rogers468532e2013-08-05 10:56:33 -07001546DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001547 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001548 movl %esp, %edi
1549 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001550 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001551 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001552 PUSH ecx // pass receiver
1553 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001554 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001555 movl %eax, %edi // remember code pointer in EDI
1556 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001557 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001558 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001559 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001560 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070015611:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001562 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001563 DELIVER_PENDING_EXCEPTION
1564END_FUNCTION art_quick_resolution_trampoline
1565
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001566DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001567 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001568 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001569 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001570 subl LITERAL(5120), %esp
1571 // prepare for artQuickGenericJniTrampoline call
1572 // (Thread*, SP)
1573 // (esp) 4(esp) <= C calling convention
1574 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001575
1576 subl LITERAL(8), %esp // Padding for 16B alignment.
1577 pushl %ebp // Pass SP (to ArtMethod).
1578 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001579 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001580
Andreas Gampec200a4a2014-06-16 18:39:09 -07001581 // The C call will have registered the complete save-frame on success.
1582 // The result of the call is:
1583 // eax: pointer to native code, 0 on error.
1584 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001585
Andreas Gampec200a4a2014-06-16 18:39:09 -07001586 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001587 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001588 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001589
Andreas Gampec200a4a2014-06-16 18:39:09 -07001590 // Release part of the alloca.
1591 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001592
1593 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001594 // Native call.
1595 call *%eax
1596
Andreas Gampe779f8c92014-06-09 18:29:38 -07001597 // result sign extension is handled in C code
1598 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001599 // (Thread*, result, result_f)
1600 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001601 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001602
Andreas Gampe4360be22015-07-14 23:34:44 -07001603 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001604 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001605 pushl %edx // Pass int result.
1606 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001607 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001608 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001609
Andreas Gampe779f8c92014-06-09 18:29:38 -07001610 // Pending exceptions possible.
1611 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1612 testl %ebx, %ebx
1613 jnz .Lexception_in_native
1614
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001615 // Tear down the alloca.
1616 movl %ebp, %esp
1617 CFI_DEF_CFA_REGISTER(esp)
1618
1619
Andreas Gampe779f8c92014-06-09 18:29:38 -07001620 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001621 // Remove space for FPR args and EAX
1622 addl LITERAL(4 + 4 * 8), %esp
1623 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1624
Andreas Gampe779f8c92014-06-09 18:29:38 -07001625 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001626 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001627 CFI_ADJUST_CFA_OFFSET(-4)
1628 POP ebx
1629 POP ebp // Restore callee saves
1630 POP esi
1631 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001632 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001633 movd %eax, %xmm0
1634 movd %edx, %xmm1
1635 punpckldq %xmm1, %xmm0
1636 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001637.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001638 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1639 // Do a call to push a new save-all frame required by the runtime.
1640 call .Lexception_call
1641.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001642 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001643END_FUNCTION art_quick_generic_jni_trampoline
1644
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001645DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001646 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001647 mov %esp, %edx // remember SP
1648 PUSH eax // alignment padding
1649 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001650 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001651 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001652 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001653 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001654 addl LITERAL(16), %esp // pop arguments
1655 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001656
1657 // Return eax:edx in xmm0 also.
1658 movd %eax, %xmm0
1659 movd %edx, %xmm1
1660 punpckldq %xmm1, %xmm0
1661
1662 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1663 CFI_ADJUST_CFA_OFFSET(-48)
1664
Andreas Gampe4360be22015-07-14 23:34:44 -07001665 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001666 POP esi
1667 POP edi
1668
Ian Rogers7db619b2013-01-16 18:35:48 -08001669 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001670END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001671
jeffhao7e4fcb82013-01-10 18:11:08 -08001672 /*
1673 * Routine that intercepts method calls and returns.
1674 */
Ian Rogers468532e2013-08-05 10:56:33 -07001675DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001676 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001677 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001678 subl LITERAL(12), %esp // Align stack.
1679 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001680 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001681 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001682 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001683 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001684 PUSH ecx // Pass receiver.
1685 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001686 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001687 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001688 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001689 movl 60(%esp), %edi // Restore edi.
1690 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001691 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001692 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001693 movl %ebx, 64(%esp)
1694 movl 0(%esp), %eax // Restore eax.
1695 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1696 movsd 8(%esp), %xmm0
1697 movsd 16(%esp), %xmm1
1698 movsd 24(%esp), %xmm2
1699 movsd 32(%esp), %xmm3
1700
1701 // Restore GPRs.
1702 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001703 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001704 movl 48(%esp), %ebx // Restore ebx.
1705 movl 52(%esp), %ebp // Restore ebp.
1706 movl 56(%esp), %esi // Restore esi.
1707 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001708 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001709 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001710END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001711
Ian Rogers468532e2013-08-05 10:56:33 -07001712DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001713 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001714 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001715 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001716 mov %esp, %ecx // Remember SP
1717 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001718 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001719 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001720 PUSH edx // Save gpr return value.
1721 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001722 subl LITERAL(16), %esp // Align stack
1723 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001724 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001725 PUSH edx // Pass gpr return value.
1726 PUSH eax
1727 PUSH ecx // Pass SP.
1728 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001729 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001730 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001731 mov %eax, %ecx // Move returned link register.
1732 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001733 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001734 movl %edx, %ebx // Move returned link register for deopt
1735 // (ebx is pretending to be our LR).
1736 POP eax // Restore gpr return value.
1737 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001738 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001739 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001740 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001741 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001742 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001743 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001744 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001745END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001746
jeffhao7e4fcb82013-01-10 18:11:08 -08001747 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001748 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1749 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001750 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001751DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001752 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001753 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1754 subl LITERAL(12), %esp // Align stack.
1755 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001756 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001757 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001758 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001759 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001760END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001761
jeffhao86e46712012-08-08 17:30:59 -07001762 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001763 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001764 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001765 */
1766DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1767 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1768 subl LITERAL(12), %esp // Align stack.
1769 CFI_ADJUST_CFA_OFFSET(12)
1770 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1771 CFI_ADJUST_CFA_OFFSET(4)
1772 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1773 UNREACHABLE
1774END_FUNCTION art_quick_deoptimize_from_compiled_code
1775
1776 /*
jeffhao86e46712012-08-08 17:30:59 -07001777 * String's compareTo.
1778 *
1779 * On entry:
1780 * eax: this string object (known non-null)
1781 * ecx: comp string object (known non-null)
1782 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001783DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001784 PUSH esi // push callee save reg
1785 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001786 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1787 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001788 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1789 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001790 /* Calculate min length and count diff */
1791 mov %edx, %ecx
1792 mov %edx, %eax
1793 subl %ebx, %eax
1794 cmovg %ebx, %ecx
1795 /*
1796 * At this point we have:
1797 * eax: value to return if first part of strings are equal
1798 * ecx: minimum among the lengths of the two strings
1799 * esi: pointer to this string data
1800 * edi: pointer to comp string data
1801 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001802 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001803 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001804 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001805.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001806 POP edi // pop callee save reg
1807 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001808 ret
1809 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001810.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001811 movzwl -2(%esi), %eax // get last compared char from this string
1812 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001813 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001814 POP edi // pop callee save reg
1815 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001816 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001817END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001818
Dave Allison8ce6b902014-08-26 11:07:58 -07001819// Return from a nested signal:
1820// Entry:
1821// eax: address of jmp_buf in TLS
1822
1823DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001824 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001825 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001826 PUSH ecx // second arg to longjmp (1)
1827 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001828 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001829 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001830END_FUNCTION art_nested_signal_return
1831
Man Cao1aee9002015-07-14 22:31:42 -07001832DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001833 PUSH edx // pass arg3 - offset
1834 PUSH ecx // pass arg2 - obj
1835 PUSH eax // pass arg1 - ref
1836 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1837 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001838 CFI_ADJUST_CFA_OFFSET(-12)
1839 ret
1840END_FUNCTION art_quick_read_barrier_slow
1841
Roland Levillain0d5a2812015-11-13 10:07:31 +00001842DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
1843 PUSH eax // pass arg1 - root
1844 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
1845 addl LITERAL(4), %esp // pop argument
1846 CFI_ADJUST_CFA_OFFSET(-4)
1847 ret
1848END_FUNCTION art_quick_read_barrier_for_root_slow
1849
Elliott Hughes787ec202012-03-29 17:14:15 -07001850 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08001851UNIMPLEMENTED art_quick_memcmp16