blob: 68ba0cf986b5302e926da7d66360adcf0ef2f082 [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 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100225 * Macro that sets up the callee save frame to conform with
226 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
227 */
228MACRO2(SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME, got_reg, temp_reg)
229 // Save core registers.
230 PUSH edi
231 PUSH esi
232 PUSH ebp
233 PUSH ebx
234 PUSH edx
235 PUSH ecx
236 PUSH eax
237 // Create space for FPR registers and stack alignment padding.
238 subl MACRO_LITERAL(12 + 8 * 8), %esp
239 CFI_ADJUST_CFA_OFFSET(12 + 8 * 8)
240 // Save FPRs.
241 movsd %xmm0, 12(%esp)
242 movsd %xmm1, 20(%esp)
243 movsd %xmm2, 28(%esp)
244 movsd %xmm3, 36(%esp)
245 movsd %xmm4, 44(%esp)
246 movsd %xmm5, 52(%esp)
247 movsd %xmm6, 60(%esp)
248 movsd %xmm7, 68(%esp)
249
250 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
251 // Load Runtime::instance_ from GOT.
252 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
253 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
254 // Push save everything callee-save method.
255 pushl RUNTIME_SAVE_EVERYTHING_CALLEE_SAVE_FRAME_OFFSET(REG_VAR(temp_reg))
256 CFI_ADJUST_CFA_OFFSET(4)
257 // Store esp as the stop quick frame.
258 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
259
260 // Ugly compile-time check, but we only have the preprocessor.
261 // Last +4: implicit return address pushed on stack when caller made call.
262#if (FRAME_SIZE_SAVE_EVERYTHING_CALLEE_SAVE != 7*4 + 8*8 + 12 + 4 + 4)
263#error "SAVE_EVERYTHING_CALLEE_SAVE_FRAME(X86) size not as expected."
264#endif
265END_MACRO
266
267MACRO0(RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME)
268 // Restore FPRs. Method and padding is still on the stack.
269 movsd 16(%esp), %xmm0
270 movsd 24(%esp), %xmm1
271 movsd 32(%esp), %xmm2
272 movsd 40(%esp), %xmm3
273 movsd 48(%esp), %xmm4
274 movsd 56(%esp), %xmm5
275 movsd 64(%esp), %xmm6
276 movsd 72(%esp), %xmm7
277
278 // Remove save everything callee save method, stack alignment padding and FPRs.
279 addl MACRO_LITERAL(16 + 8 * 8), %esp
280 CFI_ADJUST_CFA_OFFSET(-(16 + 8 * 8))
281
282 // Restore core registers.
283 POP eax
284 POP ecx
285 POP edx
286 POP ebx
287 POP ebp
288 POP esi
289 POP edi
290END_MACRO
291
292 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700293 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
294 * exception is Thread::Current()->exception_.
295 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700296MACRO0(DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700297 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700298 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100299 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700300 CFI_ADJUST_CFA_OFFSET(12)
301 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800302 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700303 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700304 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700305END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700306
Elliott Hughes787ec202012-03-29 17:14:15 -0700307MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700308 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700309 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700310 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700311 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700312 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700313 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800314 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700315 call CALLVAR(cxx_name) // cxx_name(Thread*)
316 UNREACHABLE
317 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700318END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700319
Elliott Hughes787ec202012-03-29 17:14:15 -0700320MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700321 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700322 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700323 mov %esp, %ecx
324 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100325 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700326 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700327 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800328 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700329 PUSH eax // pass arg1
330 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
331 UNREACHABLE
332 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700333END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700334
Elliott Hughes787ec202012-03-29 17:14:15 -0700335MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700336 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700337 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700338 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700339 PUSH eax // alignment padding
340 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800341 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700342 PUSH ecx // pass arg2
343 PUSH eax // pass arg1
344 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
345 UNREACHABLE
346 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700347END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700348
349 /*
350 * Called by managed code to create and deliver a NullPointerException.
351 */
Ian Rogers468532e2013-08-05 10:56:33 -0700352NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700353
354 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100355 * Call installed by a signal handler to create and deliver a NullPointerException.
356 */
357ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception_from_signal, artThrowNullPointerExceptionFromSignal
358
359 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700360 * Called by managed code to create and deliver an ArithmeticException.
361 */
Ian Rogers468532e2013-08-05 10:56:33 -0700362NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700363
364 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700365 * Called by managed code to create and deliver a StackOverflowError.
366 */
Ian Rogers468532e2013-08-05 10:56:33 -0700367NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700368
369 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700370 * Called by managed code, saves callee saves and then calls artThrowException
371 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
372 */
Ian Rogers468532e2013-08-05 10:56:33 -0700373ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700374
375 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700376 * Called by managed code to create and deliver a NoSuchMethodError.
377 */
Ian Rogers468532e2013-08-05 10:56:33 -0700378ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700379
380 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700381 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
382 * index, arg2 holds limit.
383 */
Ian Rogers468532e2013-08-05 10:56:33 -0700384TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700385
386 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100387 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
388 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
389 */
390TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
391
392 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700393 * All generated callsites for interface invokes and invocation slow paths will load arguments
394 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100395 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700396 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
397 *
398 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
399 * of the target Method* in r0 and method->code_ in r1.
400 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700401 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700402 * thread and we branch to another stub to deliver it.
403 *
404 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
405 * pointing back to the original caller.
406 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700407MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700408 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700409 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000410
Ian Rogers7caad772012-03-30 01:07:54 -0700411 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800412 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700413 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800414 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800415 PUSH ecx // pass arg2
416 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700417 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700418 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100419 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
420 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000421
422 // Restore FPRs.
423 movsd 0(%esp), %xmm0
424 movsd 8(%esp), %xmm1
425 movsd 16(%esp), %xmm2
426 movsd 24(%esp), %xmm3
427
428 // Remove space for FPR args.
429 addl MACRO_LITERAL(4 * 8), %esp
430 CFI_ADJUST_CFA_OFFSET(-4 * 8)
431
Dave Allisonbbb32c22013-11-05 18:25:18 -0800432 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800433 POP edx
434 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800435 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800436 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700437 // Swap EDI callee save with code pointer.
438 xchgl %edi, (%esp)
439 testl %eax, %eax // Branch forward if exception pending.
440 jz 1f
441 // Tail call to intended method.
442 ret
4431:
jeffhao20b5c6c2012-05-21 14:15:18 -0700444 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800445 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700446 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700447END_MACRO
448MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700449 DEFINE_FUNCTION VAR(c_name)
450 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
451 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700452END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700453
Logan Chien8dbb7082013-01-25 20:31:17 +0800454INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700455
Logan Chien8dbb7082013-01-25 20:31:17 +0800456INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
457INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
458INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
459INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700460
Jeff Hao5d917302013-02-27 17:57:33 -0800461 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000462 * Helper for quick invocation stub to set up XMM registers.
463 * Increments shorty and arg_array and clobbers temp_char.
464 * Branches to finished if it encounters the end of the shorty.
465 */
466MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
4671: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700468 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
469 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
470 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
471 je VAR(finished) // goto finished
472 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
473 je 2f // goto FOUND_DOUBLE
474 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
475 je 3f // goto FOUND_FLOAT
476 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000477 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700478 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
479 jne 1b // goto LOOP
480 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
481 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004822: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700483 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
484 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000485 jmp 4f
4863: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700487 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
488 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00004894:
490END_MACRO
491
492 /*
493 * Helper for quick invocation stub to set up GPR registers.
494 * Increments shorty and arg_array, and returns the current short character in
495 * temp_char. Branches to finished if it encounters the end of the shorty.
496 */
497MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
4981: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700499 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
500 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
501 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
502 je VAR(finished) // goto finished
503 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
504 je 3f // goto SKIP_FLOAT
505 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
506 je 4f // goto SKIP_DOUBLE
507 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005083: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700509 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
510 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005114: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700512 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
513 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005145:
515END_MACRO
516
517 /*
518 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700519 * On entry:
520 * [sp] = return address
521 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700522 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700523 * [sp + 12] = size of argument array in bytes
524 * [sp + 16] = (managed) thread pointer
525 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800526 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800527 */
528DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000529 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800530 PUSH ebp // save ebp
531 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000532 PUSH esi // save esi
533 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000534 // Set up argument XMM registers.
535 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
536 addl LITERAL(1), %esi
537 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
538 addl LITERAL(4), %edi
539 // Clobbers ESI, EDI, EAX.
540 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
541 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
542 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
543 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
544 .balign 16
545.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800546 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800547 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000548 mov 28(%ebp), %ebx // get arg array size
549 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
550 addl LITERAL(36), %ebx
551 // align frame size to 16 bytes
552 andl LITERAL(0xFFFFFFF0), %ebx
553 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800554 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000555
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700556 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000557
558 // Copy arg array into stack.
559 movl 28(%ebp), %ecx // ECX = size of args
560 movl 24(%ebp), %esi // ESI = argument array
561 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
562 rep movsb // while (ecx--) { *edi++ = *esi++ }
563
564 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
565 addl LITERAL(1), %esi
566 mov 24(%ebp), %edi // EDI := arg_array
567 mov 0(%edi), %ecx // ECX := this pointer
568 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
569
570 // Enumerate the possible cases for loading GPRS.
571 // edx (and maybe ebx):
572 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
573 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
574 je .LfirstLong
575 // Must be an integer value.
576 movl (%edi), %edx
577 addl LITERAL(4), %edi // arg_array++
578
579 // Now check ebx
580 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500581 // Must be first word of a long, or an integer. First word of long doesn't
582 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000583 movl (%edi), %ebx
584 jmp .Lgpr_setup_finished
585.LfirstLong:
586 movl (%edi), %edx
587 movl 4(%edi), %ebx
588 // Nothing left to load.
589.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000590 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700591 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800592 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800593 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000594 POP edi // pop edi
595 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800596 POP ebx // pop ebx
597 POP ebp // pop ebp
598 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800599 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800600 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800601 mov 24(%esp), %edx // get the shorty
602 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800603 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800604 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800605 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700606 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800607.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800608 movsd %xmm0, (%ecx) // store the floating point result
609 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800610.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800611 movss %xmm0, (%ecx) // store the floating point result
612 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800613END_FUNCTION art_quick_invoke_stub
614
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000615 /*
616 * Quick invocation stub (static).
617 * On entry:
618 * [sp] = return address
619 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700620 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000621 * [sp + 12] = size of argument array in bytes
622 * [sp + 16] = (managed) thread pointer
623 * [sp + 20] = JValue* result
624 * [sp + 24] = shorty
625 */
626DEFINE_FUNCTION art_quick_invoke_static_stub
627 // Save the non-volatiles.
628 PUSH ebp // save ebp
629 PUSH ebx // save ebx
630 PUSH esi // save esi
631 PUSH edi // save edi
632 // Set up argument XMM registers.
633 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
634 addl LITERAL(1), %esi
635 mov 8+16(%esp), %edi // EDI := arg_array
636 // Clobbers ESI, EDI, EAX.
637 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
638 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
639 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
640 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
641 .balign 16
642.Lxmm_setup_finished2:
643 mov %esp, %ebp // copy value of stack pointer into base pointer
644 CFI_DEF_CFA_REGISTER(ebp)
645 mov 28(%ebp), %ebx // get arg array size
646 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
647 addl LITERAL(36), %ebx
648 // align frame size to 16 bytes
649 andl LITERAL(0xFFFFFFF0), %ebx
650 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
651 subl %ebx, %esp // reserve stack space for argument array
652
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700653 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000654
655 // Copy arg array into stack.
656 movl 28(%ebp), %ecx // ECX = size of args
657 movl 24(%ebp), %esi // ESI = argument array
658 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
659 rep movsb // while (ecx--) { *edi++ = *esi++ }
660
661 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
662 addl LITERAL(1), %esi
663 mov 24(%ebp), %edi // EDI := arg_array
664
665 // Enumerate the possible cases for loading GPRS.
666 // ecx (and maybe edx)
667 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
668 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
669 je .LfirstLong2
670 // Must be an integer value. Load into ECX.
671 movl (%edi), %ecx
672 addl LITERAL(4), %edi // arg_array++
673
674 // Now check edx (and maybe ebx).
675 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
676 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
677 je .LSecondLong2
678 // Must be an integer. Load into EDX.
679 movl (%edi), %edx
680 addl LITERAL(4), %edi // arg_array++
681
682 // Is there anything for ebx?
683 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500684 // Must be first word of a long, or an integer. First word of long doesn't
685 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000686 movl (%edi), %ebx
687 jmp .Lgpr_setup_finished2
688.LSecondLong2:
689 // EDX:EBX is long. That is all.
690 movl (%edi), %edx
691 movl 4(%edi), %ebx
692 jmp .Lgpr_setup_finished2
693.LfirstLong2:
694 // ECX:EDX is a long
695 movl (%edi), %ecx
696 movl 4(%edi), %edx
697 addl LITERAL(8), %edi // arg_array += 2
698
699 // Anything for EBX?
700 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500701 // Must be first word of a long, or an integer. First word of long doesn't
702 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000703 movl (%edi), %ebx
704 jmp .Lgpr_setup_finished2
705 // Nothing left to load.
706.Lgpr_setup_finished2:
707 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700708 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000709 mov %ebp, %esp // restore stack pointer
710 CFI_DEF_CFA_REGISTER(esp)
711 POP edi // pop edi
712 POP esi // pop esi
713 POP ebx // pop ebx
714 POP ebp // pop ebp
715 mov 20(%esp), %ecx // get result pointer
716 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
717 mov %edx, 4(%ecx) // store the other half of the result
718 mov 24(%esp), %edx // get the shorty
719 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
720 je .Lreturn_double_quick2
721 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
722 je .Lreturn_float_quick2
723 ret
724.Lreturn_double_quick2:
725 movsd %xmm0, (%ecx) // store the floating point result
726 ret
727.Lreturn_float_quick2:
728 movss %xmm0, (%ecx) // store the floating point result
729 ret
730END_FUNCTION art_quick_invoke_static_stub
731
Ian Rogersd36c52e2012-04-09 16:29:25 -0700732MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700733 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700734 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700735 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700736 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700737 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700738 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800739 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700740 PUSH eax // pass arg1
741 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
742 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800743 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700744 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
745 CALL_MACRO(return_macro) // return or deliver exception
746 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700747END_MACRO
748
749MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700750 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700751 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700752 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700753 PUSH eax // push padding
754 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800755 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700756 PUSH ecx // pass arg2
757 PUSH eax // pass arg1
758 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
759 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800760 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700761 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
762 CALL_MACRO(return_macro) // return or deliver exception
763 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700764END_MACRO
765
Ian Rogersd36c52e2012-04-09 16:29:25 -0700766MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700767 DEFINE_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700768 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700769 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700770 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800771 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700772 PUSH edx // pass arg3
773 PUSH ecx // pass arg2
774 PUSH eax // pass arg1
775 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
776 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700777 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700778 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
779 CALL_MACRO(return_macro) // return or deliver exception
780 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700781END_MACRO
782
Jeff Hao848f70a2014-01-15 13:49:50 -0800783MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700784 DEFINE_FUNCTION VAR(c_name)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100785 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000786
Jeff Hao848f70a2014-01-15 13:49:50 -0800787 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700788 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800789 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700790 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800791 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700792 PUSH ebx // pass arg4
793 PUSH edx // pass arg3
794 PUSH ecx // pass arg2
795 PUSH eax // pass arg1
796 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
797 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800798 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700799 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
800 CALL_MACRO(return_macro) // return or deliver exception
801 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800802END_MACRO
803
Fred Shih37f05ef2014-07-16 18:38:08 -0700804MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700805 DEFINE_FUNCTION VAR(c_name)
806 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700807 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700808 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700809 PUSH eax // push padding
810 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700811 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700812 PUSH ecx // pass referrer
813 PUSH eax // pass arg1
814 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
815 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700816 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700817 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
818 CALL_MACRO(return_macro) // return or deliver exception
819 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700820END_MACRO
821
822MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700823 DEFINE_FUNCTION VAR(c_name)
824 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700825 // Outgoing argument set up
826 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700827 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700828 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700829 PUSH edx // pass referrer
830 PUSH ecx // pass arg2
831 PUSH eax // pass arg1
832 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
833 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700834 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -0700835 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
836 CALL_MACRO(return_macro) // return or deliver exception
837 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700838END_MACRO
839
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700840MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700841 DEFINE_FUNCTION VAR(c_name)
842 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700843 // Outgoing argument set up
844 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700845 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700846 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700847 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700848 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700849 PUSH ebx // pass referrer
850 PUSH edx // pass arg3
851 PUSH ecx // pass arg2
852 PUSH eax // pass arg1
853 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
854 // Thread*)
855 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700856 CFI_ADJUST_CFA_OFFSET(-32)
Andreas Gampe4360be22015-07-14 23:34:44 -0700857 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
858 CALL_MACRO(return_macro) // return or deliver exception
859 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700860END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700861
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700862MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700863 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700864 jz 1f // if eax == 0 goto 1
865 ret // return
8661: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700867 DELIVER_PENDING_EXCEPTION
868END_MACRO
869
Ian Rogersd36c52e2012-04-09 16:29:25 -0700870MACRO0(RETURN_IF_EAX_ZERO)
871 testl %eax, %eax // eax == 0 ?
872 jnz 1f // if eax != 0 goto 1
873 ret // return
8741: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700875 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700876END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700877
jeffhaod66a8752012-05-22 15:30:16 -0700878MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700879 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700880 jne 1f // if exception field != 0 goto 1
881 ret // return
8821: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700883 DELIVER_PENDING_EXCEPTION
884END_MACRO
885
Mathieu Chartier7410f292013-11-24 13:17:35 -0800886// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700887GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800888
889// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
890DEFINE_FUNCTION art_quick_alloc_object_rosalloc
891 // Fast path rosalloc allocation.
892 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
893 // ebx, edx: free
894 PUSH edi
895 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
896 // Load the class (edx)
897 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
898 testl %edx, %edx // Check null class
899 jz .Lart_quick_alloc_object_rosalloc_slow_path
900 // Check class status
901 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
902 jne .Lart_quick_alloc_object_rosalloc_slow_path
903 // No fake dependence needed on x86
904 // between status and flags load,
905 // since each load is a load-acquire,
906 // no loads reordering.
907 // Check access flags has
908 // kAccClassIsFinalizable
909 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
910 jnz .Lart_quick_alloc_object_rosalloc_slow_path
911
912 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
913 // Check if the thread local allocation
914 // stack has room
915 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
916 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
917 jae .Lart_quick_alloc_object_rosalloc_slow_path
918
919 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %edi // Load the object size (edi)
920 // Check if the size is for a thread
921 // local allocation
922 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
923 ja .Lart_quick_alloc_object_rosalloc_slow_path
924 decl %edi
925 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
926 // from object size.
927 // Align up the size by the rosalloc
928 // bracket quantum size and divide
929 // by the quantum size and subtract
930 // by 1. This code is a shorter but
931 // equivalent version.
932 // Load thread local rosalloc run (ebx)
933 movl THREAD_ROSALLOC_RUNS_OFFSET(%ebx, %edi, __SIZEOF_POINTER__), %ebx
934 // Load free_list head (edi),
935 // this will be the return value.
936 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
937 test %edi, %edi
938 jz .Lart_quick_alloc_object_rosalloc_slow_path
939 // Point of no slow path. Won't go to
940 // the slow path from here on. Ok to
941 // clobber eax and ecx.
942 movl %edi, %eax
943 // Load the next pointer of the head
944 // and update head of free list with
945 // next pointer
946 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
947 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
948 // Decrement size of free list by 1
949 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
950 // Store the class pointer in the
951 // header. This also overwrites the
952 // next pointer. The offsets are
953 // asserted to match.
954#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
955#error "Class pointer needs to overwrite next pointer."
956#endif
957 POISON_HEAP_REF edx
958 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
959 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
960 // Push the new object onto the thread
961 // local allocation stack and
962 // increment the thread local
963 // allocation stack top.
964 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
965 movl %eax, (%edi)
966 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
967 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
968 // No fence needed for x86.
969 POP edi
970 ret
971.Lart_quick_alloc_object_rosalloc_slow_path:
972 POP edi
973 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
974 // Outgoing argument set up
975 PUSH eax // alignment padding
976 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
977 CFI_ADJUST_CFA_OFFSET(4)
978 PUSH ecx
979 PUSH eax
980 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
981 addl LITERAL(16), %esp // pop arguments
982 CFI_ADJUST_CFA_OFFSET(-16)
983 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // resotre frame up to return address
984 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
985END_FUNCTION art_quick_alloc_object_rosalloc
986
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800987// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
988//
989// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
990MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
991 testl %edx, %edx // Check null class
992 jz VAR(slowPathLabel)
993 // Check class status.
994 cmpl LITERAL(MIRROR_CLASS_STATUS_INITIALIZED), MIRROR_CLASS_STATUS_OFFSET(%edx)
995 jne VAR(slowPathLabel)
996 // No fake dependence needed on x86
997 // between status and flags load,
998 // since each load is a load-acquire,
999 // no loads reordering.
1000 // Check access flags has
1001 // kAccClassIsFinalizable
1002 testl LITERAL(ACCESS_FLAGS_CLASS_IS_FINALIZABLE), MIRROR_CLASS_ACCESS_FLAGS_OFFSET(%edx)
1003 jnz VAR(slowPathLabel)
1004 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1005 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
1006 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
1007 movl MIRROR_CLASS_OBJECT_SIZE_OFFSET(%edx), %esi // Load the object size.
1008 cmpl %edi, %esi // Check if it fits. OK to do this
1009 // before rounding up the object size
1010 // assuming the buf size alignment.
1011 ja VAR(slowPathLabel)
1012 addl LITERAL(OBJECT_ALIGNMENT_MASK), %esi // Align the size by 8. (addr + 7) & ~7.
1013 andl LITERAL(OBJECT_ALIGNMENT_MASK_TOGGLED), %esi
1014 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
1015 // as allocated object.
1016 addl %eax, %esi // Add the object size.
1017 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
1018 addl LITERAL(1), THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
1019 // Store the class pointer in the header.
1020 // No fence needed for x86.
1021 POISON_HEAP_REF edx
1022 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
1023 POP edi
1024 POP esi
1025 ret // Fast path succeeded.
1026END_MACRO
1027
1028// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1029MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
1030 POP edi
1031 POP esi
1032 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1033 // Outgoing argument set up
1034 PUSH eax // alignment padding
1035 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1036 CFI_ADJUST_CFA_OFFSET(4)
1037 PUSH ecx
1038 PUSH eax
1039 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
1040 addl LITERAL(16), %esp
1041 CFI_ADJUST_CFA_OFFSET(-16)
1042 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1043 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
1044END_MACRO
1045
1046// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1047DEFINE_FUNCTION art_quick_alloc_object_tlab
1048 // Fast path tlab allocation.
1049 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1050 // EBX, EDX: free.
1051#if defined(USE_READ_BARRIER)
1052 int3
1053 int3
1054#endif
1055 PUSH esi
1056 PUSH edi
1057 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1058 // Might need to break down into multiple instructions to get the base address in a register.
1059 // Load the class
1060 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1061 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1062.Lart_quick_alloc_object_tlab_slow_path:
1063 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1064END_FUNCTION art_quick_alloc_object_tlab
1065
1066// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1067DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1068 // Fast path region tlab allocation.
1069 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1070 // EBX, EDX: free.
1071#if !defined(USE_READ_BARRIER)
1072 int3
1073 int3
1074#endif
1075 PUSH esi
1076 PUSH edi
1077 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
1078 // Might need to break down into multiple instructions to get the base address in a register.
1079 // Load the class
1080 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1081 // Read barrier for class load.
1082 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001083 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1084 // Null check so that we can load the lock word.
1085 testl %edx, %edx
1086 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1087 // Check the mark bit, if it is 1 return.
1088 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1089 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001090.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1091 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1092.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1093 // The read barrier slow path. Mark the class.
1094 PUSH eax
1095 PUSH ecx
1096 // Outgoing argument set up
1097 subl MACRO_LITERAL(8), %esp // Alignment padding
1098 CFI_ADJUST_CFA_OFFSET(8)
1099 PUSH edx // Pass the class as the first param.
1100 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
1101 movl %eax, %edx
1102 addl MACRO_LITERAL(12), %esp
1103 CFI_ADJUST_CFA_OFFSET(-12)
1104 POP ecx
1105 POP eax
1106 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1107.Lart_quick_alloc_object_region_tlab_slow_path:
1108 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1109END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001110
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001111ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1112ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1113ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1114ONE_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 -07001115
Ian Rogers832336b2014-10-08 15:35:22 -07001116TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001117
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001118DEFINE_FUNCTION art_quick_lock_object
1119 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001120 jz .Lslow_lock
1121.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001122 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001123 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001124 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001125 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001126 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the gc bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001127 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001128 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001129 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001130 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001131 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1132 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1133 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1134 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1135 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001136 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001137.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1138 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001139 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001140 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001141 movl %edx, %ecx // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001142 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the read barrier bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001143 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001144 test LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED), %ecx // overflowed if the first gc state bit is set.
Ian Rogers8016a122014-02-21 20:37:21 -08001145 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001146 movl %eax, %ecx // save obj to use eax for cmpxchg.
1147 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1148 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1149 // update lockword, cmpxchg necessary for read barrier bits.
1150 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1151 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001152 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001153.Llock_cmpxchg_fail:
1154 movl %ecx, %eax // restore eax
1155 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001156.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001157 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001158 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001159 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001160 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001161 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001162 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001163 PUSH eax // pass object
1164 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1165 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001166 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001167 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001168 RETURN_IF_EAX_ZERO
1169END_FUNCTION art_quick_lock_object
1170
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001171DEFINE_FUNCTION art_quick_lock_object_no_inline
1172 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1173 // Outgoing argument set up
1174 subl LITERAL(8), %esp // alignment padding
1175 CFI_ADJUST_CFA_OFFSET(8)
1176 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1177 CFI_ADJUST_CFA_OFFSET(4)
1178 PUSH eax // pass object
1179 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1180 addl LITERAL(16), %esp // pop arguments
1181 CFI_ADJUST_CFA_OFFSET(-16)
1182 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1183 RETURN_IF_EAX_ZERO
1184END_FUNCTION art_quick_lock_object_no_inline
1185
1186
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001187DEFINE_FUNCTION art_quick_unlock_object
1188 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001189 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001190.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001191 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001192 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001193 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001194 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001195 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001196 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001197 movl %ecx, %edx // copy the lock word to detect new count of 0.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001198 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %edx // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001199 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001200 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001201 // update lockword, cmpxchg necessary for read barrier bits.
1202 movl %eax, %edx // edx: obj
1203 movl %ecx, %eax // eax: old lock word.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001204 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED), %ecx // ecx: new lock word zero except original rb bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001205#ifndef USE_READ_BARRIER
1206 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1207#else
1208 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1209 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1210#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001211 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001212.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1213 // update lockword, cmpxchg necessary for read barrier bits.
1214 movl %eax, %edx // edx: obj
1215 movl %ecx, %eax // eax: old lock word.
1216 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1217#ifndef USE_READ_BARRIER
1218 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1219#else
1220 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1221 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1222#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001223 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001224.Lunlock_cmpxchg_fail: // edx: obj
1225 movl %edx, %eax // restore eax
1226 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001227.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001228 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001229 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001230 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001231 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001232 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001233 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001234 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001235 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001236 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001237 CFI_ADJUST_CFA_OFFSET(-16)
Andreas Gampe4360be22015-07-14 23:34:44 -07001238 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001239 RETURN_IF_EAX_ZERO
1240END_FUNCTION art_quick_unlock_object
1241
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001242DEFINE_FUNCTION art_quick_unlock_object_no_inline
1243 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
1244 // Outgoing argument set up
1245 subl LITERAL(8), %esp // alignment padding
1246 CFI_ADJUST_CFA_OFFSET(8)
1247 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1248 CFI_ADJUST_CFA_OFFSET(4)
1249 PUSH eax // pass object
1250 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1251 addl LITERAL(16), %esp // pop arguments
1252 CFI_ADJUST_CFA_OFFSET(-16)
1253 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
1254 RETURN_IF_EAX_ZERO
1255END_FUNCTION art_quick_unlock_object_no_inline
1256
Ian Rogers468532e2013-08-05 10:56:33 -07001257DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001258 PUSH eax // alignment padding
1259 PUSH ecx // pass arg2 - obj->klass
1260 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001261 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001262 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001263 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001264 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001265END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001266
Ian Rogersa9a82542013-10-04 11:17:26 -07001267DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001268 PUSH eax // alignment padding
1269 PUSH ecx // pass arg2 - obj->klass
1270 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001271 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001272 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001273 jz 1f // jump forward if not assignable
1274 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001275 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001276 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001277
Andreas Gampe4360be22015-07-14 23:34:44 -07001278 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070012791:
Andreas Gampe4360be22015-07-14 23:34:44 -07001280 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001281 POP ecx
1282 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001283 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001284 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001285 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001286 PUSH eax // alignment padding
1287 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001288 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001289 PUSH ecx // pass arg2
1290 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001291 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001292 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001293END_FUNCTION art_quick_check_cast
1294
Man Cao1aee9002015-07-14 22:31:42 -07001295// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1296MACRO2(POP_REG_NE, reg, exclude_reg)
1297 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1298 addl MACRO_LITERAL(4), %esp
1299 CFI_ADJUST_CFA_OFFSET(-4)
1300 .else
1301 POP RAW_VAR(reg)
1302 .endif
1303END_MACRO
1304
1305 /*
1306 * Macro to insert read barrier, only used in art_quick_aput_obj.
1307 * obj_reg and dest_reg are registers, offset is a defined literal such as
1308 * MIRROR_OBJECT_CLASS_OFFSET.
1309 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1310 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1311 */
1312MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1313#ifdef USE_READ_BARRIER
1314 PUSH eax // save registers used in art_quick_aput_obj
1315 PUSH ebx
1316 PUSH edx
1317 PUSH ecx
1318 // Outgoing argument set up
1319 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1320 CFI_ADJUST_CFA_OFFSET(4)
1321 PUSH RAW_VAR(obj_reg) // pass obj_reg
1322 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1323 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1324 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1325 .ifnc RAW_VAR(dest_reg), eax
1326 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1327 .endif
1328 addl MACRO_LITERAL(12), %esp // pop arguments
1329 CFI_ADJUST_CFA_OFFSET(-12)
1330 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1331 POP_REG_NE edx, RAW_VAR(dest_reg)
1332 POP_REG_NE ebx, RAW_VAR(dest_reg)
1333 .ifc RAW_VAR(pop_eax), true
1334 POP_REG_NE eax, RAW_VAR(dest_reg)
1335 .endif
1336#else
1337 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1338 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1339#endif // USE_READ_BARRIER
1340END_MACRO
1341
Ian Rogersa9a82542013-10-04 11:17:26 -07001342 /*
1343 * Entry from managed code for array put operations of objects where the value being stored
1344 * needs to be checked for compatibility.
1345 * eax = array, ecx = index, edx = value
1346 */
1347DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1348 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001349 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1350 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001351END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1352
1353DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001354 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001355 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001356 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001357 mov %ecx, %eax
1358 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001359 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001360END_FUNCTION art_quick_aput_obj_with_bound_check
1361
1362DEFINE_FUNCTION art_quick_aput_obj
1363 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001364 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001365 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1366 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001367 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001368#if defined(USE_READ_BARRIER)
1369 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1370 cmpl %eax, %ebx
1371 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001372 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001373#elif defined(USE_HEAP_POISONING)
1374 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001375 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1376 UNPOISON_HEAP_REF eax
1377 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001378 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001379#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001380 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001381#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001382 jne .Lcheck_assignability
1383.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001384 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001385 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001386 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1387 shrl LITERAL(7), %eax
1388 movb %dl, (%edx, %eax)
1389 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001390.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001391 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001392 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001393.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001394 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001395 PUSH ecx
1396 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001397#if defined(USE_READ_BARRIER)
1398 subl LITERAL(4), %esp // alignment padding
1399 CFI_ADJUST_CFA_OFFSET(4)
1400 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1401 subl LITERAL(4), %esp // alignment padding
1402 CFI_ADJUST_CFA_OFFSET(4)
1403 PUSH eax // pass arg2 - type of the value to be stored
1404#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001405 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001406 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001407 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001408 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001409 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001410#else
Man Cao63069212015-08-21 15:51:39 -07001411 subl LITERAL(8), %esp // alignment padding
1412 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001413 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001414 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001415#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001416 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001417 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001418 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001419 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001420 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001421 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001422 POP edx
1423 POP ecx
1424 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001425 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001426 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001427 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1428 shrl LITERAL(7), %eax
1429 movb %dl, (%edx, %eax)
1430 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001431 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001432.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001433 POP edx
1434 POP ecx
1435 POP eax
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001436 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001437 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001438 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001439 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001440 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001441 PUSH edx // pass arg2 - value
1442 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001443 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001444 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001445END_FUNCTION art_quick_aput_obj
1446
Logan Chien8dbb7082013-01-25 20:31:17 +08001447DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001448 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001449 PUSH edx // pass arg3
1450 PUSH ecx // pass arg2
1451 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001452 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001453 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001454 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001455 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001456END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001457
Vladimir Marko952dbb12016-07-28 12:01:51 +01001458DEFINE_FUNCTION art_quick_test_suspend
1459 SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME ebx, ebx // save everything for GC
1460 // Outgoing argument set up
1461 subl MACRO_LITERAL(12), %esp // push padding
1462 CFI_ADJUST_CFA_OFFSET(12)
1463 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1464 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko603b7ca2016-08-04 16:46:51 +01001465 call SYMBOL(artTestSuspendFromCode) // (Thread*)
Vladimir Marko952dbb12016-07-28 12:01:51 +01001466 addl MACRO_LITERAL(16), %esp // pop arguments
1467 CFI_ADJUST_CFA_OFFSET(-16)
1468 RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME // restore frame up to return address
1469 ret // return
1470END_FUNCTION art_quick_test_suspend
Ian Rogers7caad772012-03-30 01:07:54 -07001471
Ian Rogers468532e2013-08-05 10:56:33 -07001472DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001473 subl LITERAL(12), %esp // alignment padding, room for argument
1474 CFI_ADJUST_CFA_OFFSET(12)
1475 movsd %xmm0, 0(%esp) // arg a
1476 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001477 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001478 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001479 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001480END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001481
Ian Rogers468532e2013-08-05 10:56:33 -07001482DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001483 subl LITERAL(12), %esp // alignment padding
1484 CFI_ADJUST_CFA_OFFSET(12)
1485 movss %xmm0, 0(%esp) // arg a
1486 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001487 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001488 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001489 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001490END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001491
Ian Rogers468532e2013-08-05 10:56:33 -07001492DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001493 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001494 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001495 PUSH ebx // pass arg4 b.hi
1496 PUSH edx // pass arg3 b.lo
1497 PUSH ecx // pass arg2 a.hi
1498 PUSH eax // pass arg1 a.lo
1499 call SYMBOL(artLdiv) // (jlong a, jlong b)
1500 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001501 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001502 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001503END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001504
Ian Rogersa9a82542013-10-04 11:17:26 -07001505DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001506 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001507 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001508 PUSH ebx // pass arg4 b.hi
1509 PUSH edx // pass arg3 b.lo
1510 PUSH ecx // pass arg2 a.hi
1511 PUSH eax // pass arg1 a.lo
1512 call SYMBOL(artLmod) // (jlong a, jlong b)
1513 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001514 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001515 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001516END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001517
Ian Rogers468532e2013-08-05 10:56:33 -07001518DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001519 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1520 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1521 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001522 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001523 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001524 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001525END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001526
Ian Rogers468532e2013-08-05 10:56:33 -07001527DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001528 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001529 xchg %edx, %ecx
1530 shld %cl,%eax,%edx
1531 shl %cl,%eax
1532 test LITERAL(32), %cl
1533 jz 1f
1534 mov %eax, %edx
1535 xor %eax, %eax
15361:
1537 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001538END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001539
Ian Rogers468532e2013-08-05 10:56:33 -07001540DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001541 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001542 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001543 shrd %cl,%edx,%eax
1544 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001545 test LITERAL(32),%cl
1546 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001547 mov %edx, %eax
1548 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070015491:
1550 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001551END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001552
Ian Rogers468532e2013-08-05 10:56:33 -07001553DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001554 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001555 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001556 shrd %cl,%edx,%eax
1557 shr %cl,%edx
1558 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001559 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001560 mov %edx, %eax
1561 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070015621:
1563 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001564END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001565
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001566ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1567ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1568ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1569ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1570ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1571ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1572ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001573
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001574TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1575TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1576TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1577TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1578TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1579TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1580TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001581
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001582TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1583TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1584TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1585TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001586
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001587THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1588THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1589THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1590THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1591
1592// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001593DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001594 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001595 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001596 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001597 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001598 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001599 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001600 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001601 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001602 pushl (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+12)(%esp) // pass referrer
1603 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001604 PUSH ebx // pass high half of new_val
1605 PUSH edx // pass low half of new_val
1606 PUSH ecx // pass object
1607 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001608 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001609 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001610 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001611 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001612 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001613END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001614
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001615// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1616// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001617DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001618 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1619 movd %ebx, %xmm0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001620 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001621 movd %xmm0, %ebx
1622 mov FRAME_SIZE_REFS_ONLY_CALLEE_SAVE(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001623 subl LITERAL(12), %esp // alignment padding
1624 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001625 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001626 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001627 PUSH ebx // pass high half of new_val
1628 PUSH edx // pass low half of new_val
1629 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001630 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001631 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001632 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001633 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001634 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001635 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001636END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001637
Logan Chien8dbb7082013-01-25 20:31:17 +08001638DEFINE_FUNCTION art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001639 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001640 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001641 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001642 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001643 PUSH ecx // pass receiver
1644 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001645 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001646 movd %eax, %xmm0 // place return value also into floating point return value
1647 movd %edx, %xmm1
1648 punpckldq %xmm1, %xmm0
Mathieu Chartier9346ff02015-06-18 10:17:26 -07001649 addl LITERAL(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE), %esp
1650 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE))
1651 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001652 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001653END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001654
Jeff Hao88474b42013-10-23 16:24:40 -07001655 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001656 * Called to resolve an imt conflict.
1657 * eax is the conflict ArtMethod.
1658 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1659 *
1660 * Note that this stub writes to eax.
1661 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001662 */
1663DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001664 PUSH EDI
1665 movl 8(%esp), %edi // Load referrer
1666 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1667 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1668 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001669 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001670 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1671 popl %eax // Pop ImtConflictTable.
1672 CFI_ADJUST_CFA_OFFSET(-4)
1673.Limt_table_iterate:
1674 cmpl %edi, 0(%eax)
1675 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001676 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001677 // and jump to it.
1678 POP EDI
1679 movl __SIZEOF_POINTER__(%eax), %eax
1680 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1681.Limt_table_next_entry:
1682 // If the entry is null, the interface method is not in the ImtConflictTable.
1683 cmpl LITERAL(0), 0(%eax)
1684 jz .Lconflict_trampoline
1685 // Iterate over the entries of the ImtConflictTable.
1686 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1687 jmp .Limt_table_iterate
1688.Lconflict_trampoline:
1689 // Call the runtime stub to populate the ImtConflictTable and jump to the
1690 // resolved method.
1691 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001692 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001693END_FUNCTION art_quick_imt_conflict_trampoline
1694
Ian Rogers468532e2013-08-05 10:56:33 -07001695DEFINE_FUNCTION art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001696 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001697 movl %esp, %edi
1698 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001699 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001700 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001701 PUSH ecx // pass receiver
1702 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001703 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001704 movl %eax, %edi // remember code pointer in EDI
1705 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001706 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001707 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001708 jz 1f
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001709 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070017101:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001711 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001712 DELIVER_PENDING_EXCEPTION
1713END_FUNCTION art_quick_resolution_trampoline
1714
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001715DEFINE_FUNCTION art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001716 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001717 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001718 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001719 subl LITERAL(5120), %esp
1720 // prepare for artQuickGenericJniTrampoline call
1721 // (Thread*, SP)
1722 // (esp) 4(esp) <= C calling convention
1723 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001724
1725 subl LITERAL(8), %esp // Padding for 16B alignment.
1726 pushl %ebp // Pass SP (to ArtMethod).
1727 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001728 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001729
Andreas Gampec200a4a2014-06-16 18:39:09 -07001730 // The C call will have registered the complete save-frame on success.
1731 // The result of the call is:
1732 // eax: pointer to native code, 0 on error.
1733 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001734
Andreas Gampec200a4a2014-06-16 18:39:09 -07001735 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001736 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001737 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001738
Andreas Gampec200a4a2014-06-16 18:39:09 -07001739 // Release part of the alloca.
1740 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001741
1742 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001743 // Native call.
1744 call *%eax
1745
Andreas Gampe779f8c92014-06-09 18:29:38 -07001746 // result sign extension is handled in C code
1747 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001748 // (Thread*, result, result_f)
1749 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001750 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001751
Andreas Gampe4360be22015-07-14 23:34:44 -07001752 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001753 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001754 pushl %edx // Pass int result.
1755 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001756 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001757 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001758
Andreas Gampe779f8c92014-06-09 18:29:38 -07001759 // Pending exceptions possible.
1760 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1761 testl %ebx, %ebx
1762 jnz .Lexception_in_native
1763
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001764 // Tear down the alloca.
1765 movl %ebp, %esp
1766 CFI_DEF_CFA_REGISTER(esp)
1767
1768
Andreas Gampe779f8c92014-06-09 18:29:38 -07001769 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001770 // Remove space for FPR args and EAX
1771 addl LITERAL(4 + 4 * 8), %esp
1772 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1773
Andreas Gampe779f8c92014-06-09 18:29:38 -07001774 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001775 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001776 CFI_ADJUST_CFA_OFFSET(-4)
1777 POP ebx
1778 POP ebp // Restore callee saves
1779 POP esi
1780 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001781 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001782 movd %eax, %xmm0
1783 movd %edx, %xmm1
1784 punpckldq %xmm1, %xmm0
1785 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001786.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001787 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1788 // Do a call to push a new save-all frame required by the runtime.
1789 call .Lexception_call
1790.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001791 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001792END_FUNCTION art_quick_generic_jni_trampoline
1793
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001794DEFINE_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001795 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001796 mov %esp, %edx // remember SP
1797 PUSH eax // alignment padding
1798 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001799 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001800 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001801 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001802 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001803 addl LITERAL(16), %esp // pop arguments
1804 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001805
1806 // Return eax:edx in xmm0 also.
1807 movd %eax, %xmm0
1808 movd %edx, %xmm1
1809 punpckldq %xmm1, %xmm0
1810
1811 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1812 CFI_ADJUST_CFA_OFFSET(-48)
1813
Andreas Gampe4360be22015-07-14 23:34:44 -07001814 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001815 POP esi
1816 POP edi
1817
Ian Rogers7db619b2013-01-16 18:35:48 -08001818 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001819END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001820
jeffhao7e4fcb82013-01-10 18:11:08 -08001821 /*
1822 * Routine that intercepts method calls and returns.
1823 */
Ian Rogers468532e2013-08-05 10:56:33 -07001824DEFINE_FUNCTION art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001825 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001826 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001827 subl LITERAL(12), %esp // Align stack.
1828 CFI_ADJUST_CFA_OFFSET(12)
Sebastien Hertz32b12f82014-11-17 12:46:27 +01001829 pushl FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001830 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001831 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001832 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001833 PUSH ecx // Pass receiver.
1834 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001835 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001836 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001837 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001838 movl 60(%esp), %edi // Restore edi.
1839 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001840 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001841 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001842 movl %ebx, 64(%esp)
1843 movl 0(%esp), %eax // Restore eax.
1844 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1845 movsd 8(%esp), %xmm0
1846 movsd 16(%esp), %xmm1
1847 movsd 24(%esp), %xmm2
1848 movsd 32(%esp), %xmm3
1849
1850 // Restore GPRs.
1851 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001852 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001853 movl 48(%esp), %ebx // Restore ebx.
1854 movl 52(%esp), %ebp // Restore ebp.
1855 movl 56(%esp), %esi // Restore esi.
1856 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001857 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001858 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001859END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001860
Ian Rogers468532e2013-08-05 10:56:33 -07001861DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001862 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001863 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001864 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001865 mov %esp, %ecx // Remember SP
1866 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001867 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001868 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001869 PUSH edx // Save gpr return value.
1870 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001871 subl LITERAL(16), %esp // Align stack
1872 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001873 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001874 PUSH edx // Pass gpr return value.
1875 PUSH eax
1876 PUSH ecx // Pass SP.
1877 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001878 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001879 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001880 mov %eax, %ecx // Move returned link register.
1881 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001882 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001883 movl %edx, %ebx // Move returned link register for deopt
1884 // (ebx is pretending to be our LR).
1885 POP eax // Restore gpr return value.
1886 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001887 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001888 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001889 CFI_ADJUST_CFA_OFFSET(-8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001890 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001891 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001892 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001893 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001894END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001895
jeffhao7e4fcb82013-01-10 18:11:08 -08001896 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001897 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1898 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001899 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001900DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001901 PUSH ebx // Entry point for a jump. Fake that we were called.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001902 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1903 subl LITERAL(12), %esp // Align stack.
1904 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001905 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001906 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001907 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001908 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001909END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001910
jeffhao86e46712012-08-08 17:30:59 -07001911 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001912 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001913 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001914 */
1915DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
1916 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME ebx, ebx
1917 subl LITERAL(12), %esp // Align stack.
1918 CFI_ADJUST_CFA_OFFSET(12)
1919 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1920 CFI_ADJUST_CFA_OFFSET(4)
1921 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1922 UNREACHABLE
1923END_FUNCTION art_quick_deoptimize_from_compiled_code
1924
1925 /*
jeffhao86e46712012-08-08 17:30:59 -07001926 * String's compareTo.
1927 *
1928 * On entry:
1929 * eax: this string object (known non-null)
1930 * ecx: comp string object (known non-null)
1931 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001932DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001933 PUSH esi // push callee save reg
1934 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001935 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1936 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001937 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1938 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001939 /* Calculate min length and count diff */
1940 mov %edx, %ecx
1941 mov %edx, %eax
1942 subl %ebx, %eax
1943 cmovg %ebx, %ecx
1944 /*
1945 * At this point we have:
1946 * eax: value to return if first part of strings are equal
1947 * ecx: minimum among the lengths of the two strings
1948 * esi: pointer to this string data
1949 * edi: pointer to comp string data
1950 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001951 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001952 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001953 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001954.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001955 POP edi // pop callee save reg
1956 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001957 ret
1958 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001959.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001960 movzwl -2(%esi), %eax // get last compared char from this string
1961 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001962 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08001963 POP edi // pop callee save reg
1964 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001965 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001966END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07001967
Dave Allison8ce6b902014-08-26 11:07:58 -07001968// Return from a nested signal:
1969// Entry:
1970// eax: address of jmp_buf in TLS
1971
1972DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001973 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07001974 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001975 PUSH ecx // second arg to longjmp (1)
1976 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07001977 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07001978 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07001979END_FUNCTION art_nested_signal_return
1980
Roland Levillain02b75802016-07-13 11:54:35 +01001981// Create a function `name` calling the ReadBarrier::Mark routine,
1982// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01001983// `reg`, saving and restoring all caller-save registers.
1984//
1985// If `reg` is different from `eax`, the generated function follows a
1986// non-standard runtime calling convention:
1987// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01001988// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01001989// - register `reg` is used to return the result of this function
1990// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01001991// - EAX is treated like a normal (non-argument) caller-save register;
1992// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01001993// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01001994MACRO2(READ_BARRIER_MARK_REG, name, reg)
1995 DEFINE_FUNCTION VAR(name)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001996 // Null check so that we can load the lock word.
1997 test REG_VAR(reg), REG_VAR(reg)
1998 jz .Lret_rb_\name
1999 // Check the mark bit, if it is 1 return.
2000 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg))
2001 jz .Lslow_rb_\name
2002 ret
2003.Lslow_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002004 // Save all potentially live caller-save core registers.
2005 PUSH eax
2006 PUSH ecx
2007 PUSH edx
2008 PUSH ebx
2009 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
2010 // and create space for caller-save floating-point registers.
2011 subl MACRO_LITERAL(4 + 8 * 8), %esp
2012 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
2013 // Save all potentially live caller-save floating-point registers.
2014 movsd %xmm0, 0(%esp)
2015 movsd %xmm1, 8(%esp)
2016 movsd %xmm2, 16(%esp)
2017 movsd %xmm3, 24(%esp)
2018 movsd %xmm4, 32(%esp)
2019 movsd %xmm5, 40(%esp)
2020 movsd %xmm6, 48(%esp)
2021 movsd %xmm7, 56(%esp)
2022
2023 subl LITERAL(4), %esp // alignment padding
2024 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01002025 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
2026 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002027 .ifnc RAW_VAR(reg), eax
2028 movl %eax, REG_VAR(reg) // return result into `reg`
2029 .endif
2030 addl LITERAL(8), %esp // pop argument and remove padding
2031 CFI_ADJUST_CFA_OFFSET(-8)
2032
2033 // Restore floating-point registers.
2034 movsd 0(%esp), %xmm0
2035 movsd 8(%esp), %xmm1
2036 movsd 16(%esp), %xmm2
2037 movsd 24(%esp), %xmm3
2038 movsd 32(%esp), %xmm4
2039 movsd 40(%esp), %xmm5
2040 movsd 48(%esp), %xmm6
2041 movsd 56(%esp), %xmm7
2042 // Remove floating-point registers and padding.
2043 addl MACRO_LITERAL(8 * 8 + 4), %esp
2044 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
2045 // Restore core regs, except `reg`, as it is used to return the
2046 // result of this function (simply remove it from the stack instead).
2047 POP_REG_NE ebx, RAW_VAR(reg)
2048 POP_REG_NE edx, RAW_VAR(reg)
2049 POP_REG_NE ecx, RAW_VAR(reg)
2050 POP_REG_NE eax, RAW_VAR(reg)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002051.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002052 ret
2053 END_FUNCTION VAR(name)
2054END_MACRO
2055
Roland Levillain4359e612016-07-20 11:32:19 +01002056READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01002057READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
2058READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
2059READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
2060READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
2061// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
2062// cannot be used to pass arguments.
2063READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
2064READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00002065
Man Cao1aee9002015-07-14 22:31:42 -07002066DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00002067 PUSH edx // pass arg3 - offset
2068 PUSH ecx // pass arg2 - obj
2069 PUSH eax // pass arg1 - ref
2070 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
2071 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07002072 CFI_ADJUST_CFA_OFFSET(-12)
2073 ret
2074END_FUNCTION art_quick_read_barrier_slow
2075
Roland Levillain0d5a2812015-11-13 10:07:31 +00002076DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01002077 subl LITERAL(8), %esp // alignment padding
2078 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002079 PUSH eax // pass arg1 - root
2080 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002081 addl LITERAL(12), %esp // pop argument and remove padding
2082 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002083 ret
2084END_FUNCTION art_quick_read_barrier_for_root_slow
2085
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002086 /*
2087 * On stack replacement stub.
2088 * On entry:
2089 * [sp] = return address
2090 * [sp + 4] = stack to copy
2091 * [sp + 8] = size of stack
2092 * [sp + 12] = pc to call
2093 * [sp + 16] = JValue* result
2094 * [sp + 20] = shorty
2095 * [sp + 24] = thread
2096 */
2097DEFINE_FUNCTION art_quick_osr_stub
2098 // Save native callee saves.
2099 PUSH ebp
2100 PUSH ebx
2101 PUSH esi
2102 PUSH edi
2103 mov 4+16(%esp), %esi // ESI = argument array
2104 mov 8+16(%esp), %ecx // ECX = size of args
2105 mov 12+16(%esp), %ebx // EBX = pc to call
2106 mov %esp, %ebp // Save stack pointer
2107 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2108 PUSH ebp // Save old stack pointer
2109 subl LITERAL(12), %esp // Align stack
2110 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2111 call .Losr_entry
2112
2113 // Restore stack pointer.
2114 addl LITERAL(12), %esp
2115 POP ebp
2116 mov %ebp, %esp
2117
2118 // Restore callee saves.
2119 POP edi
2120 POP esi
2121 POP ebx
2122 POP ebp
2123 mov 16(%esp), %ecx // Get JValue result
2124 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2125 mov %edx, 4(%ecx) // Store the other half of the result
2126 mov 20(%esp), %edx // Get the shorty
2127 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2128 je .Losr_return_double_quick
2129 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2130 je .Losr_return_float_quick
2131 ret
2132.Losr_return_double_quick:
2133 movsd %xmm0, (%ecx) // Store the floating point result
2134 ret
2135.Losr_return_float_quick:
2136 movss %xmm0, (%ecx) // Store the floating point result
2137 ret
2138.Losr_entry:
2139 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2140 subl %ecx, %esp
2141 mov %esp, %edi // EDI = beginning of stack
2142 rep movsb // while (ecx--) { *edi++ = *esi++ }
2143 jmp *%ebx
2144END_FUNCTION art_quick_osr_stub
2145
Elliott Hughes787ec202012-03-29 17:14:15 -07002146 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002147UNIMPLEMENTED art_quick_memcmp16