blob: 879d49644b1b1361f259a60bcc69586e582e2e08 [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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010025 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Ian Rogers57b86d42012-03-27 16:05:41 -070026 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010027MACRO2(SETUP_SAVE_ALL_CALLEE_SAVES_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010038 pushl RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 3*4 + 16 + 4)
45#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070046#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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010051 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly)
Ian Rogers7caad772012-03-30 01:07:54 -070052 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010053MACRO2(SETUP_SAVE_REFS_ONLY_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010064 pushl RUNTIME_SAVE_REFS_ONLY_METHOD_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010071#if (FRAME_SIZE_SAVE_REFS_ONLY != 3*4 + 16 + 4)
72#error "FRAME_SIZE_SAVE_REFS_ONLY(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070073#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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010078 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010079 * and preserves the value of got_reg at entry.
80 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010081MACRO2(SETUP_SAVE_REFS_ONLY_FRAME_PRESERVE_GOT_REG, got_reg, temp_reg)
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010082 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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010094 pushl RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET(REG_VAR(temp_reg))
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +010095 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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100104#if (FRAME_SIZE_SAVE_REFS_ONLY != 3*4 + 16 + 4)
105#error "FRAME_SIZE_SAVE_REFS_ONLY(X86) size not as expected."
Nicolas Geoffray0f838aa2016-06-08 18:01:22 +0100106#endif
107END_MACRO
108
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100109MACRO0(RESTORE_SAVE_REFS_ONLY_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100119 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs)
Ian Rogers57b86d42012-03-27 16:05:41 -0700120 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100121MACRO2(SETUP_SAVE_REFS_AND_ARGS_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100142 pushl RUNTIME_SAVE_REFS_AND_ARGS_METHOD_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100149#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 7*4 + 4*8 + 4)
150#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(X86) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700151#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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100156 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs) where the method is passed in EAX.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700157 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100158MACRO0(SETUP_SAVE_REFS_AND_ARGS_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100182MACRO0(RESTORE_SAVE_REFS_AND_ARGS_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*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100203MACRO0(RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000204 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)
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000227 * when EDI is already saved.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100228 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000229MACRO2(SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED, got_reg, temp_reg)
230 // Save core registers from highest to lowest to agree with core spills bitmap.
231 // EDI, or at least a placeholder for it, is already on the stack.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100232 PUSH esi
233 PUSH ebp
234 PUSH ebx
235 PUSH edx
236 PUSH ecx
237 PUSH eax
238 // Create space for FPR registers and stack alignment padding.
239 subl MACRO_LITERAL(12 + 8 * 8), %esp
240 CFI_ADJUST_CFA_OFFSET(12 + 8 * 8)
241 // Save FPRs.
242 movsd %xmm0, 12(%esp)
243 movsd %xmm1, 20(%esp)
244 movsd %xmm2, 28(%esp)
245 movsd %xmm3, 36(%esp)
246 movsd %xmm4, 44(%esp)
247 movsd %xmm5, 52(%esp)
248 movsd %xmm6, 60(%esp)
249 movsd %xmm7, 68(%esp)
250
251 SETUP_GOT_NOSAVE RAW_VAR(got_reg)
252 // Load Runtime::instance_ from GOT.
253 movl SYMBOL(_ZN3art7Runtime9instance_E)@GOT(REG_VAR(got_reg)), REG_VAR(temp_reg)
254 movl (REG_VAR(temp_reg)), REG_VAR(temp_reg)
255 // Push save everything callee-save method.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100256 pushl RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET(REG_VAR(temp_reg))
Vladimir Marko952dbb12016-07-28 12:01:51 +0100257 CFI_ADJUST_CFA_OFFSET(4)
258 // Store esp as the stop quick frame.
259 movl %esp, %fs:THREAD_TOP_QUICK_FRAME_OFFSET
260
261 // Ugly compile-time check, but we only have the preprocessor.
262 // Last +4: implicit return address pushed on stack when caller made call.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100263#if (FRAME_SIZE_SAVE_EVERYTHING != 7*4 + 8*8 + 12 + 4 + 4)
264#error "FRAME_SIZE_SAVE_EVERYTHING(X86) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100265#endif
266END_MACRO
267
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000268 /*
269 * Macro that sets up the callee save frame to conform with
270 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
271 */
272MACRO2(SETUP_SAVE_EVERYTHING_FRAME, got_reg, temp_reg)
273 PUSH edi
274 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED RAW_VAR(got_reg), RAW_VAR(temp_reg)
275END_MACRO
276
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100277MACRO0(RESTORE_SAVE_EVERYTHING_FRAME)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100278 // Restore FPRs. Method and padding is still on the stack.
279 movsd 16(%esp), %xmm0
280 movsd 24(%esp), %xmm1
281 movsd 32(%esp), %xmm2
282 movsd 40(%esp), %xmm3
283 movsd 48(%esp), %xmm4
284 movsd 56(%esp), %xmm5
285 movsd 64(%esp), %xmm6
286 movsd 72(%esp), %xmm7
287
288 // Remove save everything callee save method, stack alignment padding and FPRs.
289 addl MACRO_LITERAL(16 + 8 * 8), %esp
290 CFI_ADJUST_CFA_OFFSET(-(16 + 8 * 8))
291
292 // Restore core registers.
293 POP eax
294 POP ecx
295 POP edx
296 POP ebx
297 POP ebp
298 POP esi
299 POP edi
300END_MACRO
301
302 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700303 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
304 * exception is Thread::Current()->exception_.
305 */
Elliott Hughes787ec202012-03-29 17:14:15 -0700306MACRO0(DELIVER_PENDING_EXCEPTION)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100307 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save callee saves for throw
Ian Rogers57b86d42012-03-27 16:05:41 -0700308 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100309 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700310 CFI_ADJUST_CFA_OFFSET(12)
311 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800312 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700313 call SYMBOL(artDeliverPendingExceptionFromCode) // artDeliverPendingExceptionFromCode(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700314 UNREACHABLE
Elliott Hughes787ec202012-03-29 17:14:15 -0700315END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700316
Elliott Hughes787ec202012-03-29 17:14:15 -0700317MACRO2(NO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700318 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100319 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700320 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100321 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700322 CFI_ADJUST_CFA_OFFSET(12)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100323 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800324 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100325 call CALLVAR(cxx_name) // cxx_name(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -0700326 UNREACHABLE
327 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700328END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700329
Vladimir Marko804b03f2016-09-14 16:26:36 +0100330MACRO2(NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING, c_name, cxx_name)
331 DEFINE_FUNCTION VAR(c_name)
332 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save all registers as basis for long jump context
333 // Outgoing argument set up
334 subl MACRO_LITERAL(12), %esp // alignment padding
335 CFI_ADJUST_CFA_OFFSET(12)
336 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
337 CFI_ADJUST_CFA_OFFSET(4)
338 call CALLVAR(cxx_name) // cxx_name(Thread*)
339 UNREACHABLE
340 END_FUNCTION VAR(c_name)
341END_MACRO
342
Elliott Hughes787ec202012-03-29 17:14:15 -0700343MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700344 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100345 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700346 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100347 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700348 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700349 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800350 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700351 PUSH eax // pass arg1
352 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
353 UNREACHABLE
354 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700355END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700356
Vladimir Marko804b03f2016-09-14 16:26:36 +0100357MACRO2(TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700358 DEFINE_FUNCTION VAR(c_name)
Vladimir Marko804b03f2016-09-14 16:26:36 +0100359 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700360 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700361 PUSH eax // alignment padding
362 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800363 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700364 PUSH ecx // pass arg2
365 PUSH eax // pass arg1
366 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
367 UNREACHABLE
368 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700369END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700370
371 /*
372 * Called by managed code to create and deliver a NullPointerException.
373 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100374NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700375
376 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100377 * Call installed by a signal handler to create and deliver a NullPointerException.
378 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000379DEFINE_FUNCTION_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, 2 * __SIZEOF_POINTER__
380 // Fault address and return address were saved by the fault handler.
381 // Save all registers as basis for long jump context; EDI will replace fault address later.
382 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED ebx, ebx
383 // Retrieve fault address and save EDI.
384 movl (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp), %eax
385 movl %edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp)
386 CFI_REL_OFFSET(%edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__))
387 // Outgoing argument set up
388 subl MACRO_LITERAL(8), %esp // alignment padding
389 CFI_ADJUST_CFA_OFFSET(8)
390 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
391 CFI_ADJUST_CFA_OFFSET(4)
392 PUSH eax // pass arg1
393 call SYMBOL(artThrowNullPointerExceptionFromSignal) // (addr, self)
394 UNREACHABLE
395END_FUNCTION art_quick_throw_null_pointer_exception
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100396
397 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700398 * Called by managed code to create and deliver an ArithmeticException.
399 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100400NO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700401
402 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700403 * Called by managed code to create and deliver a StackOverflowError.
404 */
Ian Rogers468532e2013-08-05 10:56:33 -0700405NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700406
407 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700408 * Called by managed code, saves callee saves and then calls artThrowException
409 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
410 */
Ian Rogers468532e2013-08-05 10:56:33 -0700411ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700412
413 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700414 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
415 * index, arg2 holds limit.
416 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100417TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700418
419 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100420 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
421 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
422 */
Vladimir Marko804b03f2016-09-14 16:26:36 +0100423TWO_ARG_RUNTIME_EXCEPTION_SAVE_EVERYTHING art_quick_throw_string_bounds, artThrowStringBoundsFromCode
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100424
425 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700426 * All generated callsites for interface invokes and invocation slow paths will load arguments
427 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100428 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700429 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
430 *
431 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
432 * of the target Method* in r0 and method->code_ in r1.
433 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700434 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700435 * thread and we branch to another stub to deliver it.
436 *
437 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
438 * pointing back to the original caller.
439 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700440MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100441 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700442 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000443
Ian Rogers7caad772012-03-30 01:07:54 -0700444 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800445 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700446 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800447 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800448 PUSH ecx // pass arg2
449 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700450 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700451 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100452 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
453 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000454
455 // Restore FPRs.
456 movsd 0(%esp), %xmm0
457 movsd 8(%esp), %xmm1
458 movsd 16(%esp), %xmm2
459 movsd 24(%esp), %xmm3
460
461 // Remove space for FPR args.
462 addl MACRO_LITERAL(4 * 8), %esp
463 CFI_ADJUST_CFA_OFFSET(-4 * 8)
464
Dave Allisonbbb32c22013-11-05 18:25:18 -0800465 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800466 POP edx
467 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800468 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800469 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700470 // Swap EDI callee save with code pointer.
471 xchgl %edi, (%esp)
472 testl %eax, %eax // Branch forward if exception pending.
473 jz 1f
474 // Tail call to intended method.
475 ret
4761:
jeffhao20b5c6c2012-05-21 14:15:18 -0700477 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800478 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700479 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700480END_MACRO
481MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700482 DEFINE_FUNCTION VAR(c_name)
483 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
484 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700485END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700486
Logan Chien8dbb7082013-01-25 20:31:17 +0800487INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700488
Logan Chien8dbb7082013-01-25 20:31:17 +0800489INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
490INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
491INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
492INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700493
Jeff Hao5d917302013-02-27 17:57:33 -0800494 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000495 * Helper for quick invocation stub to set up XMM registers.
496 * Increments shorty and arg_array and clobbers temp_char.
497 * Branches to finished if it encounters the end of the shorty.
498 */
499MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
5001: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700501 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
502 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
503 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
504 je VAR(finished) // goto finished
505 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
506 je 2f // goto FOUND_DOUBLE
507 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
508 je 3f // goto FOUND_FLOAT
509 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000510 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700511 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
512 jne 1b // goto LOOP
513 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
514 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005152: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700516 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
517 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000518 jmp 4f
5193: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700520 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
521 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005224:
523END_MACRO
524
525 /*
526 * Helper for quick invocation stub to set up GPR registers.
527 * Increments shorty and arg_array, and returns the current short character in
528 * temp_char. Branches to finished if it encounters the end of the shorty.
529 */
530MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
5311: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700532 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
533 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
534 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
535 je VAR(finished) // goto finished
536 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
537 je 3f // goto SKIP_FLOAT
538 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
539 je 4f // goto SKIP_DOUBLE
540 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005413: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700542 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
543 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005444: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700545 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
546 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005475:
548END_MACRO
549
550 /*
551 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700552 * On entry:
553 * [sp] = return address
554 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700555 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700556 * [sp + 12] = size of argument array in bytes
557 * [sp + 16] = (managed) thread pointer
558 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800559 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800560 */
561DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000562 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800563 PUSH ebp // save ebp
564 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000565 PUSH esi // save esi
566 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000567 // Set up argument XMM registers.
568 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
569 addl LITERAL(1), %esi
570 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
571 addl LITERAL(4), %edi
572 // Clobbers ESI, EDI, EAX.
573 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
574 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
575 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
576 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
577 .balign 16
578.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800579 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800580 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000581 mov 28(%ebp), %ebx // get arg array size
582 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
583 addl LITERAL(36), %ebx
584 // align frame size to 16 bytes
585 andl LITERAL(0xFFFFFFF0), %ebx
586 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800587 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000588
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700589 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000590
591 // Copy arg array into stack.
592 movl 28(%ebp), %ecx // ECX = size of args
593 movl 24(%ebp), %esi // ESI = argument array
594 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
595 rep movsb // while (ecx--) { *edi++ = *esi++ }
596
597 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
598 addl LITERAL(1), %esi
599 mov 24(%ebp), %edi // EDI := arg_array
600 mov 0(%edi), %ecx // ECX := this pointer
601 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
602
603 // Enumerate the possible cases for loading GPRS.
604 // edx (and maybe ebx):
605 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
606 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
607 je .LfirstLong
608 // Must be an integer value.
609 movl (%edi), %edx
610 addl LITERAL(4), %edi // arg_array++
611
612 // Now check ebx
613 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500614 // Must be first word of a long, or an integer. First word of long doesn't
615 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000616 movl (%edi), %ebx
617 jmp .Lgpr_setup_finished
618.LfirstLong:
619 movl (%edi), %edx
620 movl 4(%edi), %ebx
621 // Nothing left to load.
622.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000623 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700624 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800625 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800626 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000627 POP edi // pop edi
628 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800629 POP ebx // pop ebx
630 POP ebp // pop ebp
631 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800632 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800633 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800634 mov 24(%esp), %edx // get the shorty
635 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800636 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800637 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800638 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700639 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800640.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800641 movsd %xmm0, (%ecx) // store the floating point result
642 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800643.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800644 movss %xmm0, (%ecx) // store the floating point result
645 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800646END_FUNCTION art_quick_invoke_stub
647
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000648 /*
649 * Quick invocation stub (static).
650 * On entry:
651 * [sp] = return address
652 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700653 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000654 * [sp + 12] = size of argument array in bytes
655 * [sp + 16] = (managed) thread pointer
656 * [sp + 20] = JValue* result
657 * [sp + 24] = shorty
658 */
659DEFINE_FUNCTION art_quick_invoke_static_stub
660 // Save the non-volatiles.
661 PUSH ebp // save ebp
662 PUSH ebx // save ebx
663 PUSH esi // save esi
664 PUSH edi // save edi
665 // Set up argument XMM registers.
666 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
667 addl LITERAL(1), %esi
668 mov 8+16(%esp), %edi // EDI := arg_array
669 // Clobbers ESI, EDI, EAX.
670 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
671 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
672 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
673 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
674 .balign 16
675.Lxmm_setup_finished2:
676 mov %esp, %ebp // copy value of stack pointer into base pointer
677 CFI_DEF_CFA_REGISTER(ebp)
678 mov 28(%ebp), %ebx // get arg array size
679 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
680 addl LITERAL(36), %ebx
681 // align frame size to 16 bytes
682 andl LITERAL(0xFFFFFFF0), %ebx
683 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
684 subl %ebx, %esp // reserve stack space for argument array
685
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700686 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000687
688 // Copy arg array into stack.
689 movl 28(%ebp), %ecx // ECX = size of args
690 movl 24(%ebp), %esi // ESI = argument array
691 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
692 rep movsb // while (ecx--) { *edi++ = *esi++ }
693
694 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
695 addl LITERAL(1), %esi
696 mov 24(%ebp), %edi // EDI := arg_array
697
698 // Enumerate the possible cases for loading GPRS.
699 // ecx (and maybe edx)
700 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
701 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
702 je .LfirstLong2
703 // Must be an integer value. Load into ECX.
704 movl (%edi), %ecx
705 addl LITERAL(4), %edi // arg_array++
706
707 // Now check edx (and maybe ebx).
708 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
709 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
710 je .LSecondLong2
711 // Must be an integer. Load into EDX.
712 movl (%edi), %edx
713 addl LITERAL(4), %edi // arg_array++
714
715 // Is there anything for ebx?
716 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500717 // Must be first word of a long, or an integer. First word of long doesn't
718 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000719 movl (%edi), %ebx
720 jmp .Lgpr_setup_finished2
721.LSecondLong2:
722 // EDX:EBX is long. That is all.
723 movl (%edi), %edx
724 movl 4(%edi), %ebx
725 jmp .Lgpr_setup_finished2
726.LfirstLong2:
727 // ECX:EDX is a long
728 movl (%edi), %ecx
729 movl 4(%edi), %edx
730 addl LITERAL(8), %edi // arg_array += 2
731
732 // Anything for EBX?
733 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500734 // Must be first word of a long, or an integer. First word of long doesn't
735 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000736 movl (%edi), %ebx
737 jmp .Lgpr_setup_finished2
738 // Nothing left to load.
739.Lgpr_setup_finished2:
740 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700741 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000742 mov %ebp, %esp // restore stack pointer
743 CFI_DEF_CFA_REGISTER(esp)
744 POP edi // pop edi
745 POP esi // pop esi
746 POP ebx // pop ebx
747 POP ebp // pop ebp
748 mov 20(%esp), %ecx // get result pointer
749 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
750 mov %edx, 4(%ecx) // store the other half of the result
751 mov 24(%esp), %edx // get the shorty
752 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
753 je .Lreturn_double_quick2
754 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
755 je .Lreturn_float_quick2
756 ret
757.Lreturn_double_quick2:
758 movsd %xmm0, (%ecx) // store the floating point result
759 ret
760.Lreturn_float_quick2:
761 movss %xmm0, (%ecx) // store the floating point result
762 ret
763END_FUNCTION art_quick_invoke_static_stub
764
Ian Rogersd36c52e2012-04-09 16:29:25 -0700765MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700766 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100767 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700768 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700769 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700770 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700771 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800772 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700773 PUSH eax // pass arg1
774 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
775 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800776 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100777 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700778 CALL_MACRO(return_macro) // return or deliver exception
779 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700780END_MACRO
781
782MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700783 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100784 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700785 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700786 PUSH eax // push padding
787 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800788 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700789 PUSH ecx // pass arg2
790 PUSH eax // pass arg1
791 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
792 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800793 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100794 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700795 CALL_MACRO(return_macro) // return or deliver exception
796 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700797END_MACRO
798
Ian Rogersd36c52e2012-04-09 16:29:25 -0700799MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700800 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100801 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700802 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700803 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800804 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700805 PUSH edx // pass arg3
806 PUSH ecx // pass arg2
807 PUSH eax // pass arg1
808 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
809 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700810 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100811 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700812 CALL_MACRO(return_macro) // return or deliver exception
813 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700814END_MACRO
815
Jeff Hao848f70a2014-01-15 13:49:50 -0800816MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700817 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100818 SETUP_SAVE_REFS_ONLY_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000819
Jeff Hao848f70a2014-01-15 13:49:50 -0800820 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700821 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800822 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700823 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800824 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700825 PUSH ebx // pass arg4
826 PUSH edx // pass arg3
827 PUSH ecx // pass arg2
828 PUSH eax // pass arg1
829 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
830 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800831 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100832 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700833 CALL_MACRO(return_macro) // return or deliver exception
834 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800835END_MACRO
836
Fred Shih37f05ef2014-07-16 18:38:08 -0700837MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700838 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100839 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700840 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100841 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700842 PUSH eax // push padding
843 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700844 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700845 PUSH ecx // pass referrer
846 PUSH eax // pass arg1
847 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
848 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700849 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100850 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700851 CALL_MACRO(return_macro) // return or deliver exception
852 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700853END_MACRO
854
855MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700856 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100857 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700858 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100859 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700860 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700861 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700862 PUSH edx // pass referrer
863 PUSH ecx // pass arg2
864 PUSH eax // pass arg1
865 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
866 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700867 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100868 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700869 CALL_MACRO(return_macro) // return or deliver exception
870 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700871END_MACRO
872
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700873MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700874 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100875 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700876 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100877 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700878 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700879 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700880 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700881 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700882 PUSH ebx // pass referrer
883 PUSH edx // pass arg3
884 PUSH ecx // pass arg2
885 PUSH eax // pass arg1
886 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
887 // Thread*)
888 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700889 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100890 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700891 CALL_MACRO(return_macro) // return or deliver exception
892 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700893END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700894
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700895MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700896 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700897 jz 1f // if eax == 0 goto 1
898 ret // return
8991: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700900 DELIVER_PENDING_EXCEPTION
901END_MACRO
902
Ian Rogersd36c52e2012-04-09 16:29:25 -0700903MACRO0(RETURN_IF_EAX_ZERO)
904 testl %eax, %eax // eax == 0 ?
905 jnz 1f // if eax != 0 goto 1
906 ret // return
9071: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700908 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700909END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700910
jeffhaod66a8752012-05-22 15:30:16 -0700911MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700912 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700913 jne 1f // if exception field != 0 goto 1
914 ret // return
9151: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700916 DELIVER_PENDING_EXCEPTION
917END_MACRO
918
Mathieu Chartier7410f292013-11-24 13:17:35 -0800919// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700920GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800921
922// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
923DEFINE_FUNCTION art_quick_alloc_object_rosalloc
924 // Fast path rosalloc allocation.
925 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
926 // ebx, edx: free
927 PUSH edi
928 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
929 // Load the class (edx)
930 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
931 testl %edx, %edx // Check null class
932 jz .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800933
934 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
935 // Check if the thread local allocation
936 // stack has room
937 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
938 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
939 jae .Lart_quick_alloc_object_rosalloc_slow_path
940
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700941 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %edi // Load the object size (edi)
lwang85de95c872015-11-10 17:26:31 +0800942 // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700943 // local allocation. Also does the
944 // finalizable and initialization check.
lwang85de95c872015-11-10 17:26:31 +0800945 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
946 ja .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800947 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
948 // from object size.
lwang85de95c872015-11-10 17:26:31 +0800949 // Load thread local rosalloc run (ebx)
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700950 // Subtract __SIZEOF_POINTER__ to subtract
951 // one from edi as there is no 0 byte run
952 // and the size is already aligned.
953 movl (THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)(%ebx, %edi, __SIZEOF_POINTER__), %ebx
lwang85de95c872015-11-10 17:26:31 +0800954 // Load free_list head (edi),
955 // this will be the return value.
956 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
957 test %edi, %edi
958 jz .Lart_quick_alloc_object_rosalloc_slow_path
959 // Point of no slow path. Won't go to
960 // the slow path from here on. Ok to
961 // clobber eax and ecx.
962 movl %edi, %eax
963 // Load the next pointer of the head
964 // and update head of free list with
965 // next pointer
966 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
967 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
968 // Decrement size of free list by 1
969 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
970 // Store the class pointer in the
971 // header. This also overwrites the
972 // next pointer. The offsets are
973 // asserted to match.
974#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
975#error "Class pointer needs to overwrite next pointer."
976#endif
977 POISON_HEAP_REF edx
978 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
979 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
980 // Push the new object onto the thread
981 // local allocation stack and
982 // increment the thread local
983 // allocation stack top.
984 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
985 movl %eax, (%edi)
986 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
987 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
988 // No fence needed for x86.
989 POP edi
990 ret
991.Lart_quick_alloc_object_rosalloc_slow_path:
992 POP edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100993 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
lwang85de95c872015-11-10 17:26:31 +0800994 // Outgoing argument set up
995 PUSH eax // alignment padding
996 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
997 CFI_ADJUST_CFA_OFFSET(4)
998 PUSH ecx
999 PUSH eax
1000 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001001 addl LITERAL(16), %esp // pop arguments
lwang85de95c872015-11-10 17:26:31 +08001002 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001003 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
lwang85de95c872015-11-10 17:26:31 +08001004 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
1005END_FUNCTION art_quick_alloc_object_rosalloc
1006
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001007// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1008//
1009// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
1010MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001011 testl %edx, %edx // Check null class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001012 jz VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001013 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1014 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
1015 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001016 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %esi // Load the object size.
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001017 cmpl %edi, %esi // Check if it fits.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001018 ja VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001019 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
1020 // as allocated object.
1021 addl %eax, %esi // Add the object size.
1022 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001023 incl THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001024 // Store the class pointer in the header.
1025 // No fence needed for x86.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001026 POISON_HEAP_REF edx
1027 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
1028 POP edi
1029 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001030 ret // Fast path succeeded.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001031END_MACRO
1032
1033// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1034MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
1035 POP edi
1036 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001037 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001038 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001039 PUSH eax // alignment padding
1040 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001041 CFI_ADJUST_CFA_OFFSET(4)
1042 PUSH ecx
1043 PUSH eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001044 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001045 addl LITERAL(16), %esp
1046 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001047 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
1048 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001049END_MACRO
1050
1051// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1052DEFINE_FUNCTION art_quick_alloc_object_tlab
1053 // Fast path tlab allocation.
1054 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1055 // EBX, EDX: free.
1056#if defined(USE_READ_BARRIER)
1057 int3
1058 int3
1059#endif
1060 PUSH esi
1061 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001062 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001063 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001064 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001065 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1066 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1067.Lart_quick_alloc_object_tlab_slow_path:
1068 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1069END_FUNCTION art_quick_alloc_object_tlab
1070
1071// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1072DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1073 // Fast path region tlab allocation.
1074 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1075 // EBX, EDX: free.
1076#if !defined(USE_READ_BARRIER)
1077 int3
1078 int3
1079#endif
1080 PUSH esi
1081 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001082 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001083 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001084 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001085 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001086 // Read barrier for class load.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001087 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001088 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1089 // Null check so that we can load the lock word.
1090 testl %edx, %edx
1091 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1092 // Check the mark bit, if it is 1 return.
1093 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1094 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001095.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1096 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1097.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1098 // The read barrier slow path. Mark the class.
1099 PUSH eax
1100 PUSH ecx
1101 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001102 subl MACRO_LITERAL(8), %esp // Alignment padding
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001103 CFI_ADJUST_CFA_OFFSET(8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001104 PUSH edx // Pass the class as the first param.
1105 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001106 movl %eax, %edx
1107 addl MACRO_LITERAL(12), %esp
1108 CFI_ADJUST_CFA_OFFSET(-12)
1109 POP ecx
1110 POP eax
1111 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1112.Lart_quick_alloc_object_region_tlab_slow_path:
1113 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1114END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001115
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001116DEFINE_FUNCTION art_quick_resolve_string
Christina Wadsworth74898e72016-08-25 13:23:01 -07001117 movl 4(%esp), %ecx // get referrer
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001118 movl ART_METHOD_DECLARING_CLASS_OFFSET(%ecx), %ecx // get declaring class
1119 movl DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET(%ecx), %ecx // get string dex cache
1120 movl LITERAL(STRING_DEX_CACHE_SIZE_MINUS_ONE), %edx
1121 andl %eax, %edx
Christina Wadsworth74898e72016-08-25 13:23:01 -07001122 movlps (%ecx, %edx, STRING_DEX_CACHE_ELEMENT_SIZE), %xmm0 // load string idx and ptr to xmm0
1123 movd %xmm0, %ecx // extract pointer
1124 pshufd LITERAL(0x55), %xmm0, %xmm0 // shuffle index into lowest bits
1125 movd %xmm0, %edx // extract index
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001126 cmp %edx, %eax
1127 jne .Lart_quick_resolve_string_slow_path
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001128 movl %ecx, %eax
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001129#ifdef USE_READ_BARRIER
1130 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1131 jne .Lart_quick_resolve_string_marking
1132#endif
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001133 ret
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001134.Lart_quick_resolve_string_slow_path:
1135 // Outgoing argument set up
Christina Wadsworth74898e72016-08-25 13:23:01 -07001136 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001137 subl LITERAL(8), %esp // push padding
1138 CFI_ADJUST_CFA_OFFSET(8)
1139 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1140 CFI_ADJUST_CFA_OFFSET(4)
1141 PUSH eax // pass arg1
1142 call SYMBOL(artResolveStringFromCode)
1143 addl LITERAL(16), %esp // pop arguments
1144 CFI_ADJUST_CFA_OFFSET(-16)
1145 RESTORE_SAVE_REFS_ONLY_FRAME
1146 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001147.Lart_quick_resolve_string_marking:
Christina Wadsworth74898e72016-08-25 13:23:01 -07001148 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001149 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax)
1150 jnz .Lart_quick_resolve_string_no_rb
1151 subl LITERAL(12), %esp // alignment padding
1152 CFI_ADJUST_CFA_OFFSET(12)
1153 PUSH eax // Pass the string as the first param.
1154 call SYMBOL(artReadBarrierMark)
1155 addl LITERAL(16), %esp
1156 CFI_ADJUST_CFA_OFFSET(-16)
1157.Lart_quick_resolve_string_no_rb:
1158 RESTORE_SAVE_REFS_ONLY_FRAME
1159 ret
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001160END_FUNCTION art_quick_resolve_string
1161
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001162ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1163ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1164ONE_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 -07001165
Ian Rogers832336b2014-10-08 15:35:22 -07001166TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001167
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001168DEFINE_FUNCTION art_quick_lock_object
1169 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001170 jz .Lslow_lock
1171.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001172 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001173 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001174 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001175 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001176 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the gc bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001177 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001178 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001179 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001180 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001181 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1182 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1183 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1184 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1185 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001186 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001187.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1188 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001189 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001190 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001191 movl %edx, %ecx // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001192 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the read barrier bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001193 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001194 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 -08001195 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001196 movl %eax, %ecx // save obj to use eax for cmpxchg.
1197 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1198 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1199 // update lockword, cmpxchg necessary for read barrier bits.
1200 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1201 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001202 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001203.Llock_cmpxchg_fail:
1204 movl %ecx, %eax // restore eax
1205 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001206.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001207 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001208 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001209 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001210 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001211 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001212 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001213 PUSH eax // pass object
1214 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1215 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001216 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001217 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001218 RETURN_IF_EAX_ZERO
1219END_FUNCTION art_quick_lock_object
1220
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001221DEFINE_FUNCTION art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001222 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001223 // Outgoing argument set up
1224 subl LITERAL(8), %esp // alignment padding
1225 CFI_ADJUST_CFA_OFFSET(8)
1226 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1227 CFI_ADJUST_CFA_OFFSET(4)
1228 PUSH eax // pass object
1229 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1230 addl LITERAL(16), %esp // pop arguments
1231 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001232 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001233 RETURN_IF_EAX_ZERO
1234END_FUNCTION art_quick_lock_object_no_inline
1235
1236
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001237DEFINE_FUNCTION art_quick_unlock_object
1238 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001239 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001240.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001241 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001242 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001243 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001244 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001245 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001246 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001247 movl %ecx, %edx // copy the lock word to detect new count of 0.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001248 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %edx // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001249 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001250 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001251 // update lockword, cmpxchg necessary for read barrier bits.
1252 movl %eax, %edx // edx: obj
1253 movl %ecx, %eax // eax: old lock word.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001254 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 -08001255#ifndef USE_READ_BARRIER
1256 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1257#else
1258 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1259 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1260#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001261 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001262.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1263 // update lockword, cmpxchg necessary for read barrier bits.
1264 movl %eax, %edx // edx: obj
1265 movl %ecx, %eax // eax: old lock word.
1266 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1267#ifndef USE_READ_BARRIER
1268 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1269#else
1270 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1271 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1272#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001273 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001274.Lunlock_cmpxchg_fail: // edx: obj
1275 movl %edx, %eax // restore eax
1276 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001277.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001278 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001279 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001280 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001281 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001282 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001283 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001284 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001285 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001286 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001287 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001288 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001289 RETURN_IF_EAX_ZERO
1290END_FUNCTION art_quick_unlock_object
1291
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001292DEFINE_FUNCTION art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001293 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001294 // Outgoing argument set up
1295 subl LITERAL(8), %esp // alignment padding
1296 CFI_ADJUST_CFA_OFFSET(8)
1297 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1298 CFI_ADJUST_CFA_OFFSET(4)
1299 PUSH eax // pass object
1300 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1301 addl LITERAL(16), %esp // pop arguments
1302 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001303 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001304 RETURN_IF_EAX_ZERO
1305END_FUNCTION art_quick_unlock_object_no_inline
1306
Ian Rogers468532e2013-08-05 10:56:33 -07001307DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001308 PUSH eax // alignment padding
1309 PUSH ecx // pass arg2 - obj->klass
1310 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001311 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001312 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001313 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001314 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001315END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001316
Ian Rogersa9a82542013-10-04 11:17:26 -07001317DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001318 PUSH eax // alignment padding
1319 PUSH ecx // pass arg2 - obj->klass
1320 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001321 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001322 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001323 jz 1f // jump forward if not assignable
1324 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001325 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001326 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001327
Andreas Gampe4360be22015-07-14 23:34:44 -07001328 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070013291:
Andreas Gampe4360be22015-07-14 23:34:44 -07001330 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001331 POP ecx
1332 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001333 CFI_ADJUST_CFA_OFFSET(-4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001334 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001335 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001336 PUSH eax // alignment padding
1337 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001338 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001339 PUSH ecx // pass arg2
1340 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001341 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001342 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001343END_FUNCTION art_quick_check_cast
1344
Man Cao1aee9002015-07-14 22:31:42 -07001345// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1346MACRO2(POP_REG_NE, reg, exclude_reg)
1347 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1348 addl MACRO_LITERAL(4), %esp
1349 CFI_ADJUST_CFA_OFFSET(-4)
1350 .else
1351 POP RAW_VAR(reg)
1352 .endif
1353END_MACRO
1354
1355 /*
1356 * Macro to insert read barrier, only used in art_quick_aput_obj.
1357 * obj_reg and dest_reg are registers, offset is a defined literal such as
1358 * MIRROR_OBJECT_CLASS_OFFSET.
1359 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1360 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1361 */
1362MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1363#ifdef USE_READ_BARRIER
1364 PUSH eax // save registers used in art_quick_aput_obj
1365 PUSH ebx
1366 PUSH edx
1367 PUSH ecx
1368 // Outgoing argument set up
1369 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1370 CFI_ADJUST_CFA_OFFSET(4)
1371 PUSH RAW_VAR(obj_reg) // pass obj_reg
1372 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1373 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1374 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1375 .ifnc RAW_VAR(dest_reg), eax
1376 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1377 .endif
1378 addl MACRO_LITERAL(12), %esp // pop arguments
1379 CFI_ADJUST_CFA_OFFSET(-12)
1380 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1381 POP_REG_NE edx, RAW_VAR(dest_reg)
1382 POP_REG_NE ebx, RAW_VAR(dest_reg)
1383 .ifc RAW_VAR(pop_eax), true
1384 POP_REG_NE eax, RAW_VAR(dest_reg)
1385 .endif
1386#else
1387 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1388 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1389#endif // USE_READ_BARRIER
1390END_MACRO
1391
Ian Rogersa9a82542013-10-04 11:17:26 -07001392 /*
1393 * Entry from managed code for array put operations of objects where the value being stored
1394 * needs to be checked for compatibility.
1395 * eax = array, ecx = index, edx = value
1396 */
1397DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1398 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001399 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1400 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001401END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1402
1403DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001404 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001405 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001406 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001407 mov %ecx, %eax
1408 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001409 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001410END_FUNCTION art_quick_aput_obj_with_bound_check
1411
1412DEFINE_FUNCTION art_quick_aput_obj
1413 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001414 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001415 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1416 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001417 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001418#if defined(USE_READ_BARRIER)
1419 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1420 cmpl %eax, %ebx
1421 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001422 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001423#elif defined(USE_HEAP_POISONING)
1424 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001425 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1426 UNPOISON_HEAP_REF eax
1427 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001428 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001429#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001430 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001431#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001432 jne .Lcheck_assignability
1433.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001434 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001435 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001436 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1437 shrl LITERAL(7), %eax
1438 movb %dl, (%edx, %eax)
1439 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001440.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001441 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001442 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001443.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001444 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001445 PUSH ecx
1446 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001447#if defined(USE_READ_BARRIER)
1448 subl LITERAL(4), %esp // alignment padding
1449 CFI_ADJUST_CFA_OFFSET(4)
1450 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1451 subl LITERAL(4), %esp // alignment padding
1452 CFI_ADJUST_CFA_OFFSET(4)
1453 PUSH eax // pass arg2 - type of the value to be stored
1454#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001455 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001456 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001457 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001458 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001459 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001460#else
Man Cao63069212015-08-21 15:51:39 -07001461 subl LITERAL(8), %esp // alignment padding
1462 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001463 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001464 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001465#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001466 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001467 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001468 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001469 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001470 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001471 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001472 POP edx
1473 POP ecx
1474 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001475 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001476 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001477 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1478 shrl LITERAL(7), %eax
1479 movb %dl, (%edx, %eax)
1480 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001481 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001482.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001483 POP edx
1484 POP ecx
1485 POP eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001486 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001487 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001488 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001489 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001490 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001491 PUSH edx // pass arg2 - value
1492 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001493 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001494 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001495END_FUNCTION art_quick_aput_obj
1496
Logan Chien8dbb7082013-01-25 20:31:17 +08001497DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001498 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001499 PUSH edx // pass arg3
1500 PUSH ecx // pass arg2
1501 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001502 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001503 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001504 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001505 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001506END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001507
Vladimir Marko952dbb12016-07-28 12:01:51 +01001508DEFINE_FUNCTION art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001509 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save everything for GC
Vladimir Marko952dbb12016-07-28 12:01:51 +01001510 // Outgoing argument set up
1511 subl MACRO_LITERAL(12), %esp // push padding
1512 CFI_ADJUST_CFA_OFFSET(12)
1513 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1514 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko603b7ca2016-08-04 16:46:51 +01001515 call SYMBOL(artTestSuspendFromCode) // (Thread*)
Vladimir Marko952dbb12016-07-28 12:01:51 +01001516 addl MACRO_LITERAL(16), %esp // pop arguments
1517 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001518 RESTORE_SAVE_EVERYTHING_FRAME // restore frame up to return address
Vladimir Marko952dbb12016-07-28 12:01:51 +01001519 ret // return
1520END_FUNCTION art_quick_test_suspend
Ian Rogers7caad772012-03-30 01:07:54 -07001521
Ian Rogers468532e2013-08-05 10:56:33 -07001522DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001523 subl LITERAL(12), %esp // alignment padding, room for argument
1524 CFI_ADJUST_CFA_OFFSET(12)
1525 movsd %xmm0, 0(%esp) // arg a
1526 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001527 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001528 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001529 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001530END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001531
Ian Rogers468532e2013-08-05 10:56:33 -07001532DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001533 subl LITERAL(12), %esp // alignment padding
1534 CFI_ADJUST_CFA_OFFSET(12)
1535 movss %xmm0, 0(%esp) // arg a
1536 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001537 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001538 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001539 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001540END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001541
Ian Rogers468532e2013-08-05 10:56:33 -07001542DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001543 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001544 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001545 PUSH ebx // pass arg4 b.hi
1546 PUSH edx // pass arg3 b.lo
1547 PUSH ecx // pass arg2 a.hi
1548 PUSH eax // pass arg1 a.lo
1549 call SYMBOL(artLdiv) // (jlong a, jlong b)
1550 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001551 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001552 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001553END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001554
Ian Rogersa9a82542013-10-04 11:17:26 -07001555DEFINE_FUNCTION art_quick_lmod
Andreas Gampe4360be22015-07-14 23:34:44 -07001556 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001557 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001558 PUSH ebx // pass arg4 b.hi
1559 PUSH edx // pass arg3 b.lo
1560 PUSH ecx // pass arg2 a.hi
1561 PUSH eax // pass arg1 a.lo
1562 call SYMBOL(artLmod) // (jlong a, jlong b)
1563 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001564 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001565 ret
Ian Rogersa9a82542013-10-04 11:17:26 -07001566END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001567
Ian Rogers468532e2013-08-05 10:56:33 -07001568DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001569 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1570 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1571 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001572 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001573 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001574 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001575END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001576
Ian Rogers468532e2013-08-05 10:56:33 -07001577DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001578 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001579 xchg %edx, %ecx
1580 shld %cl,%eax,%edx
1581 shl %cl,%eax
1582 test LITERAL(32), %cl
1583 jz 1f
1584 mov %eax, %edx
1585 xor %eax, %eax
15861:
1587 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001588END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001589
Ian Rogers468532e2013-08-05 10:56:33 -07001590DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001591 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001592 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001593 shrd %cl,%edx,%eax
1594 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001595 test LITERAL(32),%cl
1596 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001597 mov %edx, %eax
1598 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070015991:
1600 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001601END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001602
Ian Rogers468532e2013-08-05 10:56:33 -07001603DEFINE_FUNCTION art_quick_lushr
jeffhao644d5312012-05-03 19:04:49 -07001604 // ecx:eax >>> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001605 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001606 shrd %cl,%edx,%eax
1607 shr %cl,%edx
1608 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001609 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001610 mov %edx, %eax
1611 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070016121:
1613 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001614END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001615
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001616ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1617ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1618ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1619ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1620ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1621ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1622ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001623
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001624TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1625TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1626TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1627TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1628TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1629TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1630TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001631
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001632TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1633TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1634TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1635TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001636
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001637THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1638THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1639THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1640THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1641
1642// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001643DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001644 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001645 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001646 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001647 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001648 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001649 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001650 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001651 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001652 pushl (FRAME_SIZE_SAVE_REFS_ONLY+12)(%esp) // pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001653 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001654 PUSH ebx // pass high half of new_val
1655 PUSH edx // pass low half of new_val
1656 PUSH ecx // pass object
1657 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001658 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001659 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001660 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001661 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001662 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001663END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001664
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001665// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1666// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001667DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001668 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1669 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001670 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001671 movd %xmm0, %ebx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001672 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001673 subl LITERAL(12), %esp // alignment padding
1674 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001675 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001676 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001677 PUSH ebx // pass high half of new_val
1678 PUSH edx // pass low half of new_val
1679 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001680 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001681 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001682 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001683 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001684 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001685 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001686END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001687
Logan Chien8dbb7082013-01-25 20:31:17 +08001688DEFINE_FUNCTION art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001689 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001690 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001691 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001692 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001693 PUSH ecx // pass receiver
1694 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001695 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001696 movd %eax, %xmm0 // place return value also into floating point return value
1697 movd %edx, %xmm1
1698 punpckldq %xmm1, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001699 addl LITERAL(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY), %esp
1700 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY))
1701 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001702 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001703END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001704
Jeff Hao88474b42013-10-23 16:24:40 -07001705 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001706 * Called to resolve an imt conflict.
1707 * eax is the conflict ArtMethod.
1708 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1709 *
1710 * Note that this stub writes to eax.
1711 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001712 */
1713DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001714 PUSH EDI
1715 movl 8(%esp), %edi // Load referrer
1716 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1717 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1718 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001719 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001720 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1721 popl %eax // Pop ImtConflictTable.
1722 CFI_ADJUST_CFA_OFFSET(-4)
1723.Limt_table_iterate:
1724 cmpl %edi, 0(%eax)
1725 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001726 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001727 // and jump to it.
1728 POP EDI
1729 movl __SIZEOF_POINTER__(%eax), %eax
1730 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1731.Limt_table_next_entry:
1732 // If the entry is null, the interface method is not in the ImtConflictTable.
1733 cmpl LITERAL(0), 0(%eax)
1734 jz .Lconflict_trampoline
1735 // Iterate over the entries of the ImtConflictTable.
1736 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1737 jmp .Limt_table_iterate
1738.Lconflict_trampoline:
1739 // Call the runtime stub to populate the ImtConflictTable and jump to the
1740 // resolved method.
1741 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001742 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001743END_FUNCTION art_quick_imt_conflict_trampoline
1744
Ian Rogers468532e2013-08-05 10:56:33 -07001745DEFINE_FUNCTION art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001746 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001747 movl %esp, %edi
1748 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001749 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001750 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001751 PUSH ecx // pass receiver
1752 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001753 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001754 movl %eax, %edi // remember code pointer in EDI
1755 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001756 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001757 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001758 jz 1f
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001759 RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070017601:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001761 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001762 DELIVER_PENDING_EXCEPTION
1763END_FUNCTION art_quick_resolution_trampoline
1764
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001765DEFINE_FUNCTION art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001766 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001767 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001768 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001769 subl LITERAL(5120), %esp
1770 // prepare for artQuickGenericJniTrampoline call
1771 // (Thread*, SP)
1772 // (esp) 4(esp) <= C calling convention
1773 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001774
1775 subl LITERAL(8), %esp // Padding for 16B alignment.
1776 pushl %ebp // Pass SP (to ArtMethod).
1777 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001778 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001779
Andreas Gampec200a4a2014-06-16 18:39:09 -07001780 // The C call will have registered the complete save-frame on success.
1781 // The result of the call is:
1782 // eax: pointer to native code, 0 on error.
1783 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001784
Andreas Gampec200a4a2014-06-16 18:39:09 -07001785 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001786 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001787 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001788
Andreas Gampec200a4a2014-06-16 18:39:09 -07001789 // Release part of the alloca.
1790 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001791
1792 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001793 // Native call.
1794 call *%eax
1795
Andreas Gampe779f8c92014-06-09 18:29:38 -07001796 // result sign extension is handled in C code
1797 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001798 // (Thread*, result, result_f)
1799 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001800 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001801
Andreas Gampe4360be22015-07-14 23:34:44 -07001802 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001803 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001804 pushl %edx // Pass int result.
1805 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001806 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001807 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001808
Andreas Gampe779f8c92014-06-09 18:29:38 -07001809 // Pending exceptions possible.
1810 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1811 testl %ebx, %ebx
1812 jnz .Lexception_in_native
1813
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001814 // Tear down the alloca.
1815 movl %ebp, %esp
1816 CFI_DEF_CFA_REGISTER(esp)
1817
1818
Andreas Gampe779f8c92014-06-09 18:29:38 -07001819 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001820 // Remove space for FPR args and EAX
1821 addl LITERAL(4 + 4 * 8), %esp
1822 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1823
Andreas Gampe779f8c92014-06-09 18:29:38 -07001824 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001825 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001826 CFI_ADJUST_CFA_OFFSET(-4)
1827 POP ebx
1828 POP ebp // Restore callee saves
1829 POP esi
1830 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001831 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001832 movd %eax, %xmm0
1833 movd %edx, %xmm1
1834 punpckldq %xmm1, %xmm0
1835 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001836.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001837 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1838 // Do a call to push a new save-all frame required by the runtime.
1839 call .Lexception_call
1840.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001841 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001842END_FUNCTION art_quick_generic_jni_trampoline
1843
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001844DEFINE_FUNCTION art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001845 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001846 mov %esp, %edx // remember SP
1847 PUSH eax // alignment padding
1848 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001849 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001850 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001851 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001852 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001853 addl LITERAL(16), %esp // pop arguments
1854 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001855
1856 // Return eax:edx in xmm0 also.
1857 movd %eax, %xmm0
1858 movd %edx, %xmm1
1859 punpckldq %xmm1, %xmm0
1860
1861 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1862 CFI_ADJUST_CFA_OFFSET(-48)
1863
Andreas Gampe4360be22015-07-14 23:34:44 -07001864 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001865 POP esi
1866 POP edi
1867
Ian Rogers7db619b2013-01-16 18:35:48 -08001868 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001869END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001870
jeffhao7e4fcb82013-01-10 18:11:08 -08001871 /*
1872 * Routine that intercepts method calls and returns.
1873 */
Ian Rogers468532e2013-08-05 10:56:33 -07001874DEFINE_FUNCTION art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001875 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001876 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001877 subl LITERAL(12), %esp // Align stack.
1878 CFI_ADJUST_CFA_OFFSET(12)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001879 pushl FRAME_SIZE_SAVE_REFS_AND_ARGS-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001880 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001881 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001882 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001883 PUSH ecx // Pass receiver.
1884 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001885 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001886 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001887 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001888 movl 60(%esp), %edi // Restore edi.
1889 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001890 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001891 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001892 movl %ebx, 64(%esp)
1893 movl 0(%esp), %eax // Restore eax.
1894 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1895 movsd 8(%esp), %xmm0
1896 movsd 16(%esp), %xmm1
1897 movsd 24(%esp), %xmm2
1898 movsd 32(%esp), %xmm3
1899
1900 // Restore GPRs.
1901 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001902 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001903 movl 48(%esp), %ebx // Restore ebx.
1904 movl 52(%esp), %ebp // Restore ebp.
1905 movl 56(%esp), %esi // Restore esi.
1906 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001907 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001908 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001909END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001910
Ian Rogers468532e2013-08-05 10:56:33 -07001911DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001912 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001913 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001914 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001915 mov %esp, %ecx // Remember SP
1916 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001917 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001918 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001919 PUSH edx // Save gpr return value.
1920 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001921 subl LITERAL(16), %esp // Align stack
1922 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001923 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001924 PUSH edx // Pass gpr return value.
1925 PUSH eax
1926 PUSH ecx // Pass SP.
1927 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001928 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001929 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001930 mov %eax, %ecx // Move returned link register.
1931 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001932 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001933 movl %edx, %ebx // Move returned link register for deopt
1934 // (ebx is pretending to be our LR).
1935 POP eax // Restore gpr return value.
1936 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001937 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001938 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001939 CFI_ADJUST_CFA_OFFSET(-8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001940 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001941 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001942 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001943 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001944END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001945
jeffhao7e4fcb82013-01-10 18:11:08 -08001946 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001947 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1948 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001949 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001950DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001951 PUSH ebx // Entry point for a jump. Fake that we were called.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001952 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001953 subl LITERAL(12), %esp // Align stack.
1954 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001955 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001956 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001957 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001958 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001959END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001960
jeffhao86e46712012-08-08 17:30:59 -07001961 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001962 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001963 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001964 */
1965DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001966 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Sebastien Hertz07474662015-08-25 15:12:33 +00001967 subl LITERAL(12), %esp // Align stack.
1968 CFI_ADJUST_CFA_OFFSET(12)
1969 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1970 CFI_ADJUST_CFA_OFFSET(4)
1971 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1972 UNREACHABLE
1973END_FUNCTION art_quick_deoptimize_from_compiled_code
1974
1975 /*
jeffhao86e46712012-08-08 17:30:59 -07001976 * String's compareTo.
1977 *
1978 * On entry:
1979 * eax: this string object (known non-null)
1980 * ecx: comp string object (known non-null)
1981 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001982DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001983 PUSH esi // push callee save reg
1984 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001985 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1986 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001987 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1988 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001989 /* Calculate min length and count diff */
1990 mov %edx, %ecx
1991 mov %edx, %eax
1992 subl %ebx, %eax
1993 cmovg %ebx, %ecx
1994 /*
1995 * At this point we have:
1996 * eax: value to return if first part of strings are equal
1997 * ecx: minimum among the lengths of the two strings
1998 * esi: pointer to this string data
1999 * edi: pointer to comp string data
2000 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07002001 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07002002 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08002003 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07002004.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08002005 POP edi // pop callee save reg
2006 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07002007 ret
2008 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08002009.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07002010 movzwl -2(%esi), %eax // get last compared char from this string
2011 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07002012 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08002013 POP edi // pop callee save reg
2014 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07002015 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08002016END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07002017
Dave Allison8ce6b902014-08-26 11:07:58 -07002018// Return from a nested signal:
2019// Entry:
2020// eax: address of jmp_buf in TLS
2021
2022DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002023 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07002024 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002025 PUSH ecx // second arg to longjmp (1)
2026 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07002027 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07002028 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07002029END_FUNCTION art_nested_signal_return
2030
Roland Levillain02b75802016-07-13 11:54:35 +01002031// Create a function `name` calling the ReadBarrier::Mark routine,
2032// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01002033// `reg`, saving and restoring all caller-save registers.
2034//
2035// If `reg` is different from `eax`, the generated function follows a
2036// non-standard runtime calling convention:
2037// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002038// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01002039// - register `reg` is used to return the result of this function
2040// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01002041// - EAX is treated like a normal (non-argument) caller-save register;
2042// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002043// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002044MACRO2(READ_BARRIER_MARK_REG, name, reg)
2045 DEFINE_FUNCTION VAR(name)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002046 // Null check so that we can load the lock word.
2047 test REG_VAR(reg), REG_VAR(reg)
2048 jz .Lret_rb_\name
2049 // Check the mark bit, if it is 1 return.
2050 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg))
2051 jz .Lslow_rb_\name
2052 ret
2053.Lslow_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002054 // Save all potentially live caller-save core registers.
2055 PUSH eax
2056 PUSH ecx
2057 PUSH edx
2058 PUSH ebx
2059 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
2060 // and create space for caller-save floating-point registers.
2061 subl MACRO_LITERAL(4 + 8 * 8), %esp
2062 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
2063 // Save all potentially live caller-save floating-point registers.
2064 movsd %xmm0, 0(%esp)
2065 movsd %xmm1, 8(%esp)
2066 movsd %xmm2, 16(%esp)
2067 movsd %xmm3, 24(%esp)
2068 movsd %xmm4, 32(%esp)
2069 movsd %xmm5, 40(%esp)
2070 movsd %xmm6, 48(%esp)
2071 movsd %xmm7, 56(%esp)
2072
2073 subl LITERAL(4), %esp // alignment padding
2074 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01002075 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
2076 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002077 .ifnc RAW_VAR(reg), eax
2078 movl %eax, REG_VAR(reg) // return result into `reg`
2079 .endif
2080 addl LITERAL(8), %esp // pop argument and remove padding
2081 CFI_ADJUST_CFA_OFFSET(-8)
2082
2083 // Restore floating-point registers.
2084 movsd 0(%esp), %xmm0
2085 movsd 8(%esp), %xmm1
2086 movsd 16(%esp), %xmm2
2087 movsd 24(%esp), %xmm3
2088 movsd 32(%esp), %xmm4
2089 movsd 40(%esp), %xmm5
2090 movsd 48(%esp), %xmm6
2091 movsd 56(%esp), %xmm7
2092 // Remove floating-point registers and padding.
2093 addl MACRO_LITERAL(8 * 8 + 4), %esp
2094 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
2095 // Restore core regs, except `reg`, as it is used to return the
2096 // result of this function (simply remove it from the stack instead).
2097 POP_REG_NE ebx, RAW_VAR(reg)
2098 POP_REG_NE edx, RAW_VAR(reg)
2099 POP_REG_NE ecx, RAW_VAR(reg)
2100 POP_REG_NE eax, RAW_VAR(reg)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002101.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002102 ret
2103 END_FUNCTION VAR(name)
2104END_MACRO
2105
Roland Levillain4359e612016-07-20 11:32:19 +01002106READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01002107READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
2108READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
2109READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
2110READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
2111// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
2112// cannot be used to pass arguments.
2113READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
2114READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00002115
Man Cao1aee9002015-07-14 22:31:42 -07002116DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00002117 PUSH edx // pass arg3 - offset
2118 PUSH ecx // pass arg2 - obj
2119 PUSH eax // pass arg1 - ref
2120 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
2121 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07002122 CFI_ADJUST_CFA_OFFSET(-12)
2123 ret
2124END_FUNCTION art_quick_read_barrier_slow
2125
Roland Levillain0d5a2812015-11-13 10:07:31 +00002126DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01002127 subl LITERAL(8), %esp // alignment padding
2128 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002129 PUSH eax // pass arg1 - root
2130 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002131 addl LITERAL(12), %esp // pop argument and remove padding
2132 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002133 ret
2134END_FUNCTION art_quick_read_barrier_for_root_slow
2135
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002136 /*
2137 * On stack replacement stub.
2138 * On entry:
2139 * [sp] = return address
2140 * [sp + 4] = stack to copy
2141 * [sp + 8] = size of stack
2142 * [sp + 12] = pc to call
2143 * [sp + 16] = JValue* result
2144 * [sp + 20] = shorty
2145 * [sp + 24] = thread
2146 */
2147DEFINE_FUNCTION art_quick_osr_stub
2148 // Save native callee saves.
2149 PUSH ebp
2150 PUSH ebx
2151 PUSH esi
2152 PUSH edi
2153 mov 4+16(%esp), %esi // ESI = argument array
2154 mov 8+16(%esp), %ecx // ECX = size of args
2155 mov 12+16(%esp), %ebx // EBX = pc to call
2156 mov %esp, %ebp // Save stack pointer
2157 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2158 PUSH ebp // Save old stack pointer
2159 subl LITERAL(12), %esp // Align stack
2160 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2161 call .Losr_entry
2162
2163 // Restore stack pointer.
2164 addl LITERAL(12), %esp
2165 POP ebp
2166 mov %ebp, %esp
2167
2168 // Restore callee saves.
2169 POP edi
2170 POP esi
2171 POP ebx
2172 POP ebp
2173 mov 16(%esp), %ecx // Get JValue result
2174 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2175 mov %edx, 4(%ecx) // Store the other half of the result
2176 mov 20(%esp), %edx // Get the shorty
2177 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2178 je .Losr_return_double_quick
2179 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2180 je .Losr_return_float_quick
2181 ret
2182.Losr_return_double_quick:
2183 movsd %xmm0, (%ecx) // Store the floating point result
2184 ret
2185.Losr_return_float_quick:
2186 movss %xmm0, (%ecx) // Store the floating point result
2187 ret
2188.Losr_entry:
2189 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2190 subl %ecx, %esp
2191 mov %esp, %edi // EDI = beginning of stack
2192 rep movsb // while (ecx--) { *edi++ = *esi++ }
2193 jmp *%ebx
2194END_FUNCTION art_quick_osr_stub
2195
Elliott Hughes787ec202012-03-29 17:14:15 -07002196 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002197UNIMPLEMENTED art_quick_memcmp16