blob: 77e04e7981e4cecd985aebd72798e5fca82a570f [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
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010076 /*
77 * Macro that sets up the callee save frame to conform with
78 * Runtime::CreateCalleeSaveMethod(kRefsOnly)
79 * and preserves the value of got_reg at entry.
80 */
81MACRO2(SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG, got_reg, temp_reg)
82 PUSH edi // Save callee saves (ebx is saved/restored by the upcall)
83 PUSH esi
84 PUSH ebp
Vladimir Marko2ebef632016-06-21 11:24:47 +010085 PUSH RAW_VAR(got_reg) // Save got_reg
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010086 subl MACRO_LITERAL(8), %esp // Grow stack by 2 words.
87 CFI_ADJUST_CFA_OFFSET(8)
88
89 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
90 // Load Runtime::instance_ from GOT.
91 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
92 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
93 // Push save all callee-save method.
94 pushl RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
95 CFI_ADJUST_CFA_OFFSET(4)
96 // Store esp as the top quick frame.
97 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
98 // Restore got_reg.
99 movl 12(%esp), REG_VAR(got_reg)
Vladimir Marko2ebef632016-06-21 11:24:47 +0100100 CFI_RESTORE(RAW_VAR(got_reg))
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100101
102 // Ugly compile-time check, but we only have the preprocessor.
103 // Last +4: implicit return address pushed on stack when caller made call.
104#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 3*4 + 16 + 4)
105#error "REFS_ONLY_CALLEE_SAVE_FRAME(X86) size not as expected."
106#endif
107END_MACRO
108
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700109MACRO0(RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME)
Ian Rogers47d00c02014-04-16 17:33:27 -0700110 addl MACRO_LITERAL(16), %esp // Unwind stack up to saved values
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800111 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2a6c7b72013-10-16 11:16:33 -0700112 POP ebp // Restore callee saves (ebx is saved/restored by the upcall)
113 POP esi
114 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700115END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700116
117 /*
118 * Macro that sets up the callee save frame to conform with
Ian Rogers7caad772012-03-30 01:07:54 -0700119 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700120 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700121MACRO2(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME, got_reg, temp_reg)
Ian Rogersaeeada42013-02-13 11:28:34 -0800122 PUSH edi // Save callee saves
123 PUSH esi
124 PUSH ebp
125 PUSH ebx // Save args
126 PUSH edx
127 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000128 // Create space for FPR args.
129 subl MACRO_LITERAL(4 * 8), %esp
130 CFI_ADJUST_CFA_OFFSET(4 * 8)
131 // Save FPRs.
132 movsd %xmm0, 0(%esp)
133 movsd %xmm1, 8(%esp)
134 movsd %xmm2, 16(%esp)
135 movsd %xmm3, 24(%esp)
136
Andreas Gampe4360be22015-07-14 23:34:44 -0700137 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700138 // Load Runtime::instance_ from GOT.
Andreas Gampe4360be22015-07-14 23:34:44 -0700139 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
140 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700141 // Push save all callee-save method.
Andreas Gampe4360be22015-07-14 23:34:44 -0700142 pushl RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143 CFI_ADJUST_CFA_OFFSET(4)
144 // Store esp as the stop quick frame.
145 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700146
147 // Ugly compile-time check, but we only have the preprocessor.
148 // Last +4: implicit return address pushed on stack when caller made call.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000149#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 7*4 + 4*8 + 4)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700150#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(X86) size not as expected."
151#endif
Elliott Hughes787ec202012-03-29 17:14:15 -0700152END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700153
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700154 /*
155 * Macro that sets up the callee save frame to conform with
156 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs) where the method is passed in EAX.
157 */
158MACRO0(SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000159 // Save callee and GPR args, mixed together to agree with core spills bitmap.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700160 PUSH edi // Save callee saves
161 PUSH esi
162 PUSH ebp
163 PUSH ebx // Save args
164 PUSH edx
165 PUSH ecx
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000166
167 // Create space for FPR args.
168 subl MACRO_LITERAL(32), %esp
169 CFI_ADJUST_CFA_OFFSET(32)
170
171 // Save FPRs.
172 movsd %xmm0, 0(%esp)
173 movsd %xmm1, 8(%esp)
174 movsd %xmm2, 16(%esp)
175 movsd %xmm3, 24(%esp)
176
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700177 PUSH eax // Store the ArtMethod reference at the bottom of the stack.
178 // Store esp as the stop quick frame.
179 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
180END_MACRO
181
182MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000183 // Restore FPRs. EAX is still on the stack.
184 movsd 4(%esp), %xmm0
185 movsd 12(%esp), %xmm1
186 movsd 20(%esp), %xmm2
187 movsd 28(%esp), %xmm3
188
189 addl MACRO_LITERAL(36), %esp // Remove FPRs and EAX.
190 CFI_ADJUST_CFA_OFFSET(-36)
191
Andreas Gampe4360be22015-07-14 23:34:44 -0700192 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800193 POP edx
194 POP ebx
Andreas Gampe4360be22015-07-14 23:34:44 -0700195 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800196 POP esi
197 POP edi
Elliott Hughes787ec202012-03-29 17:14:15 -0700198END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700199
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000200// Restore register and jump to routine
201// Inputs: EDI contains pointer to code.
202// Notes: Need to pop EAX too (restores Method*)
203MACRO0(RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP)
204 POP eax // Restore Method*
205
206 // Restore FPRs.
207 movsd 0(%esp), %xmm0
208 movsd 8(%esp), %xmm1
209 movsd 16(%esp), %xmm2
210 movsd 24(%esp), %xmm3
211
212 addl MACRO_LITERAL(32), %esp // Remove FPRs.
213 CFI_ADJUST_CFA_OFFSET(-32)
214
215 POP ecx // Restore args except eax
216 POP edx
217 POP ebx
218 POP ebp // Restore callee saves
219 POP esi
220 xchgl 0(%esp),%edi // restore EDI and place code pointer as only value on stack
221 ret
222END_MACRO
223
Ian Rogers57b86d42012-03-27 16:05:41 -0700224 /*
225 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
226 * exception is Thread::Current()->exception_.
227 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700228MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700229 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700230 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100231 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700232 CFI_ADJUST_CFA_OFFSET(12)
233 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800234 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700235 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700236 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700237END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700238
Elliott Hughes787ec202012-03-29 17:14:15 -0700239MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700240 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700241 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700242 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700243 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700244 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700245 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800246 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700247 call CALLVAR(cxx_name) // cxx_name(Thread*)
248 UNREACHABLE
249 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700250END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700251
Elliott Hughes787ec202012-03-29 17:14:15 -0700252MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700253 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700254 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700255 mov %esp, %ecx
256 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100257 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700258 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700259 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800260 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700261 PUSH eax // pass arg1
262 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
263 UNREACHABLE
264 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700265END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700266
Elliott Hughes787ec202012-03-29 17:14:15 -0700267MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700268 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700269 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700270 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700271 PUSH eax // alignment padding
272 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800273 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700274 PUSH ecx // pass arg2
275 PUSH eax // pass arg1
276 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
277 UNREACHABLE
278 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700279END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700280
281 /*
282 * Called by managed code to create and deliver a NullPointerException.
283 */
Ian Rogers468532e2013-08-05 10:56:33 -0700284NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700285
286 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100287 * Call installed by a signal handler to create and deliver a NullPointerException.
288 */
289ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
290
291 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700292 * Called by managed code to create and deliver an ArithmeticException.
293 */
Ian Rogers468532e2013-08-05 10:56:33 -0700294NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700295
296 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700297 * Called by managed code to create and deliver a StackOverflowError.
298 */
Ian Rogers468532e2013-08-05 10:56:33 -0700299NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700300
301 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700302 * Called by managed code, saves callee saves and then calls artThrowException
303 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
304 */
Ian Rogers468532e2013-08-05 10:56:33 -0700305ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700306
307 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700308 * Called by managed code to create and deliver a NoSuchMethodError.
309 */
Ian Rogers468532e2013-08-05 10:56:33 -0700310ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700311
312 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700313 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
314 * index, arg2 holds limit.
315 */
Ian Rogers468532e2013-08-05 10:56:33 -0700316TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700317
318 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100319 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
320 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
321 */
322TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
323
324 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700325 * All generated callsites for interface invokes and invocation slow paths will load arguments
326 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100327 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700328 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
329 *
330 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
331 * of the target Method* in r0 and method->code_ in r1.
332 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700333 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700334 * thread and we branch to another stub to deliver it.
335 *
336 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
337 * pointing back to the original caller.
338 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700339MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700340 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700341 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000342
Ian Rogers7caad772012-03-30 01:07:54 -0700343 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800344 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700345 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800346 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800347 PUSH ecx // pass arg2
348 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700349 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700350 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100351 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
352 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000353
354 // Restore FPRs.
355 movsd 0(%esp), %xmm0
356 movsd 8(%esp), %xmm1
357 movsd 16(%esp), %xmm2
358 movsd 24(%esp), %xmm3
359
360 // Remove space for FPR args.
361 addl MACRO_LITERAL(4 * 8), %esp
362 CFI_ADJUST_CFA_OFFSET(-4 * 8)
363
Dave Allisonbbb32c22013-11-05 18:25:18 -0800364 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800365 POP edx
366 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800367 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800368 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700369 // Swap EDI callee save with code pointer.
370 xchgl %edi, (%esp)
371 testl %eax, %eax // Branch forward if exception pending.
372 jz 1f
373 // Tail call to intended method.
374 ret
3751:
jeffhao20b5c6c2012-05-21 14:15:18 -0700376 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800377 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700378 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700379END_MACRO
380MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700381 DEFINE_FUNCTION VAR(c_name)
382 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
383 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700384END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700385
Logan Chien8dbb7082013-01-25 20:31:17 +0800386INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700387
Logan Chien8dbb7082013-01-25 20:31:17 +0800388INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
389INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
390INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
391INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700392
Jeff Hao5d917302013-02-27 17:57:33 -0800393 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000394 * Helper for quick invocation stub to set up XMM registers.
395 * Increments shorty and arg_array and clobbers temp_char.
396 * Branches to finished if it encounters the end of the shorty.
397 */
398MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
3991: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700400 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
401 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
402 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
403 je VAR(finished) // goto finished
404 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
405 je 2f // goto FOUND_DOUBLE
406 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
407 je 3f // goto FOUND_FLOAT
408 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000409 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700410 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
411 jne 1b // goto LOOP
412 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
413 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004142: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700415 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
416 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000417 jmp 4f
4183: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700419 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
420 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004214:
422END_MACRO
423
424 /*
425 * Helper for quick invocation stub to set up GPR registers.
426 * Increments shorty and arg_array, and returns the current short character in
427 * temp_char. Branches to finished if it encounters the end of the shorty.
428 */
429MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
4301: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700431 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
432 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
433 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
434 je VAR(finished) // goto finished
435 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
436 je 3f // goto SKIP_FLOAT
437 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
438 je 4f // goto SKIP_DOUBLE
439 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004403: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700441 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
442 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004434: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700444 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
445 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004465:
447END_MACRO
448
449 /*
450 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700451 * On entry:
452 * [sp] = return address
453 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700454 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700455 * [sp + 12] = size of argument array in bytes
456 * [sp + 16] = (managed) thread pointer
457 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800458 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800459 */
460DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000461 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800462 PUSH ebp // save ebp
463 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000464 PUSH esi // save esi
465 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000466 // Set up argument XMM registers.
467 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
468 addl LITERAL(1), %esi
469 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
470 addl LITERAL(4), %edi
471 // Clobbers ESI, EDI, EAX.
472 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
473 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
474 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
475 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
476 .balign 16
477.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800478 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800479 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000480 mov 28(%ebp), %ebx // get arg array size
481 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
482 addl LITERAL(36), %ebx
483 // align frame size to 16 bytes
484 andl LITERAL(0xFFFFFFF0), %ebx
485 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800486 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000487
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700488 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000489
490 // Copy arg array into stack.
491 movl 28(%ebp), %ecx // ECX = size of args
492 movl 24(%ebp), %esi // ESI = argument array
493 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
494 rep movsb // while (ecx--) { *edi++ = *esi++ }
495
496 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
497 addl LITERAL(1), %esi
498 mov 24(%ebp), %edi // EDI := arg_array
499 mov 0(%edi), %ecx // ECX := this pointer
500 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
501
502 // Enumerate the possible cases for loading GPRS.
503 // edx (and maybe ebx):
504 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
505 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
506 je .LfirstLong
507 // Must be an integer value.
508 movl (%edi), %edx
509 addl LITERAL(4), %edi // arg_array++
510
511 // Now check ebx
512 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500513 // Must be first word of a long, or an integer. First word of long doesn't
514 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000515 movl (%edi), %ebx
516 jmp .Lgpr_setup_finished
517.LfirstLong:
518 movl (%edi), %edx
519 movl 4(%edi), %ebx
520 // Nothing left to load.
521.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000522 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700523 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800524 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800525 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000526 POP edi // pop edi
527 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800528 POP ebx // pop ebx
529 POP ebp // pop ebp
530 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800531 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800532 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800533 mov 24(%esp), %edx // get the shorty
534 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800535 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800536 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800537 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700538 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800539.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800540 movsd %xmm0, (%ecx) // store the floating point result
541 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800542.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800543 movss %xmm0, (%ecx) // store the floating point result
544 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800545END_FUNCTION art_quick_invoke_stub
546
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000547 /*
548 * Quick invocation stub (static).
549 * On entry:
550 * [sp] = return address
551 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700552 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000553 * [sp + 12] = size of argument array in bytes
554 * [sp + 16] = (managed) thread pointer
555 * [sp + 20] = JValue* result
556 * [sp + 24] = shorty
557 */
558DEFINE_FUNCTION art_quick_invoke_static_stub
559 // Save the non-volatiles.
560 PUSH ebp // save ebp
561 PUSH ebx // save ebx
562 PUSH esi // save esi
563 PUSH edi // save edi
564 // Set up argument XMM registers.
565 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
566 addl LITERAL(1), %esi
567 mov 8+16(%esp), %edi // EDI := arg_array
568 // Clobbers ESI, EDI, EAX.
569 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
570 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
571 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
572 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
573 .balign 16
574.Lxmm_setup_finished2:
575 mov %esp, %ebp // copy value of stack pointer into base pointer
576 CFI_DEF_CFA_REGISTER(ebp)
577 mov 28(%ebp), %ebx // get arg array size
578 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
579 addl LITERAL(36), %ebx
580 // align frame size to 16 bytes
581 andl LITERAL(0xFFFFFFF0), %ebx
582 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
583 subl %ebx, %esp // reserve stack space for argument array
584
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700585 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000586
587 // Copy arg array into stack.
588 movl 28(%ebp), %ecx // ECX = size of args
589 movl 24(%ebp), %esi // ESI = argument array
590 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
591 rep movsb // while (ecx--) { *edi++ = *esi++ }
592
593 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
594 addl LITERAL(1), %esi
595 mov 24(%ebp), %edi // EDI := arg_array
596
597 // Enumerate the possible cases for loading GPRS.
598 // ecx (and maybe edx)
599 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
600 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
601 je .LfirstLong2
602 // Must be an integer value. Load into ECX.
603 movl (%edi), %ecx
604 addl LITERAL(4), %edi // arg_array++
605
606 // Now check edx (and maybe ebx).
607 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
608 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
609 je .LSecondLong2
610 // Must be an integer. Load into EDX.
611 movl (%edi), %edx
612 addl LITERAL(4), %edi // arg_array++
613
614 // Is there anything for ebx?
615 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500616 // Must be first word of a long, or an integer. First word of long doesn't
617 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000618 movl (%edi), %ebx
619 jmp .Lgpr_setup_finished2
620.LSecondLong2:
621 // EDX:EBX is long. That is all.
622 movl (%edi), %edx
623 movl 4(%edi), %ebx
624 jmp .Lgpr_setup_finished2
625.LfirstLong2:
626 // ECX:EDX is a long
627 movl (%edi), %ecx
628 movl 4(%edi), %edx
629 addl LITERAL(8), %edi // arg_array += 2
630
631 // Anything for EBX?
632 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500633 // Must be first word of a long, or an integer. First word of long doesn't
634 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000635 movl (%edi), %ebx
636 jmp .Lgpr_setup_finished2
637 // Nothing left to load.
638.Lgpr_setup_finished2:
639 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700640 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000641 mov %ebp, %esp // restore stack pointer
642 CFI_DEF_CFA_REGISTER(esp)
643 POP edi // pop edi
644 POP esi // pop esi
645 POP ebx // pop ebx
646 POP ebp // pop ebp
647 mov 20(%esp), %ecx // get result pointer
648 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
649 mov %edx, 4(%ecx) // store the other half of the result
650 mov 24(%esp), %edx // get the shorty
651 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
652 je .Lreturn_double_quick2
653 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
654 je .Lreturn_float_quick2
655 ret
656.Lreturn_double_quick2:
657 movsd %xmm0, (%ecx) // store the floating point result
658 ret
659.Lreturn_float_quick2:
660 movss %xmm0, (%ecx) // store the floating point result
661 ret
662END_FUNCTION art_quick_invoke_static_stub
663
Ian Rogersd36c52e2012-04-09 16:29:25 -0700664MACRO3(NO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700665 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700666 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700667 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700668 subl MACRO_LITERAL(12), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700669 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700670 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800671 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700672 call CALLVAR(cxx_name) // cxx_name(Thread*)
673 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800674 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700675 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
676 CALL_MACRO(return_macro) // return or deliver exception
677 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700678END_MACRO
679
680MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700681 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700682 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700683 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700684 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700685 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700686 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800687 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700688 PUSH eax // pass arg1
689 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
690 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800691 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700692 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
693 CALL_MACRO(return_macro) // return or deliver exception
694 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700695END_MACRO
696
697MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700698 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700699 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700700 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700701 PUSH eax // push padding
702 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800703 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700704 PUSH ecx // pass arg2
705 PUSH eax // pass arg1
706 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
707 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800708 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700709 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
710 CALL_MACRO(return_macro) // return or deliver exception
711 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700712END_MACRO
713
Ian Rogersd36c52e2012-04-09 16:29:25 -0700714MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700715 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700716 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700717 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700718 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800719 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700720 PUSH edx // pass arg3
721 PUSH ecx // pass arg2
722 PUSH eax // pass arg1
723 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
724 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700725 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700726 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
727 CALL_MACRO(return_macro) // return or deliver exception
728 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700729END_MACRO
730
Jeff Hao848f70a2014-01-15 13:49:50 -0800731MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700732 DEFINE_FUNCTION VAR(c_name)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100733 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000734
Jeff Hao848f70a2014-01-15 13:49:50 -0800735 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700736 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800737 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700738 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800739 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700740 PUSH ebx // pass arg4
741 PUSH edx // pass arg3
742 PUSH ecx // pass arg2
743 PUSH eax // pass arg1
744 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
745 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800746 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700747 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
748 CALL_MACRO(return_macro) // return or deliver exception
749 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800750END_MACRO
751
Fred Shih37f05ef2014-07-16 18:38:08 -0700752MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700753 DEFINE_FUNCTION VAR(c_name)
754 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700755 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700756 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700757 PUSH eax // push padding
758 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700759 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700760 PUSH ecx // pass referrer
761 PUSH eax // pass arg1
762 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
763 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700764 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700765 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
766 CALL_MACRO(return_macro) // return or deliver exception
767 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700768END_MACRO
769
770MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700771 DEFINE_FUNCTION VAR(c_name)
772 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700773 // Outgoing argument set up
774 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700775 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700776 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700777 PUSH edx // pass referrer
778 PUSH ecx // pass arg2
779 PUSH eax // pass arg1
780 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
781 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700782 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700783 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
784 CALL_MACRO(return_macro) // return or deliver exception
785 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700786END_MACRO
787
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700788MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700789 DEFINE_FUNCTION VAR(c_name)
790 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700791 // Outgoing argument set up
792 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700793 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700794 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700795 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700796 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700797 PUSH ebx // pass referrer
798 PUSH edx // pass arg3
799 PUSH ecx // pass arg2
800 PUSH eax // pass arg1
801 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
802 // Thread*)
803 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700804 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700805 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
806 CALL_MACRO(return_macro) // return or deliver exception
807 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700808END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700809
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700810MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700811 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700812 jz 1f // if eax == 0 goto 1
813 ret // return
8141: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700815 DELIVER_PENDING_EXCEPTION
816END_MACRO
817
Ian Rogersd36c52e2012-04-09 16:29:25 -0700818MACRO0(RETURN_IF_EAX_ZERO)
819 testl %eax, %eax // eax == 0 ?
820 jnz 1f // if eax != 0 goto 1
821 ret // return
8221: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700823 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700824END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700825
jeffhaod66a8752012-05-22 15:30:16 -0700826MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700827 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700828 jne 1f // if exception field != 0 goto 1
829 ret // return
8301: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700831 DELIVER_PENDING_EXCEPTION
832END_MACRO
833
Mathieu Chartier7410f292013-11-24 13:17:35 -0800834// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700835GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800836
837// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
838DEFINE_FUNCTION art_quick_alloc_object_rosalloc
839 // Fast path rosalloc allocation.
840 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
841 // ebx, edx: free
842 PUSH edi
843 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
844 // Load the class (edx)
845 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
846 testl %edx, %edx // Check null class
847 jz .Lart_quick_alloc_object_rosalloc_slow_path
848 // Check class status
849 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
850 jne .Lart_quick_alloc_object_rosalloc_slow_path
851 // No fake dependence needed on x86
852 // between status and flags load,
853 // since each load is a load-acquire,
854 // no loads reordering.
855 // Check access flags has
856 // kAccClassIsFinalizable
857 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
858 jnz .Lart_quick_alloc_object_rosalloc_slow_path
859
860 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
861 // Check if the thread local allocation
862 // stack has room
863 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
864 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
865 jae .Lart_quick_alloc_object_rosalloc_slow_path
866
867 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
868 // Check if the size is for a thread
869 // local allocation
870 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
871 ja .Lart_quick_alloc_object_rosalloc_slow_path
872 decl %edi
873 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
874 // from object size.
875 // Align up the size by the rosalloc
876 // bracket quantum size and divide
877 // by the quantum size and subtract
878 // by 1. This code is a shorter but
879 // equivalent version.
880 // Load thread local rosalloc run (ebx)
881 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
882 // Load free_list head (edi),
883 // this will be the return value.
884 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
885 test %edi, %edi
886 jz .Lart_quick_alloc_object_rosalloc_slow_path
887 // Point of no slow path. Won't go to
888 // the slow path from here on. Ok to
889 // clobber eax and ecx.
890 movl %edi, %eax
891 // Load the next pointer of the head
892 // and update head of free list with
893 // next pointer
894 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
895 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
896 // Decrement size of free list by 1
897 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
898 // Store the class pointer in the
899 // header. This also overwrites the
900 // next pointer. The offsets are
901 // asserted to match.
902#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
903#error "Class pointer needs to overwrite next pointer."
904#endif
905 POISON_HEAP_REF edx
906 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
907 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
908 // Push the new object onto the thread
909 // local allocation stack and
910 // increment the thread local
911 // allocation stack top.
912 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
913 movl %eax, (%edi)
914 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
915 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
916 // No fence needed for x86.
917 POP edi
918 ret
919.Lart_quick_alloc_object_rosalloc_slow_path:
920 POP edi
921 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
922 // Outgoing argument set up
923 PUSH eax // alignment padding
924 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
925 CFI_ADJUST_CFA_OFFSET(4)
926 PUSH ecx
927 PUSH eax
928 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
929 addl LITERAL(16), %esp // pop arguments
930 CFI_ADJUST_CFA_OFFSET(-16)
931 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
932 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
933END_FUNCTION art_quick_alloc_object_rosalloc
934
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800935// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
936//
937// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
938MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
939 testl %edx, %edx // Check null class
940 jz VAR(slowPathLabel)
941 // Check class status.
942 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
943 jne VAR(slowPathLabel)
944 // No fake dependence needed on x86
945 // between status and flags load,
946 // since each load is a load-acquire,
947 // no loads reordering.
948 // Check access flags has
949 // kAccClassIsFinalizable
950 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
951 jnz VAR(slowPathLabel)
952 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
953 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
954 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
955 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
956 cmpl %edi, %esi // Check if it fits. OK to do this
957 // before rounding up the object size
958 // assuming the buf size alignment.
959 ja VAR(slowPathLabel)
960 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
961 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
962 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
963 // as allocated object.
964 addl %eax, %esi // Add the object size.
965 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
966 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
967 // Store the class pointer in the header.
968 // No fence needed for x86.
969 POISON_HEAP_REF edx
970 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
971 POP edi
972 POP esi
973 ret // Fast path succeeded.
974END_MACRO
975
976// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
977MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
978 POP edi
979 POP esi
980 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
981 // Outgoing argument set up
982 PUSH eax // alignment padding
983 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
984 CFI_ADJUST_CFA_OFFSET(4)
985 PUSH ecx
986 PUSH eax
987 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
988 addl LITERAL(16), %esp
989 CFI_ADJUST_CFA_OFFSET(-16)
990 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
991 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
992END_MACRO
993
994// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
995DEFINE_FUNCTION art_quick_alloc_object_tlab
996 // Fast path tlab allocation.
997 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
998 // EBX, EDX: free.
999#if defined(USE_READ_BARRIER)
1000 int3
1001 int3
1002#endif
1003 PUSH esi
1004 PUSH edi
1005 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1006 // Might need to break down into multiple instructions to get the base address in a register.
1007 // Load the class
1008 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1009 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1010.Lart_quick_alloc_object_tlab_slow_path:
1011 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1012END_FUNCTION art_quick_alloc_object_tlab
1013
1014// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1015DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1016 // Fast path region tlab allocation.
1017 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1018 // EBX, EDX: free.
1019#if !defined(USE_READ_BARRIER)
1020 int3
1021 int3
1022#endif
1023 PUSH esi
1024 PUSH edi
1025 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1026 // Might need to break down into multiple instructions to get the base address in a register.
1027 // Load the class
1028 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1029 // Read barrier for class load.
1030 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1031 jne .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1032.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1033 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1034.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1035 // The read barrier slow path. Mark the class.
1036 PUSH eax
1037 PUSH ecx
1038 // Outgoing argument set up
1039 subl MACRO_LITERAL(8), %esp // Alignment padding
1040 CFI_ADJUST_CFA_OFFSET(8)
1041 PUSH edx // Pass the class as the first param.
1042 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1043 movl %eax, %edx
1044 addl MACRO_LITERAL(12), %esp
1045 CFI_ADJUST_CFA_OFFSET(-12)
1046 POP ecx
1047 POP eax
1048 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1049.Lart_quick_alloc_object_region_tlab_slow_path:
1050 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1051END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001052
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001053ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1054ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1055ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1056ONE_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 -07001057
Ian Rogers832336b2014-10-08 15:35:22 -07001058TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001059
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001060DEFINE_FUNCTION art_quick_lock_object
1061 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001062 jz .Lslow_lock
1063.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001064 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001065 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001066 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001067 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
1068 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001069 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001070 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001071 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001072 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001073 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1074 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1075 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1076 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1077 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001078 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001079.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1080 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001081 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001082 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001083 movl %edx, %ecx // copy the lock word to check count overflow.
1084 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %ecx // zero the read barrier bits.
1085 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
1086 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 -08001087 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001088 movl %eax, %ecx // save obj to use eax for cmpxchg.
1089 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1090 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1091 // update lockword, cmpxchg necessary for read barrier bits.
1092 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1093 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001094 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001095.Llock_cmpxchg_fail:
1096 movl %ecx, %eax // restore eax
1097 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001098.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001099 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001100 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001101 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001102 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001103 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001104 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001105 PUSH eax // pass object
1106 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1107 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001108 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001109 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001110 RETURN_IF_EAX_ZERO
1111END_FUNCTION art_quick_lock_object
1112
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001113DEFINE_FUNCTION art_quick_lock_object_no_inline
1114 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1115 // Outgoing argument set up
1116 subl LITERAL(8), %esp // alignment padding
1117 CFI_ADJUST_CFA_OFFSET(8)
1118 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1119 CFI_ADJUST_CFA_OFFSET(4)
1120 PUSH eax // pass object
1121 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1122 addl LITERAL(16), %esp // pop arguments
1123 CFI_ADJUST_CFA_OFFSET(-16)
1124 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1125 RETURN_IF_EAX_ZERO
1126END_FUNCTION art_quick_lock_object_no_inline
1127
1128
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001129DEFINE_FUNCTION art_quick_unlock_object
1130 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001131 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001132.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001133 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001134 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001135 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001136 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001137 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001138 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001139 movl %ecx, %edx // copy the lock word to detect new count of 0.
1140 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED), %edx // zero the read barrier bits.
1141 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001142 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001143 // update lockword, cmpxchg necessary for read barrier bits.
1144 movl %eax, %edx // edx: obj
1145 movl %ecx, %eax // eax: old lock word.
1146 andl LITERAL(LOCK_WORD_READ_BARRIER_STATE_MASK), %ecx // ecx: new lock word zero except original rb bits.
1147#ifndef USE_READ_BARRIER
1148 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1149#else
1150 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1151 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1152#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001153 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001154.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1155 // update lockword, cmpxchg necessary for read barrier bits.
1156 movl %eax, %edx // edx: obj
1157 movl %ecx, %eax // eax: old lock word.
1158 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1159#ifndef USE_READ_BARRIER
1160 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1161#else
1162 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1163 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1164#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001165 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001166.Lunlock_cmpxchg_fail: // edx: obj
1167 movl %edx, %eax // restore eax
1168 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001169.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001170 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001171 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001172 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001173 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001174 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001175 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001176 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001177 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001178 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001179 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001180 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001181 RETURN_IF_EAX_ZERO
1182END_FUNCTION art_quick_unlock_object
1183
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001184DEFINE_FUNCTION art_quick_unlock_object_no_inline
1185 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1186 // Outgoing argument set up
1187 subl LITERAL(8), %esp // alignment padding
1188 CFI_ADJUST_CFA_OFFSET(8)
1189 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1190 CFI_ADJUST_CFA_OFFSET(4)
1191 PUSH eax // pass object
1192 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1193 addl LITERAL(16), %esp // pop arguments
1194 CFI_ADJUST_CFA_OFFSET(-16)
1195 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1196 RETURN_IF_EAX_ZERO
1197END_FUNCTION art_quick_unlock_object_no_inline
1198
Ian Rogers468532e2013-08-05 10:56:33 -07001199DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001200 PUSH eax // alignment padding
1201 PUSH ecx // pass arg2 - obj->klass
1202 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001203 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -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 Rogers468532e2013-08-05 10:56:33 -07001207END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001208
Ian Rogersa9a82542013-10-04 11:17:26 -07001209DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001210 PUSH eax // alignment padding
1211 PUSH ecx // pass arg2 - obj->klass
1212 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001213 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001214 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001215 jz 1f // jump forward if not assignable
1216 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001217 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001218 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001219
Andreas Gampe4360be22015-07-14 23:34:44 -07001220 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070012211:
Andreas Gampe4360be22015-07-14 23:34:44 -07001222 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001223 POP ecx
1224 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001225 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001226 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001227 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001228 PUSH eax // alignment padding
1229 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001230 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001231 PUSH ecx // pass arg2
1232 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001233 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001234 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001235END_FUNCTION art_quick_check_cast
1236
Man Cao1aee9002015-07-14 22:31:42 -07001237// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1238MACRO2(POP_REG_NE, reg, exclude_reg)
1239 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1240 addl MACRO_LITERAL(4), %esp
1241 CFI_ADJUST_CFA_OFFSET(-4)
1242 .else
1243 POP RAW_VAR(reg)
1244 .endif
1245END_MACRO
1246
1247 /*
1248 * Macro to insert read barrier, only used in art_quick_aput_obj.
1249 * obj_reg and dest_reg are registers, offset is a defined literal such as
1250 * MIRROR_OBJECT_CLASS_OFFSET.
1251 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1252 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1253 */
1254MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1255#ifdef USE_READ_BARRIER
1256 PUSH eax // save registers used in art_quick_aput_obj
1257 PUSH ebx
1258 PUSH edx
1259 PUSH ecx
1260 // Outgoing argument set up
1261 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1262 CFI_ADJUST_CFA_OFFSET(4)
1263 PUSH RAW_VAR(obj_reg) // pass obj_reg
1264 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1265 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1266 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1267 .ifnc RAW_VAR(dest_reg), eax
1268 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1269 .endif
1270 addl MACRO_LITERAL(12), %esp // pop arguments
1271 CFI_ADJUST_CFA_OFFSET(-12)
1272 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1273 POP_REG_NE edx, RAW_VAR(dest_reg)
1274 POP_REG_NE ebx, RAW_VAR(dest_reg)
1275 .ifc RAW_VAR(pop_eax), true
1276 POP_REG_NE eax, RAW_VAR(dest_reg)
1277 .endif
1278#else
1279 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1280 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1281#endif // USE_READ_BARRIER
1282END_MACRO
1283
Ian Rogersa9a82542013-10-04 11:17:26 -07001284 /*
1285 * Entry from managed code for array put operations of objects where the value being stored
1286 * needs to be checked for compatibility.
1287 * eax = array, ecx = index, edx = value
1288 */
1289DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1290 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001291 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1292 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001293END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1294
1295DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001296 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001297 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001298 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001299 mov %ecx, %eax
1300 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001301 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001302END_FUNCTION art_quick_aput_obj_with_bound_check
1303
1304DEFINE_FUNCTION art_quick_aput_obj
1305 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001306 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001307 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1308 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001309 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001310#if defined(USE_READ_BARRIER)
1311 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1312 cmpl %eax, %ebx
1313 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001314 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001315#elif defined(USE_HEAP_POISONING)
1316 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001317 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1318 UNPOISON_HEAP_REF eax
1319 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001320 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001321#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001322 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001323#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001324 jne .Lcheck_assignability
1325.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001326 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001327 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001328 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1329 shrl LITERAL(7), %eax
1330 movb %dl, (%edx, %eax)
1331 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001332.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001333 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001334 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001335.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001336 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001337 PUSH ecx
1338 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001339#if defined(USE_READ_BARRIER)
1340 subl LITERAL(4), %esp // alignment padding
1341 CFI_ADJUST_CFA_OFFSET(4)
1342 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1343 subl LITERAL(4), %esp // alignment padding
1344 CFI_ADJUST_CFA_OFFSET(4)
1345 PUSH eax // pass arg2 - type of the value to be stored
1346#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001347 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001348 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001349 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001350 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001351 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001352#else
Man Cao63069212015-08-21 15:51:39 -07001353 subl LITERAL(8), %esp // alignment padding
1354 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001355 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001356 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001357#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001358 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001359 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001360 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001361 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001362 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001363 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001364 POP edx
1365 POP ecx
1366 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001367 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001368 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001369 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1370 shrl LITERAL(7), %eax
1371 movb %dl, (%edx, %eax)
1372 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001373 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001374.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001375 POP edx
1376 POP ecx
1377 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001378 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001379 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001380 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001381 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001382 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001383 PUSH edx // pass arg2 - value
1384 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001385 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001386 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001387END_FUNCTION art_quick_aput_obj
1388
Logan Chien8dbb7082013-01-25 20:31:17 +08001389DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001390 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001391 PUSH edx // pass arg3
1392 PUSH ecx // pass arg2
1393 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001394 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001395 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001396 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001397 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001398END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001399
Logan Chien8dbb7082013-01-25 20:31:17 +08001400NO_ARG_DOWNCALL art_quick_test_suspend, artTestSuspendFromCode, ret
Ian Rogers7caad772012-03-30 01:07:54 -07001401
Ian Rogers468532e2013-08-05 10:56:33 -07001402DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001403 subl LITERAL(12), %esp // alignment padding, room for argument
1404 CFI_ADJUST_CFA_OFFSET(12)
1405 movsd %xmm0, 0(%esp) // arg a
1406 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001407 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001408 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001409 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001410END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001411
Ian Rogers468532e2013-08-05 10:56:33 -07001412DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001413 subl LITERAL(12), %esp // alignment padding
1414 CFI_ADJUST_CFA_OFFSET(12)
1415 movss %xmm0, 0(%esp) // arg a
1416 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001417 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001418 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001419 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001420END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001421
Ian Rogers468532e2013-08-05 10:56:33 -07001422DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001423 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001424 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001425 PUSH ebx // pass arg4 b.hi
1426 PUSH edx // pass arg3 b.lo
1427 PUSH ecx // pass arg2 a.hi
1428 PUSH eax // pass arg1 a.lo
1429 call SYMBOL(artLdiv) // (jlong a, jlong b)
1430 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001431 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001432 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001433END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001434
Ian Rogersa9a82542013-10-04 11:17:26 -07001435DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001436 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001437 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001438 PUSH ebx // pass arg4 b.hi
1439 PUSH edx // pass arg3 b.lo
1440 PUSH ecx // pass arg2 a.hi
1441 PUSH eax // pass arg1 a.lo
1442 call SYMBOL(artLmod) // (jlong a, jlong b)
1443 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001444 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001445 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001446END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001447
Ian Rogers468532e2013-08-05 10:56:33 -07001448DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001449 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1450 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1451 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001452 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001453 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001454 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001455END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001456
Ian Rogers468532e2013-08-05 10:56:33 -07001457DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001458 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001459 xchg %edx, %ecx
1460 shld %cl,%eax,%edx
1461 shl %cl,%eax
1462 test LITERAL(32), %cl
1463 jz 1f
1464 mov %eax, %edx
1465 xor %eax, %eax
14661:
1467 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001468END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001469
Ian Rogers468532e2013-08-05 10:56:33 -07001470DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001471 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001472 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001473 shrd %cl,%edx,%eax
1474 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001475 test LITERAL(32),%cl
1476 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001477 mov %edx, %eax
1478 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014791:
1480 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001481END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001482
Ian Rogers468532e2013-08-05 10:56:33 -07001483DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001484 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001485 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001486 shrd %cl,%edx,%eax
1487 shr %cl,%edx
1488 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001489 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001490 mov %edx, %eax
1491 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070014921:
1493 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001494END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001495
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001496ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1497ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1498ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1499ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1500ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1501ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1502ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001503
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001504TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1505TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1506TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1507TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1508TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1509TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1510TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001511
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001512TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1513TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1514TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1515TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001516
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001517THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1518THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1519THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1520THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1521
1522// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001523DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001524 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001525 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001526 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001527 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001528 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001529 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001530 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001531 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001532 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1533 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001534 PUSH ebx // pass high half of new_val
1535 PUSH edx // pass low half of new_val
1536 PUSH ecx // pass object
1537 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001538 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001539 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001540 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001541 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001542 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001543END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001544
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001545// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1546// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001547DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001548 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1549 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001550 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001551 movd %xmm0, %ebx
1552 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001553 subl LITERAL(12), %esp // alignment padding
1554 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001555 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001556 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001557 PUSH ebx // pass high half of new_val
1558 PUSH edx // pass low half of new_val
1559 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001560 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001561 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001562 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001563 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001564 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001565 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001566END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001567
Logan Chien8dbb7082013-01-25 20:31:17 +08001568DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001569 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001570 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001571 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001572 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001573 PUSH ecx // pass receiver
1574 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001575 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001576 movd %eax, %xmm0 // place return value also into floating point return value
1577 movd %edx, %xmm1
1578 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001579 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1580 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1581 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001582 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001583END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001584
Jeff Hao88474b42013-10-23 16:24:40 -07001585 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001586 * Called to resolve an imt conflict.
1587 * eax is the conflict ArtMethod.
1588 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1589 *
1590 * Note that this stub writes to eax.
1591 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001592 */
1593DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001594 PUSH EDI
1595 movl 8(%esp), %edi // Load referrer
1596 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1597 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1598 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001599 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001600 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1601 popl %eax // Pop ImtConflictTable.
1602 CFI_ADJUST_CFA_OFFSET(-4)
1603.Limt_table_iterate:
1604 cmpl %edi, 0(%eax)
1605 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001606 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001607 // and jump to it.
1608 POP EDI
1609 movl __SIZEOF_POINTER__(%eax), %eax
1610 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1611.Limt_table_next_entry:
1612 // If the entry is null, the interface method is not in the ImtConflictTable.
1613 cmpl LITERAL(0), 0(%eax)
1614 jz .Lconflict_trampoline
1615 // Iterate over the entries of the ImtConflictTable.
1616 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1617 jmp .Limt_table_iterate
1618.Lconflict_trampoline:
1619 // Call the runtime stub to populate the ImtConflictTable and jump to the
1620 // resolved method.
1621 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001622 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001623END_FUNCTION art_quick_imt_conflict_trampoline
1624
Ian Rogers468532e2013-08-05 10:56:33 -07001625DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001626 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001627 movl %esp, %edi
1628 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001629 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001630 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001631 PUSH ecx // pass receiver
1632 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001633 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001634 movl %eax, %edi // remember code pointer in EDI
1635 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001636 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001637 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001638 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001639 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070016401:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001641 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001642 DELIVER_PENDING_EXCEPTION
1643END_FUNCTION art_quick_resolution_trampoline
1644
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001645DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001646 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001647 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001648 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001649 subl LITERAL(5120), %esp
1650 // prepare for artQuickGenericJniTrampoline call
1651 // (Thread*, SP)
1652 // (esp) 4(esp) <= C calling convention
1653 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001654
1655 subl LITERAL(8), %esp // Padding for 16B alignment.
1656 pushl %ebp // Pass SP (to ArtMethod).
1657 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001658 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001659
Andreas Gampec200a4a2014-06-16 18:39:09 -07001660 // The C call will have registered the complete save-frame on success.
1661 // The result of the call is:
1662 // eax: pointer to native code, 0 on error.
1663 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001664
Andreas Gampec200a4a2014-06-16 18:39:09 -07001665 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001666 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001667 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001668
Andreas Gampec200a4a2014-06-16 18:39:09 -07001669 // Release part of the alloca.
1670 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001671
1672 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001673 // Native call.
1674 call *%eax
1675
Andreas Gampe779f8c92014-06-09 18:29:38 -07001676 // result sign extension is handled in C code
1677 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001678 // (Thread*, result, result_f)
1679 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001680 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001681
Andreas Gampe4360be22015-07-14 23:34:44 -07001682 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001683 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001684 pushl %edx // Pass int result.
1685 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001686 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001687 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001688
Andreas Gampe779f8c92014-06-09 18:29:38 -07001689 // Pending exceptions possible.
1690 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1691 testl %ebx, %ebx
1692 jnz .Lexception_in_native
1693
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001694 // Tear down the alloca.
1695 movl %ebp, %esp
1696 CFI_DEF_CFA_REGISTER(esp)
1697
1698
Andreas Gampe779f8c92014-06-09 18:29:38 -07001699 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001700 // Remove space for FPR args and EAX
1701 addl LITERAL(4 + 4 * 8), %esp
1702 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1703
Andreas Gampe779f8c92014-06-09 18:29:38 -07001704 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001705 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001706 CFI_ADJUST_CFA_OFFSET(-4)
1707 POP ebx
1708 POP ebp // Restore callee saves
1709 POP esi
1710 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001711 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001712 movd %eax, %xmm0
1713 movd %edx, %xmm1
1714 punpckldq %xmm1, %xmm0
1715 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001716.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001717 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1718 // Do a call to push a new save-all frame required by the runtime.
1719 call .Lexception_call
1720.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001721 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001722END_FUNCTION art_quick_generic_jni_trampoline
1723
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001724DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001725 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001726 mov %esp, %edx // remember SP
1727 PUSH eax // alignment padding
1728 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001729 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001730 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001731 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001732 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001733 addl LITERAL(16), %esp // pop arguments
1734 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001735
1736 // Return eax:edx in xmm0 also.
1737 movd %eax, %xmm0
1738 movd %edx, %xmm1
1739 punpckldq %xmm1, %xmm0
1740
1741 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1742 CFI_ADJUST_CFA_OFFSET(-48)
1743
Andreas Gampe4360be22015-07-14 23:34:44 -07001744 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001745 POP esi
1746 POP edi
1747
Ian Rogers7db619b2013-01-16 18:35:48 -08001748 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001749END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001750
jeffhao7e4fcb82013-01-10 18:11:08 -08001751 /*
1752 * Routine that intercepts method calls and returns.
1753 */
Ian Rogers468532e2013-08-05 10:56:33 -07001754DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001755 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001756 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001757 subl LITERAL(12), %esp // Align stack.
1758 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001759 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001760 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001761 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001762 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001763 PUSH ecx // Pass receiver.
1764 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001765 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001766 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001767 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001768 movl 60(%esp), %edi // Restore edi.
1769 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001770 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001771 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001772 movl %ebx, 64(%esp)
1773 movl 0(%esp), %eax // Restore eax.
1774 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1775 movsd 8(%esp), %xmm0
1776 movsd 16(%esp), %xmm1
1777 movsd 24(%esp), %xmm2
1778 movsd 32(%esp), %xmm3
1779
1780 // Restore GPRs.
1781 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001782 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001783 movl 48(%esp), %ebx // Restore ebx.
1784 movl 52(%esp), %ebp // Restore ebp.
1785 movl 56(%esp), %esi // Restore esi.
1786 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001787 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001788 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001789END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001790
Ian Rogers468532e2013-08-05 10:56:33 -07001791DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001792 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001793 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001794 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001795 mov %esp, %ecx // Remember SP
1796 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001797 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001798 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001799 PUSH edx // Save gpr return value.
1800 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001801 subl LITERAL(16), %esp // Align stack
1802 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001803 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001804 PUSH edx // Pass gpr return value.
1805 PUSH eax
1806 PUSH ecx // Pass SP.
1807 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001808 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001809 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001810 mov %eax, %ecx // Move returned link register.
1811 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001812 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001813 movl %edx, %ebx // Move returned link register for deopt
1814 // (ebx is pretending to be our LR).
1815 POP eax // Restore gpr return value.
1816 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001817 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001818 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001819 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001820 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001821 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001822 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001823 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001824END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001825
jeffhao7e4fcb82013-01-10 18:11:08 -08001826 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001827 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1828 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001829 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001830DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001831 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001832 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1833 subl LITERAL(12), %esp // Align stack.
1834 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001835 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001836 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001837 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001838 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001839END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001840
jeffhao86e46712012-08-08 17:30:59 -07001841 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001842 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001843 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001844 */
1845DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1846 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1847 subl LITERAL(12), %esp // Align stack.
1848 CFI_ADJUST_CFA_OFFSET(12)
1849 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1850 CFI_ADJUST_CFA_OFFSET(4)
1851 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1852 UNREACHABLE
1853END_FUNCTION art_quick_deoptimize_from_compiled_code
1854
1855 /*
jeffhao86e46712012-08-08 17:30:59 -07001856 * String's compareTo.
1857 *
1858 * On entry:
1859 * eax: this string object (known non-null)
1860 * ecx: comp string object (known non-null)
1861 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001862DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001863 PUSH esi // push callee save reg
1864 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001865 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1866 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001867 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1868 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001869 /* Calculate min length and count diff */
1870 mov %edx, %ecx
1871 mov %edx, %eax
1872 subl %ebx, %eax
1873 cmovg %ebx, %ecx
1874 /*
1875 * At this point we have:
1876 * eax: value to return if first part of strings are equal
1877 * ecx: minimum among the lengths of the two strings
1878 * esi: pointer to this string data
1879 * edi: pointer to comp string data
1880 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001881 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001882 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001883 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001884.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001885 POP edi // pop callee save reg
1886 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001887 ret
1888 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001889.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001890 movzwl -2(%esi), %eax // get last compared char from this string
1891 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001892 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001893 POP edi // pop callee save reg
1894 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001895 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001896END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001897
Dave Allison8ce6b902014-08-26 11:07:58 -07001898// Return from a nested signal:
1899// Entry:
1900// eax: address of jmp_buf in TLS
1901
1902DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001903 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001904 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001905 PUSH ecx // second arg to longjmp (1)
1906 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001907 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001908 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001909END_FUNCTION art_nested_signal_return
1910
Roland Levillain02b75802016-07-13 11:54:35 +01001911// Create a function `name` calling the ReadBarrier::Mark routine,
1912// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001913// `reg`, saving and restoring all caller-save registers.
1914//
1915// If `reg` is different from `eax`, the generated function follows a
1916// non-standard runtime calling convention:
1917// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001918// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01001919// - register `reg` is used to return the result of this function
1920// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01001921// - EAX is treated like a normal (non-argument) caller-save register;
1922// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001923// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001924MACRO2(READ_BARRIER_MARK_REG, name, reg)
1925 DEFINE_FUNCTION VAR(name)
Roland Levillain4359e612016-07-20 11:32:19 +01001926 // Save all potentially live caller-save core registers.
1927 PUSH eax
1928 PUSH ecx
1929 PUSH edx
1930 PUSH ebx
1931 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
1932 // and create space for caller-save floating-point registers.
1933 subl MACRO_LITERAL(4 + 8 * 8), %esp
1934 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
1935 // Save all potentially live caller-save floating-point registers.
1936 movsd %xmm0, 0(%esp)
1937 movsd %xmm1, 8(%esp)
1938 movsd %xmm2, 16(%esp)
1939 movsd %xmm3, 24(%esp)
1940 movsd %xmm4, 32(%esp)
1941 movsd %xmm5, 40(%esp)
1942 movsd %xmm6, 48(%esp)
1943 movsd %xmm7, 56(%esp)
1944
1945 subl LITERAL(4), %esp // alignment padding
1946 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01001947 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
1948 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01001949 .ifnc RAW_VAR(reg), eax
1950 movl %eax, REG_VAR(reg) // return result into `reg`
1951 .endif
1952 addl LITERAL(8), %esp // pop argument and remove padding
1953 CFI_ADJUST_CFA_OFFSET(-8)
1954
1955 // Restore floating-point registers.
1956 movsd 0(%esp), %xmm0
1957 movsd 8(%esp), %xmm1
1958 movsd 16(%esp), %xmm2
1959 movsd 24(%esp), %xmm3
1960 movsd 32(%esp), %xmm4
1961 movsd 40(%esp), %xmm5
1962 movsd 48(%esp), %xmm6
1963 movsd 56(%esp), %xmm7
1964 // Remove floating-point registers and padding.
1965 addl MACRO_LITERAL(8 * 8 + 4), %esp
1966 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
1967 // Restore core regs, except `reg`, as it is used to return the
1968 // result of this function (simply remove it from the stack instead).
1969 POP_REG_NE ebx, RAW_VAR(reg)
1970 POP_REG_NE edx, RAW_VAR(reg)
1971 POP_REG_NE ecx, RAW_VAR(reg)
1972 POP_REG_NE eax, RAW_VAR(reg)
Roland Levillain02b75802016-07-13 11:54:35 +01001973 ret
1974 END_FUNCTION VAR(name)
1975END_MACRO
1976
Roland Levillain4359e612016-07-20 11:32:19 +01001977READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01001978READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
1979READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
1980READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
1981READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
1982// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
1983// cannot be used to pass arguments.
1984READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
1985READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00001986
Man Cao1aee9002015-07-14 22:31:42 -07001987DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00001988 PUSH edx // pass arg3 - offset
1989 PUSH ecx // pass arg2 - obj
1990 PUSH eax // pass arg1 - ref
1991 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
1992 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07001993 CFI_ADJUST_CFA_OFFSET(-12)
1994 ret
1995END_FUNCTION art_quick_read_barrier_slow
1996
Roland Levillain0d5a2812015-11-13 10:07:31 +00001997DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01001998 subl LITERAL(8), %esp // alignment padding
1999 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002000 PUSH eax // pass arg1 - root
2001 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002002 addl LITERAL(12), %esp // pop argument and remove padding
2003 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002004 ret
2005END_FUNCTION art_quick_read_barrier_for_root_slow
2006
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002007 /*
2008 * On stack replacement stub.
2009 * On entry:
2010 * [sp] = return address
2011 * [sp + 4] = stack to copy
2012 * [sp + 8] = size of stack
2013 * [sp + 12] = pc to call
2014 * [sp + 16] = JValue* result
2015 * [sp + 20] = shorty
2016 * [sp + 24] = thread
2017 */
2018DEFINE_FUNCTION art_quick_osr_stub
2019 // Save native callee saves.
2020 PUSH ebp
2021 PUSH ebx
2022 PUSH esi
2023 PUSH edi
2024 mov 4+16(%esp), %esi // ESI = argument array
2025 mov 8+16(%esp), %ecx // ECX = size of args
2026 mov 12+16(%esp), %ebx // EBX = pc to call
2027 mov %esp, %ebp // Save stack pointer
2028 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2029 PUSH ebp // Save old stack pointer
2030 subl LITERAL(12), %esp // Align stack
2031 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2032 call .Losr_entry
2033
2034 // Restore stack pointer.
2035 addl LITERAL(12), %esp
2036 POP ebp
2037 mov %ebp, %esp
2038
2039 // Restore callee saves.
2040 POP edi
2041 POP esi
2042 POP ebx
2043 POP ebp
2044 mov 16(%esp), %ecx // Get JValue result
2045 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2046 mov %edx, 4(%ecx) // Store the other half of the result
2047 mov 20(%esp), %edx // Get the shorty
2048 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2049 je .Losr_return_double_quick
2050 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2051 je .Losr_return_float_quick
2052 ret
2053.Losr_return_double_quick:
2054 movsd %xmm0, (%ecx) // Store the floating point result
2055 ret
2056.Losr_return_float_quick:
2057 movss %xmm0, (%ecx) // Store the floating point result
2058 ret
2059.Losr_entry:
2060 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2061 subl %ecx, %esp
2062 mov %esp, %edi // EDI = beginning of stack
2063 rep movsb // while (ecx--) { *edi++ = *esi++ }
2064 jmp *%ebx
2065END_FUNCTION art_quick_osr_stub
2066
Elliott Hughes787ec202012-03-29 17:14:15 -07002067 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002068UNIMPLEMENTED art_quick_memcmp16