blob: f3793e15a7c9b23e68ae415a616acfa74fe1af94 [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
Elliott Hughes787ec202012-03-29 17:14:15 -0700330MACRO2(ONE_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700331 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100332 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700333 // Outgoing argument set up
Roland Levillaina7821bf2016-06-30 16:21:31 +0100334 subl MACRO_LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700335 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700336 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800337 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700338 PUSH eax // pass arg1
339 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
340 UNREACHABLE
341 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700342END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700343
Elliott Hughes787ec202012-03-29 17:14:15 -0700344MACRO2(TWO_ARG_RUNTIME_EXCEPTION, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700345 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100346 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogers57b86d42012-03-27 16:05:41 -0700347 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700348 PUSH eax // alignment padding
349 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 ecx // pass arg2
352 PUSH eax // pass arg1
353 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
354 UNREACHABLE
355 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700356END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700357
358 /*
359 * Called by managed code to create and deliver a NullPointerException.
360 */
Ian Rogers468532e2013-08-05 10:56:33 -0700361NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700362
363 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100364 * Call installed by a signal handler to create and deliver a NullPointerException.
365 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000366DEFINE_FUNCTION_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, 2 * __SIZEOF_POINTER__
367 // Fault address and return address were saved by the fault handler.
368 // Save all registers as basis for long jump context; EDI will replace fault address later.
369 SETUP_SAVE_EVERYTHING_FRAME_EDI_SAVED ebx, ebx
370 // Retrieve fault address and save EDI.
371 movl (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp), %eax
372 movl %edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__)(%esp)
373 CFI_REL_OFFSET(%edi, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__))
374 // Outgoing argument set up
375 subl MACRO_LITERAL(8), %esp // alignment padding
376 CFI_ADJUST_CFA_OFFSET(8)
377 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
378 CFI_ADJUST_CFA_OFFSET(4)
379 PUSH eax // pass arg1
380 call SYMBOL(artThrowNullPointerExceptionFromSignal) // (addr, self)
381 UNREACHABLE
382END_FUNCTION art_quick_throw_null_pointer_exception
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100383
384 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700385 * Called by managed code to create and deliver an ArithmeticException.
386 */
Ian Rogers468532e2013-08-05 10:56:33 -0700387NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700388
389 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700390 * Called by managed code to create and deliver a StackOverflowError.
391 */
Ian Rogers468532e2013-08-05 10:56:33 -0700392NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
Ian Rogers57b86d42012-03-27 16:05:41 -0700393
394 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700395 * Called by managed code, saves callee saves and then calls artThrowException
396 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
397 */
Ian Rogers468532e2013-08-05 10:56:33 -0700398ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700399
400 /*
Elliott Hughes787ec202012-03-29 17:14:15 -0700401 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
402 * index, arg2 holds limit.
403 */
Ian Rogers468532e2013-08-05 10:56:33 -0700404TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
Elliott Hughes787ec202012-03-29 17:14:15 -0700405
406 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100407 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
408 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
409 */
410TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
411
412 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700413 * All generated callsites for interface invokes and invocation slow paths will load arguments
414 * as usual - except instead of loading arg0/r0 with the target Method*, arg0/r0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100415 * the method_idx. This wrapper will save arg1-arg3 and call the appropriate C helper.
Ian Rogers57b86d42012-03-27 16:05:41 -0700416 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/r1.
417 *
418 * The helper will attempt to locate the target and return a 64-bit result in r0/r1 consisting
419 * of the target Method* in r0 and method->code_ in r1.
420 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700421 * If unsuccessful, the helper will return null/null will bea pending exception in the
Ian Rogers57b86d42012-03-27 16:05:41 -0700422 * thread and we branch to another stub to deliver it.
423 *
424 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
425 * pointing back to the original caller.
426 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700427MACRO1(INVOKE_TRAMPOLINE_BODY, cxx_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100428 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Ian Rogers7caad772012-03-30 01:07:54 -0700429 movl %esp, %edx // remember SP
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000430
Ian Rogers7caad772012-03-30 01:07:54 -0700431 // Outgoing argument set up
Ian Rogersaeeada42013-02-13 11:28:34 -0800432 PUSH edx // pass SP
Ian Rogers7caad772012-03-30 01:07:54 -0700433 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800434 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -0800435 PUSH ecx // pass arg2
436 PUSH eax // pass arg1
Andreas Gampe4360be22015-07-14 23:34:44 -0700437 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*, SP)
Ian Rogers7caad772012-03-30 01:07:54 -0700438 movl %edx, %edi // save code pointer in EDI
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100439 addl MACRO_LITERAL(20), %esp // Pop arguments skip eax
440 CFI_ADJUST_CFA_OFFSET(-20)
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000441
442 // Restore FPRs.
443 movsd 0(%esp), %xmm0
444 movsd 8(%esp), %xmm1
445 movsd 16(%esp), %xmm2
446 movsd 24(%esp), %xmm3
447
448 // Remove space for FPR args.
449 addl MACRO_LITERAL(4 * 8), %esp
450 CFI_ADJUST_CFA_OFFSET(-4 * 8)
451
Dave Allisonbbb32c22013-11-05 18:25:18 -0800452 POP ecx // Restore args except eax
Ian Rogersaeeada42013-02-13 11:28:34 -0800453 POP edx
454 POP ebx
Dave Allisonbbb32c22013-11-05 18:25:18 -0800455 POP ebp // Restore callee saves
Ian Rogersaeeada42013-02-13 11:28:34 -0800456 POP esi
Ian Rogers7caad772012-03-30 01:07:54 -0700457 // Swap EDI callee save with code pointer.
458 xchgl %edi, (%esp)
459 testl %eax, %eax // Branch forward if exception pending.
460 jz 1f
461 // Tail call to intended method.
462 ret
4631:
jeffhao20b5c6c2012-05-21 14:15:18 -0700464 addl MACRO_LITERAL(4), %esp // Pop code pointer off stack
Mark Mendell3f2d0312014-01-20 17:20:27 -0800465 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers7caad772012-03-30 01:07:54 -0700466 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700467END_MACRO
468MACRO2(INVOKE_TRAMPOLINE, c_name, cxx_name)
Andreas Gampe4360be22015-07-14 23:34:44 -0700469 DEFINE_FUNCTION VAR(c_name)
470 INVOKE_TRAMPOLINE_BODY RAW_VAR(cxx_name)
471 END_FUNCTION VAR(c_name)
Elliott Hughes787ec202012-03-29 17:14:15 -0700472END_MACRO
Ian Rogers57b86d42012-03-27 16:05:41 -0700473
Logan Chien8dbb7082013-01-25 20:31:17 +0800474INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700475
Logan Chien8dbb7082013-01-25 20:31:17 +0800476INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
477INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
478INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
479INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Ian Rogers57b86d42012-03-27 16:05:41 -0700480
Jeff Hao5d917302013-02-27 17:57:33 -0800481 /*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000482 * Helper for quick invocation stub to set up XMM registers.
483 * Increments shorty and arg_array and clobbers temp_char.
484 * Branches to finished if it encounters the end of the shorty.
485 */
486MACRO5(LOOP_OVER_SHORTY_LOADING_XMMS, xmm_reg, shorty, arg_array, temp_char, finished)
4871: // LOOP
Andreas Gampe4360be22015-07-14 23:34:44 -0700488 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
489 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
490 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
491 je VAR(finished) // goto finished
492 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
493 je 2f // goto FOUND_DOUBLE
494 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
495 je 3f // goto FOUND_FLOAT
496 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000497 // Handle extra space in arg array taken by a long.
Andreas Gampe4360be22015-07-14 23:34:44 -0700498 cmpb MACRO_LITERAL(74), REG_VAR(temp_char) // if (temp_char != 'J')
499 jne 1b // goto LOOP
500 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
501 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005022: // FOUND_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700503 movsd (REG_VAR(arg_array)), REG_VAR(xmm_reg)
504 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000505 jmp 4f
5063: // FOUND_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700507 movss (REG_VAR(arg_array)), REG_VAR(xmm_reg)
508 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005094:
510END_MACRO
511
512 /*
513 * Helper for quick invocation stub to set up GPR registers.
514 * Increments shorty and arg_array, and returns the current short character in
515 * temp_char. Branches to finished if it encounters the end of the shorty.
516 */
517MACRO4(SKIP_OVER_FLOATS, shorty, arg_array, temp_char, finished)
5181: // LOOP:
Andreas Gampe4360be22015-07-14 23:34:44 -0700519 movb (REG_VAR(shorty)), REG_VAR(temp_char) // temp_char := *shorty
520 addl MACRO_LITERAL(1), REG_VAR(shorty) // shorty++
521 cmpb MACRO_LITERAL(0), REG_VAR(temp_char) // if (temp_char == '\0')
522 je VAR(finished) // goto finished
523 cmpb MACRO_LITERAL(70), REG_VAR(temp_char) // if (temp_char == 'F')
524 je 3f // goto SKIP_FLOAT
525 cmpb MACRO_LITERAL(68), REG_VAR(temp_char) // if (temp_char == 'D')
526 je 4f // goto SKIP_DOUBLE
527 jmp 5f // goto end
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005283: // SKIP_FLOAT
Andreas Gampe4360be22015-07-14 23:34:44 -0700529 addl MACRO_LITERAL(4), REG_VAR(arg_array) // arg_array++
530 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005314: // SKIP_DOUBLE
Andreas Gampe4360be22015-07-14 23:34:44 -0700532 addl MACRO_LITERAL(8), REG_VAR(arg_array) // arg_array+=2
533 jmp 1b // goto LOOP
Mark P Mendell966c3ae2015-01-27 15:45:27 +00005345:
535END_MACRO
536
537 /*
538 * Quick invocation stub (non-static).
Jeff Hao6474d192013-03-26 14:08:09 -0700539 * On entry:
540 * [sp] = return address
541 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700542 * [sp + 8] = argument array or null for no argument methods
Jeff Hao6474d192013-03-26 14:08:09 -0700543 * [sp + 12] = size of argument array in bytes
544 * [sp + 16] = (managed) thread pointer
545 * [sp + 20] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800546 * [sp + 24] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800547 */
548DEFINE_FUNCTION art_quick_invoke_stub
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000549 // Save the non-volatiles.
Jeff Hao5d917302013-02-27 17:57:33 -0800550 PUSH ebp // save ebp
551 PUSH ebx // save ebx
Nicolas Geoffray48088462014-12-12 10:29:38 +0000552 PUSH esi // save esi
553 PUSH edi // save edi
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000554 // Set up argument XMM registers.
555 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
556 addl LITERAL(1), %esi
557 mov 8+16(%esp), %edi // EDI := arg_array + 4 ; ie skip this pointer.
558 addl LITERAL(4), %edi
559 // Clobbers ESI, EDI, EAX.
560 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished
561 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished
562 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished
563 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished
564 .balign 16
565.Lxmm_setup_finished:
Jeff Hao5d917302013-02-27 17:57:33 -0800566 mov %esp, %ebp // copy value of stack pointer into base pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800567 CFI_DEF_CFA_REGISTER(ebp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000568 mov 28(%ebp), %ebx // get arg array size
569 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
570 addl LITERAL(36), %ebx
571 // align frame size to 16 bytes
572 andl LITERAL(0xFFFFFFF0), %ebx
573 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
Jeff Hao5d917302013-02-27 17:57:33 -0800574 subl %ebx, %esp // reserve stack space for argument array
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000575
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700576 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000577
578 // Copy arg array into stack.
579 movl 28(%ebp), %ecx // ECX = size of args
580 movl 24(%ebp), %esi // ESI = argument array
581 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
582 rep movsb // while (ecx--) { *edi++ = *esi++ }
583
584 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
585 addl LITERAL(1), %esi
586 mov 24(%ebp), %edi // EDI := arg_array
587 mov 0(%edi), %ecx // ECX := this pointer
588 addl LITERAL(4), %edi // EDI := arg_array + 4 ; ie skip this pointer.
589
590 // Enumerate the possible cases for loading GPRS.
591 // edx (and maybe ebx):
592 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
593 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
594 je .LfirstLong
595 // Must be an integer value.
596 movl (%edi), %edx
597 addl LITERAL(4), %edi // arg_array++
598
599 // Now check ebx
600 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500601 // Must be first word of a long, or an integer. First word of long doesn't
602 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000603 movl (%edi), %ebx
604 jmp .Lgpr_setup_finished
605.LfirstLong:
606 movl (%edi), %edx
607 movl 4(%edi), %ebx
608 // Nothing left to load.
609.Lgpr_setup_finished:
Nicolas Geoffray48088462014-12-12 10:29:38 +0000610 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700611 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Jeff Hao5d917302013-02-27 17:57:33 -0800612 mov %ebp, %esp // restore stack pointer
Mark Mendell3f2d0312014-01-20 17:20:27 -0800613 CFI_DEF_CFA_REGISTER(esp)
Nicolas Geoffray48088462014-12-12 10:29:38 +0000614 POP edi // pop edi
615 POP esi // pop esi
Jeff Hao5d917302013-02-27 17:57:33 -0800616 POP ebx // pop ebx
617 POP ebp // pop ebp
618 mov 20(%esp), %ecx // get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800619 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
Jeff Hao5d917302013-02-27 17:57:33 -0800620 mov %edx, 4(%ecx) // store the other half of the result
Ian Rogers0177e532014-02-11 16:30:46 -0800621 mov 24(%esp), %edx // get the shorty
622 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
Ian Rogers8016a122014-02-21 20:37:21 -0800623 je .Lreturn_double_quick
Ian Rogers0177e532014-02-11 16:30:46 -0800624 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
Ian Rogers8016a122014-02-21 20:37:21 -0800625 je .Lreturn_float_quick
Jeff Hao6474d192013-03-26 14:08:09 -0700626 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800627.Lreturn_double_quick:
Jeff Hao5d917302013-02-27 17:57:33 -0800628 movsd %xmm0, (%ecx) // store the floating point result
629 ret
Ian Rogers8016a122014-02-21 20:37:21 -0800630.Lreturn_float_quick:
Ian Rogers0177e532014-02-11 16:30:46 -0800631 movss %xmm0, (%ecx) // store the floating point result
632 ret
Jeff Hao5d917302013-02-27 17:57:33 -0800633END_FUNCTION art_quick_invoke_stub
634
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000635 /*
636 * Quick invocation stub (static).
637 * On entry:
638 * [sp] = return address
639 * [sp + 4] = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700640 * [sp + 8] = argument array or null for no argument methods
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000641 * [sp + 12] = size of argument array in bytes
642 * [sp + 16] = (managed) thread pointer
643 * [sp + 20] = JValue* result
644 * [sp + 24] = shorty
645 */
646DEFINE_FUNCTION art_quick_invoke_static_stub
647 // Save the non-volatiles.
648 PUSH ebp // save ebp
649 PUSH ebx // save ebx
650 PUSH esi // save esi
651 PUSH edi // save edi
652 // Set up argument XMM registers.
653 mov 24+16(%esp), %esi // ESI := shorty + 1 ; ie skip return arg character.
654 addl LITERAL(1), %esi
655 mov 8+16(%esp), %edi // EDI := arg_array
656 // Clobbers ESI, EDI, EAX.
657 LOOP_OVER_SHORTY_LOADING_XMMS xmm0, esi, edi, al, .Lxmm_setup_finished2
658 LOOP_OVER_SHORTY_LOADING_XMMS xmm1, esi, edi, al, .Lxmm_setup_finished2
659 LOOP_OVER_SHORTY_LOADING_XMMS xmm2, esi, edi, al, .Lxmm_setup_finished2
660 LOOP_OVER_SHORTY_LOADING_XMMS xmm3, esi, edi, al, .Lxmm_setup_finished2
661 .balign 16
662.Lxmm_setup_finished2:
663 mov %esp, %ebp // copy value of stack pointer into base pointer
664 CFI_DEF_CFA_REGISTER(ebp)
665 mov 28(%ebp), %ebx // get arg array size
666 // reserve space for return addr, method*, ebx, ebp, esi, and edi in frame
667 addl LITERAL(36), %ebx
668 // align frame size to 16 bytes
669 andl LITERAL(0xFFFFFFF0), %ebx
670 subl LITERAL(20), %ebx // remove space for return address, ebx, ebp, esi and edi
671 subl %ebx, %esp // reserve stack space for argument array
672
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700673 movl LITERAL(0), (%esp) // store null for method*
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000674
675 // Copy arg array into stack.
676 movl 28(%ebp), %ecx // ECX = size of args
677 movl 24(%ebp), %esi // ESI = argument array
678 leal 4(%esp), %edi // EDI = just after Method* in stack arguments
679 rep movsb // while (ecx--) { *edi++ = *esi++ }
680
681 mov 40(%ebp), %esi // ESI := shorty + 1 ; ie skip return arg character.
682 addl LITERAL(1), %esi
683 mov 24(%ebp), %edi // EDI := arg_array
684
685 // Enumerate the possible cases for loading GPRS.
686 // ecx (and maybe edx)
687 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
688 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
689 je .LfirstLong2
690 // Must be an integer value. Load into ECX.
691 movl (%edi), %ecx
692 addl LITERAL(4), %edi // arg_array++
693
694 // Now check edx (and maybe ebx).
695 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
696 cmpb LITERAL(74), %al // if (al == 'J') goto FOUND_LONG
697 je .LSecondLong2
698 // Must be an integer. Load into EDX.
699 movl (%edi), %edx
700 addl LITERAL(4), %edi // arg_array++
701
702 // Is there anything for ebx?
703 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500704 // Must be first word of a long, or an integer. First word of long doesn't
705 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000706 movl (%edi), %ebx
707 jmp .Lgpr_setup_finished2
708.LSecondLong2:
709 // EDX:EBX is long. That is all.
710 movl (%edi), %edx
711 movl 4(%edi), %ebx
712 jmp .Lgpr_setup_finished2
713.LfirstLong2:
714 // ECX:EDX is a long
715 movl (%edi), %ecx
716 movl 4(%edi), %edx
717 addl LITERAL(8), %edi // arg_array += 2
718
719 // Anything for EBX?
720 SKIP_OVER_FLOATS esi, edi, al, .Lgpr_setup_finished2
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500721 // Must be first word of a long, or an integer. First word of long doesn't
722 // go into EBX, but can be loaded there anyways, as it is harmless.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000723 movl (%edi), %ebx
724 jmp .Lgpr_setup_finished2
725 // Nothing left to load.
726.Lgpr_setup_finished2:
727 mov 20(%ebp), %eax // move method pointer into eax
Mathieu Chartiere401d142015-04-22 13:56:20 -0700728 call *ART_METHOD_QUICK_CODE_OFFSET_32(%eax) // call the method
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000729 mov %ebp, %esp // restore stack pointer
730 CFI_DEF_CFA_REGISTER(esp)
731 POP edi // pop edi
732 POP esi // pop esi
733 POP ebx // pop ebx
734 POP ebp // pop ebp
735 mov 20(%esp), %ecx // get result pointer
736 mov %eax, (%ecx) // store the result assuming its a long, int or Object*
737 mov %edx, 4(%ecx) // store the other half of the result
738 mov 24(%esp), %edx // get the shorty
739 cmpb LITERAL(68), (%edx) // test if result type char == 'D'
740 je .Lreturn_double_quick2
741 cmpb LITERAL(70), (%edx) // test if result type char == 'F'
742 je .Lreturn_float_quick2
743 ret
744.Lreturn_double_quick2:
745 movsd %xmm0, (%ecx) // store the floating point result
746 ret
747.Lreturn_float_quick2:
748 movss %xmm0, (%ecx) // store the floating point result
749 ret
750END_FUNCTION art_quick_invoke_static_stub
751
Ian Rogersd36c52e2012-04-09 16:29:25 -0700752MACRO3(ONE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700753 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100754 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd36c52e2012-04-09 16:29:25 -0700755 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700756 subl MACRO_LITERAL(8), %esp // push padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700757 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -0700758 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800759 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700760 PUSH eax // pass arg1
761 call CALLVAR(cxx_name) // cxx_name(arg1, Thread*)
762 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800763 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100764 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700765 CALL_MACRO(return_macro) // return or deliver exception
766 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700767END_MACRO
768
769MACRO3(TWO_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700770 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100771 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700772 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700773 PUSH eax // push padding
774 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800775 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700776 PUSH ecx // pass arg2
777 PUSH eax // pass arg1
778 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, Thread*)
779 addl MACRO_LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -0800780 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100781 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700782 CALL_MACRO(return_macro) // return or deliver exception
783 END_FUNCTION VAR(c_name)
Ian Rogers7caad772012-03-30 01:07:54 -0700784END_MACRO
785
Ian Rogersd36c52e2012-04-09 16:29:25 -0700786MACRO3(THREE_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700787 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100788 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers7caad772012-03-30 01:07:54 -0700789 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700790 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -0800791 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700792 PUSH edx // pass arg3
793 PUSH ecx // pass arg2
794 PUSH eax // pass arg1
795 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, Thread*)
796 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700797 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100798 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700799 CALL_MACRO(return_macro) // return or deliver exception
800 END_FUNCTION VAR(c_name)
Ian Rogersd36c52e2012-04-09 16:29:25 -0700801END_MACRO
802
Jeff Hao848f70a2014-01-15 13:49:50 -0800803MACRO3(FOUR_ARG_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700804 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100805 SETUP_SAVE_REFS_ONLY_FRAME_PRESERVE_GOT_REG ebx, ebx // save ref containing registers for GC
Roland Levillainf969a202016-03-09 16:14:00 +0000806
Jeff Hao848f70a2014-01-15 13:49:50 -0800807 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -0700808 subl MACRO_LITERAL(12), %esp // alignment padding
Jeff Hao848f70a2014-01-15 13:49:50 -0800809 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700810 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Jeff Hao848f70a2014-01-15 13:49:50 -0800811 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700812 PUSH ebx // pass arg4
813 PUSH edx // pass arg3
814 PUSH ecx // pass arg2
815 PUSH eax // pass arg1
816 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, arg4, Thread*)
817 addl MACRO_LITERAL(32), %esp // pop arguments
Jeff Hao848f70a2014-01-15 13:49:50 -0800818 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100819 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700820 CALL_MACRO(return_macro) // return or deliver exception
821 END_FUNCTION VAR(c_name)
Jeff Hao848f70a2014-01-15 13:49:50 -0800822END_MACRO
823
Fred Shih37f05ef2014-07-16 18:38:08 -0700824MACRO3(ONE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700825 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100826 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700827 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100828 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700829 PUSH eax // push padding
830 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700831 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700832 PUSH ecx // pass referrer
833 PUSH eax // pass arg1
834 call CALLVAR(cxx_name) // cxx_name(arg1, referrer, Thread*)
835 addl MACRO_LITERAL(16), %esp // pop arguments
Fred Shih37f05ef2014-07-16 18:38:08 -0700836 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100837 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700838 CALL_MACRO(return_macro) // return or deliver exception
839 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700840END_MACRO
841
842MACRO3(TWO_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700843 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100844 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700845 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100846 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %edx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700847 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Fred Shih37f05ef2014-07-16 18:38:08 -0700848 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700849 PUSH edx // pass referrer
850 PUSH ecx // pass arg2
851 PUSH eax // pass arg1
852 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, referrer, Thread*)
853 addl MACRO_LITERAL(16), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700854 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100855 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700856 CALL_MACRO(return_macro) // return or deliver exception
857 END_FUNCTION VAR(c_name)
Fred Shih37f05ef2014-07-16 18:38:08 -0700858END_MACRO
859
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700860MACRO3(THREE_ARG_REF_DOWNCALL, c_name, cxx_name, return_macro)
Andreas Gampe4360be22015-07-14 23:34:44 -0700861 DEFINE_FUNCTION VAR(c_name)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100862 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700863 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100864 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ebx // get referrer
Andreas Gampe4360be22015-07-14 23:34:44 -0700865 subl MACRO_LITERAL(12), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700866 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -0700867 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700868 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -0700869 PUSH ebx // pass referrer
870 PUSH edx // pass arg3
871 PUSH ecx // pass arg2
872 PUSH eax // pass arg1
873 call CALLVAR(cxx_name) // cxx_name(arg1, arg2, arg3, referrer,
874 // Thread*)
875 addl LITERAL(32), %esp // pop arguments
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700876 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100877 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampe4360be22015-07-14 23:34:44 -0700878 CALL_MACRO(return_macro) // return or deliver exception
879 END_FUNCTION VAR(c_name)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700880END_MACRO
Fred Shih37f05ef2014-07-16 18:38:08 -0700881
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700882MACRO0(RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER)
Ian Rogers7caad772012-03-30 01:07:54 -0700883 testl %eax, %eax // eax == 0 ?
Ian Rogersd36c52e2012-04-09 16:29:25 -0700884 jz 1f // if eax == 0 goto 1
885 ret // return
8861: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700887 DELIVER_PENDING_EXCEPTION
888END_MACRO
889
Ian Rogersd36c52e2012-04-09 16:29:25 -0700890MACRO0(RETURN_IF_EAX_ZERO)
891 testl %eax, %eax // eax == 0 ?
892 jnz 1f // if eax != 0 goto 1
893 ret // return
8941: // deliver exception on current thread
Ian Rogers7caad772012-03-30 01:07:54 -0700895 DELIVER_PENDING_EXCEPTION
Ian Rogersd36c52e2012-04-09 16:29:25 -0700896END_MACRO
Ian Rogers7caad772012-03-30 01:07:54 -0700897
jeffhaod66a8752012-05-22 15:30:16 -0700898MACRO0(RETURN_OR_DELIVER_PENDING_EXCEPTION)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700899 cmpl MACRO_LITERAL(0),%fs:THREAD_EXCEPTION_OFFSET // exception field == 0 ?
Andreas Gampe4360be22015-07-14 23:34:44 -0700900 jne 1f // if exception field != 0 goto 1
901 ret // return
9021: // deliver exception on current thread
jeffhaod66a8752012-05-22 15:30:16 -0700903 DELIVER_PENDING_EXCEPTION
904END_MACRO
905
Mathieu Chartier7410f292013-11-24 13:17:35 -0800906// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -0700907GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
lwang85de95c872015-11-10 17:26:31 +0800908
909// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
910DEFINE_FUNCTION art_quick_alloc_object_rosalloc
911 // Fast path rosalloc allocation.
912 // eax: uint32_t type_idx/return value, ecx: ArtMethod*
913 // ebx, edx: free
914 PUSH edi
915 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
916 // Load the class (edx)
917 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
918 testl %edx, %edx // Check null class
919 jz .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800920
921 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
922 // Check if the thread local allocation
923 // stack has room
924 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
925 cmpl THREAD_LOCAL_ALLOC_STACK_END_OFFSET(%ebx), %edi
926 jae .Lart_quick_alloc_object_rosalloc_slow_path
927
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700928 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %edi // Load the object size (edi)
lwang85de95c872015-11-10 17:26:31 +0800929 // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700930 // local allocation. Also does the
931 // finalizable and initialization check.
lwang85de95c872015-11-10 17:26:31 +0800932 cmpl LITERAL(ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE), %edi
933 ja .Lart_quick_alloc_object_rosalloc_slow_path
lwang85de95c872015-11-10 17:26:31 +0800934 shrl LITERAL(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT), %edi // Calculate the rosalloc bracket index
935 // from object size.
lwang85de95c872015-11-10 17:26:31 +0800936 // Load thread local rosalloc run (ebx)
Mathieu Chartier161db1d2016-09-01 14:06:54 -0700937 // Subtract __SIZEOF_POINTER__ to subtract
938 // one from edi as there is no 0 byte run
939 // and the size is already aligned.
940 movl (THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)(%ebx, %edi, __SIZEOF_POINTER__), %ebx
lwang85de95c872015-11-10 17:26:31 +0800941 // Load free_list head (edi),
942 // this will be the return value.
943 movl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx), %edi
944 test %edi, %edi
945 jz .Lart_quick_alloc_object_rosalloc_slow_path
946 // Point of no slow path. Won't go to
947 // the slow path from here on. Ok to
948 // clobber eax and ecx.
949 movl %edi, %eax
950 // Load the next pointer of the head
951 // and update head of free list with
952 // next pointer
953 movl ROSALLOC_SLOT_NEXT_OFFSET(%eax), %edi
954 movl %edi, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)(%ebx)
955 // Decrement size of free list by 1
956 decl (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)(%ebx)
957 // Store the class pointer in the
958 // header. This also overwrites the
959 // next pointer. The offsets are
960 // asserted to match.
961#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
962#error "Class pointer needs to overwrite next pointer."
963#endif
964 POISON_HEAP_REF edx
965 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
966 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
967 // Push the new object onto the thread
968 // local allocation stack and
969 // increment the thread local
970 // allocation stack top.
971 movl THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx), %edi
972 movl %eax, (%edi)
973 addl LITERAL(COMPRESSED_REFERENCE_SIZE), %edi
974 movl %edi, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET(%ebx)
975 // No fence needed for x86.
976 POP edi
977 ret
978.Lart_quick_alloc_object_rosalloc_slow_path:
979 POP edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100980 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
lwang85de95c872015-11-10 17:26:31 +0800981 // Outgoing argument set up
982 PUSH eax // alignment padding
983 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
984 CFI_ADJUST_CFA_OFFSET(4)
985 PUSH ecx
986 PUSH eax
987 call SYMBOL(artAllocObjectFromCodeRosAlloc) // cxx_name(arg0, arg1, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100988 addl LITERAL(16), %esp // pop arguments
lwang85de95c872015-11-10 17:26:31 +0800989 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100990 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
lwang85de95c872015-11-10 17:26:31 +0800991 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
992END_FUNCTION art_quick_alloc_object_rosalloc
993
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800994// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
995//
996// EAX: type_idx/return_value, ECX: ArtMethod*, EDX: the class.
997MACRO1(ALLOC_OBJECT_TLAB_FAST_PATH, slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100998 testl %edx, %edx // Check null class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +0800999 jz VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001000 movl %fs:THREAD_SELF_OFFSET, %ebx // ebx = thread
1001 movl THREAD_LOCAL_END_OFFSET(%ebx), %edi // Load thread_local_end.
1002 subl THREAD_LOCAL_POS_OFFSET(%ebx), %edi // Compute the remaining buffer size.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001003 movl MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET(%edx), %esi // Load the object size.
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001004 cmpl %edi, %esi // Check if it fits.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001005 ja VAR(slowPathLabel)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001006 movl THREAD_LOCAL_POS_OFFSET(%ebx), %eax // Load thread_local_pos
1007 // as allocated object.
1008 addl %eax, %esi // Add the object size.
1009 movl %esi, THREAD_LOCAL_POS_OFFSET(%ebx) // Update thread_local_pos.
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001010 incl THREAD_LOCAL_OBJECTS_OFFSET(%ebx) // Increase thread_local_objects.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001011 // Store the class pointer in the header.
1012 // No fence needed for x86.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001013 POISON_HEAP_REF edx
1014 movl %edx, MIRROR_OBJECT_CLASS_OFFSET(%eax)
1015 POP edi
1016 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001017 ret // Fast path succeeded.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001018END_MACRO
1019
1020// The common slow path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1021MACRO1(ALLOC_OBJECT_TLAB_SLOW_PATH, cxx_name)
1022 POP edi
1023 POP esi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001024 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001025 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001026 PUSH eax // alignment padding
1027 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001028 CFI_ADJUST_CFA_OFFSET(4)
1029 PUSH ecx
1030 PUSH eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001031 call CALLVAR(cxx_name) // cxx_name(arg0, arg1, Thread*)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001032 addl LITERAL(16), %esp
1033 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001034 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
1035 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER // return or deliver exception
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001036END_MACRO
1037
1038// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1039DEFINE_FUNCTION art_quick_alloc_object_tlab
1040 // Fast path tlab allocation.
1041 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1042 // EBX, EDX: free.
1043#if defined(USE_READ_BARRIER)
1044 int3
1045 int3
1046#endif
1047 PUSH esi
1048 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001049 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001050 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001051 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001052 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
1053 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
1054.Lart_quick_alloc_object_tlab_slow_path:
1055 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeTLAB
1056END_FUNCTION art_quick_alloc_object_tlab
1057
1058// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB).
1059DEFINE_FUNCTION art_quick_alloc_object_region_tlab
1060 // Fast path region tlab allocation.
1061 // EAX: uint32_t type_idx/return value, ECX: ArtMethod*.
1062 // EBX, EDX: free.
1063#if !defined(USE_READ_BARRIER)
1064 int3
1065 int3
1066#endif
1067 PUSH esi
1068 PUSH edi
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001069 movl ART_METHOD_DEX_CACHE_TYPES_OFFSET_32(%ecx), %edx // Load dex cache resolved types array
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001070 // Might need to break down into multiple instructions to get the base address in a register.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001071 // Load the class
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001072 movl 0(%edx, %eax, COMPRESSED_REFERENCE_SIZE), %edx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001073 // Read barrier for class load.
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001074 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001075 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1076 // Null check so that we can load the lock word.
1077 testl %edx, %edx
1078 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1079 // Check the mark bit, if it is 1 return.
1080 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1081 jz .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001082.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1083 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1084.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1085 // The read barrier slow path. Mark the class.
1086 PUSH eax
1087 PUSH ecx
1088 // Outgoing argument set up
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001089 subl MACRO_LITERAL(8), %esp // Alignment padding
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001090 CFI_ADJUST_CFA_OFFSET(8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001091 PUSH edx // Pass the class as the first param.
1092 call SYMBOL(artReadBarrierMark) // cxx_name(mirror::Object* obj)
Sang, Chunlei69cee6a2016-04-21 10:22:02 +08001093 movl %eax, %edx
1094 addl MACRO_LITERAL(12), %esp
1095 CFI_ADJUST_CFA_OFFSET(-12)
1096 POP ecx
1097 POP eax
1098 jmp .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1099.Lart_quick_alloc_object_region_tlab_slow_path:
1100 ALLOC_OBJECT_TLAB_SLOW_PATH artAllocObjectFromCodeRegionTLAB
1101END_FUNCTION art_quick_alloc_object_region_tlab
Mark Mendell3f2d0312014-01-20 17:20:27 -08001102
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001103DEFINE_FUNCTION art_quick_resolve_string
Christina Wadsworth74898e72016-08-25 13:23:01 -07001104 movl 4(%esp), %ecx // get referrer
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001105 movl ART_METHOD_DECLARING_CLASS_OFFSET(%ecx), %ecx // get declaring class
1106 movl DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET(%ecx), %ecx // get string dex cache
1107 movl LITERAL(STRING_DEX_CACHE_SIZE_MINUS_ONE), %edx
1108 andl %eax, %edx
Christina Wadsworth74898e72016-08-25 13:23:01 -07001109 movlps (%ecx, %edx, STRING_DEX_CACHE_ELEMENT_SIZE), %xmm0 // load string idx and ptr to xmm0
1110 movd %xmm0, %ecx // extract pointer
1111 pshufd LITERAL(0x55), %xmm0, %xmm0 // shuffle index into lowest bits
1112 movd %xmm0, %edx // extract index
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001113 cmp %edx, %eax
1114 jne .Lart_quick_resolve_string_slow_path
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001115 movl %ecx, %eax
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001116#ifdef USE_READ_BARRIER
1117 cmpl LITERAL(0), %fs:THREAD_IS_GC_MARKING_OFFSET
1118 jne .Lart_quick_resolve_string_marking
1119#endif
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001120 ret
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001121.Lart_quick_resolve_string_slow_path:
1122 // Outgoing argument set up
Christina Wadsworth74898e72016-08-25 13:23:01 -07001123 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001124 subl LITERAL(8), %esp // push padding
1125 CFI_ADJUST_CFA_OFFSET(8)
1126 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1127 CFI_ADJUST_CFA_OFFSET(4)
1128 PUSH eax // pass arg1
1129 call SYMBOL(artResolveStringFromCode)
1130 addl LITERAL(16), %esp // pop arguments
1131 CFI_ADJUST_CFA_OFFSET(-16)
1132 RESTORE_SAVE_REFS_ONLY_FRAME
1133 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001134.Lart_quick_resolve_string_marking:
Christina Wadsworth74898e72016-08-25 13:23:01 -07001135 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Christina Wadsworth4489fb32016-08-23 14:13:43 -07001136 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax)
1137 jnz .Lart_quick_resolve_string_no_rb
1138 subl LITERAL(12), %esp // alignment padding
1139 CFI_ADJUST_CFA_OFFSET(12)
1140 PUSH eax // Pass the string as the first param.
1141 call SYMBOL(artReadBarrierMark)
1142 addl LITERAL(16), %esp
1143 CFI_ADJUST_CFA_OFFSET(-16)
1144.Lart_quick_resolve_string_no_rb:
1145 RESTORE_SAVE_REFS_ONLY_FRAME
1146 ret
Christina Wadsworth39c8a112016-08-22 13:22:36 -07001147END_FUNCTION art_quick_resolve_string
1148
Hiroshi Yamauchi4adeab12015-10-02 15:27:55 -07001149ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1150ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1151ONE_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 -07001152
Ian Rogers832336b2014-10-08 15:35:22 -07001153TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_EAX_ZERO
Ian Rogers7caad772012-03-30 01:07:54 -07001154
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001155DEFINE_FUNCTION art_quick_lock_object
1156 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001157 jz .Lslow_lock
1158.Lretry_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001159 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001160 test LITERAL(LOCK_WORD_STATE_MASK), %ecx // test the 2 high bits.
Ian Rogers8016a122014-02-21 20:37:21 -08001161 jne .Lslow_lock // slow path if either of the two high bits are set.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001162 movl %ecx, %edx // save lock word (edx) to keep read barrier bits.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001163 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the gc bits.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001164 test %ecx, %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001165 jnz .Lalready_thin // lock word contains a thin lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001166 // unlocked case - edx: original lock word, eax: obj.
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001167 movl %eax, %ecx // remember object in case of retry
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001168 movl %edx, %eax // eax: lock word zero except for read barrier bits.
1169 movl %fs:THREAD_ID_OFFSET, %edx // load thread id.
1170 or %eax, %edx // edx: thread id with count of 0 + read barrier bits.
1171 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1172 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001173 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001174.Lalready_thin: // edx: lock word (with high 2 bits zero and original rb bits), eax: obj.
1175 movl %fs:THREAD_ID_OFFSET, %ecx // ecx := thread id
Serguei Katkov8ef84af2014-04-03 15:17:26 +07001176 cmpw %cx, %dx // do we hold the lock already?
Ian Rogers8016a122014-02-21 20:37:21 -08001177 jne .Lslow_lock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001178 movl %edx, %ecx // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001179 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %ecx // zero the read barrier bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001180 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // increment recursion count for overflow check.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001181 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 -08001182 jne .Lslow_lock // count overflowed so go slow
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001183 movl %eax, %ecx // save obj to use eax for cmpxchg.
1184 movl %edx, %eax // copy the lock word as the old val for cmpxchg.
1185 addl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx // increment recursion count again for real.
1186 // update lockword, cmpxchg necessary for read barrier bits.
1187 lock cmpxchg %edx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%ecx) // eax: old val, edx: new val.
1188 jnz .Llock_cmpxchg_fail // cmpxchg failed retry
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001189 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001190.Llock_cmpxchg_fail:
1191 movl %ecx, %eax // restore eax
1192 jmp .Lretry_lock
Ian Rogers8016a122014-02-21 20:37:21 -08001193.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001194 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001195 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001196 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001197 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001198 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001199 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001200 PUSH eax // pass object
1201 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1202 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001203 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001204 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001205 RETURN_IF_EAX_ZERO
1206END_FUNCTION art_quick_lock_object
1207
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001208DEFINE_FUNCTION art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001209 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001210 // Outgoing argument set up
1211 subl LITERAL(8), %esp // alignment padding
1212 CFI_ADJUST_CFA_OFFSET(8)
1213 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1214 CFI_ADJUST_CFA_OFFSET(4)
1215 PUSH eax // pass object
1216 call SYMBOL(artLockObjectFromCode) // artLockObjectFromCode(object, Thread*)
1217 addl LITERAL(16), %esp // pop arguments
1218 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001219 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001220 RETURN_IF_EAX_ZERO
1221END_FUNCTION art_quick_lock_object_no_inline
1222
1223
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001224DEFINE_FUNCTION art_quick_unlock_object
1225 testl %eax, %eax // null check object/eax
Ian Rogers8016a122014-02-21 20:37:21 -08001226 jz .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001227.Lretry_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001228 movl MIRROR_OBJECT_LOCK_WORD_OFFSET(%eax), %ecx // ecx := lock word
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001229 movl %fs:THREAD_ID_OFFSET, %edx // edx := thread id
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001230 test LITERAL(LOCK_WORD_STATE_MASK), %ecx
Serguei Katkove78d4e12014-04-07 10:14:08 +07001231 jnz .Lslow_unlock // lock word contains a monitor
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001232 cmpw %cx, %dx // does the thread id match?
Ian Rogers8016a122014-02-21 20:37:21 -08001233 jne .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001234 movl %ecx, %edx // copy the lock word to detect new count of 0.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001235 andl LITERAL(LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED), %edx // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001236 cmpl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %edx
Ian Rogers8016a122014-02-21 20:37:21 -08001237 jae .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001238 // update lockword, cmpxchg necessary for read barrier bits.
1239 movl %eax, %edx // edx: obj
1240 movl %ecx, %eax // eax: old lock word.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001241 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 -08001242#ifndef USE_READ_BARRIER
1243 movl %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1244#else
1245 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1246 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1247#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001248 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001249.Lrecursive_thin_unlock: // ecx: original lock word, eax: obj
1250 // update lockword, cmpxchg necessary for read barrier bits.
1251 movl %eax, %edx // edx: obj
1252 movl %ecx, %eax // eax: old lock word.
1253 subl LITERAL(LOCK_WORD_THIN_LOCK_COUNT_ONE), %ecx // ecx: new lock word with decremented count.
1254#ifndef USE_READ_BARRIER
1255 mov %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx)
1256#else
1257 lock cmpxchg %ecx, MIRROR_OBJECT_LOCK_WORD_OFFSET(%edx) // eax: old val, ecx: new val.
1258 jnz .Lunlock_cmpxchg_fail // cmpxchg failed retry
1259#endif
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001260 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001261.Lunlock_cmpxchg_fail: // edx: obj
1262 movl %edx, %eax // restore eax
1263 jmp .Lretry_unlock
Ian Rogers8016a122014-02-21 20:37:21 -08001264.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001265 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001266 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001267 subl LITERAL(8), %esp // alignment padding
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001268 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampe4360be22015-07-14 23:34:44 -07001269 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001270 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001271 PUSH eax // pass object
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001272 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001273 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001274 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001275 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001276 RETURN_IF_EAX_ZERO
1277END_FUNCTION art_quick_unlock_object
1278
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001279DEFINE_FUNCTION art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001280 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001281 // Outgoing argument set up
1282 subl LITERAL(8), %esp // alignment padding
1283 CFI_ADJUST_CFA_OFFSET(8)
1284 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1285 CFI_ADJUST_CFA_OFFSET(4)
1286 PUSH eax // pass object
1287 call SYMBOL(artUnlockObjectFromCode) // artUnlockObjectFromCode(object, Thread*)
1288 addl LITERAL(16), %esp // pop arguments
1289 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001290 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001291 RETURN_IF_EAX_ZERO
1292END_FUNCTION art_quick_unlock_object_no_inline
1293
Ian Rogers468532e2013-08-05 10:56:33 -07001294DEFINE_FUNCTION art_quick_is_assignable
Andreas Gampe4360be22015-07-14 23:34:44 -07001295 PUSH eax // alignment padding
1296 PUSH ecx // pass arg2 - obj->klass
1297 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001298 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Andreas Gampe4360be22015-07-14 23:34:44 -07001299 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001300 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001301 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001302END_FUNCTION art_quick_is_assignable
Ian Rogers7caad772012-03-30 01:07:54 -07001303
Ian Rogersa9a82542013-10-04 11:17:26 -07001304DEFINE_FUNCTION art_quick_check_cast
Andreas Gampe4360be22015-07-14 23:34:44 -07001305 PUSH eax // alignment padding
1306 PUSH ecx // pass arg2 - obj->klass
1307 PUSH eax // pass arg1 - checked class
Andreas Gampe29b38412014-08-13 00:15:43 -07001308 call SYMBOL(artIsAssignableFromCode) // (Class* klass, Class* ref_klass)
Ian Rogersa9a82542013-10-04 11:17:26 -07001309 testl %eax, %eax
Andreas Gampe4360be22015-07-14 23:34:44 -07001310 jz 1f // jump forward if not assignable
1311 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001312 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogersa9a82542013-10-04 11:17:26 -07001313 ret
Andreas Gampe6b90d422015-06-26 19:49:24 -07001314
Andreas Gampe4360be22015-07-14 23:34:44 -07001315 CFI_ADJUST_CFA_OFFSET(12) // Reset unwind info so following code unwinds.
Ian Rogersa9a82542013-10-04 11:17:26 -070013161:
Andreas Gampe4360be22015-07-14 23:34:44 -07001317 POP eax // pop arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001318 POP ecx
1319 addl LITERAL(4), %esp
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001320 CFI_ADJUST_CFA_OFFSET(-4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001321 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001322 // Outgoing argument set up
Andreas Gampe4360be22015-07-14 23:34:44 -07001323 PUSH eax // alignment padding
1324 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001325 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe4360be22015-07-14 23:34:44 -07001326 PUSH ecx // pass arg2
1327 PUSH eax // pass arg1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001328 call SYMBOL(artThrowClassCastException) // (Class* a, Class* b, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001329 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001330END_FUNCTION art_quick_check_cast
1331
Man Cao1aee9002015-07-14 22:31:42 -07001332// Restore reg's value if reg is not the same as exclude_reg, otherwise just adjust stack.
1333MACRO2(POP_REG_NE, reg, exclude_reg)
1334 .ifc RAW_VAR(reg), RAW_VAR(exclude_reg)
1335 addl MACRO_LITERAL(4), %esp
1336 CFI_ADJUST_CFA_OFFSET(-4)
1337 .else
1338 POP RAW_VAR(reg)
1339 .endif
1340END_MACRO
1341
1342 /*
1343 * Macro to insert read barrier, only used in art_quick_aput_obj.
1344 * obj_reg and dest_reg are registers, offset is a defined literal such as
1345 * MIRROR_OBJECT_CLASS_OFFSET.
1346 * pop_eax is a boolean flag, indicating if eax is popped after the call.
1347 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1348 */
1349MACRO4(READ_BARRIER, obj_reg, offset, dest_reg, pop_eax)
1350#ifdef USE_READ_BARRIER
1351 PUSH eax // save registers used in art_quick_aput_obj
1352 PUSH ebx
1353 PUSH edx
1354 PUSH ecx
1355 // Outgoing argument set up
1356 pushl MACRO_LITERAL((RAW_VAR(offset))) // pass offset, double parentheses are necessary
1357 CFI_ADJUST_CFA_OFFSET(4)
1358 PUSH RAW_VAR(obj_reg) // pass obj_reg
1359 PUSH eax // pass ref, just pass eax for now since parameter ref is unused
1360 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj_reg, offset)
1361 // No need to unpoison return value in eax, artReadBarrierSlow() would do the unpoisoning.
1362 .ifnc RAW_VAR(dest_reg), eax
1363 movl %eax, REG_VAR(dest_reg) // save loaded ref in dest_reg
1364 .endif
1365 addl MACRO_LITERAL(12), %esp // pop arguments
1366 CFI_ADJUST_CFA_OFFSET(-12)
1367 POP_REG_NE ecx, RAW_VAR(dest_reg) // Restore args except dest_reg
1368 POP_REG_NE edx, RAW_VAR(dest_reg)
1369 POP_REG_NE ebx, RAW_VAR(dest_reg)
1370 .ifc RAW_VAR(pop_eax), true
1371 POP_REG_NE eax, RAW_VAR(dest_reg)
1372 .endif
1373#else
1374 movl RAW_VAR(offset)(REG_VAR(obj_reg)), REG_VAR(dest_reg)
1375 UNPOISON_HEAP_REF RAW_VAR(dest_reg)
1376#endif // USE_READ_BARRIER
1377END_MACRO
1378
Ian Rogersa9a82542013-10-04 11:17:26 -07001379 /*
1380 * Entry from managed code for array put operations of objects where the value being stored
1381 * needs to be checked for compatibility.
1382 * eax = array, ecx = index, edx = value
1383 */
1384DEFINE_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1385 testl %eax, %eax
Dan Albert3bed41c2014-08-07 17:39:34 -07001386 jnz SYMBOL(art_quick_aput_obj_with_bound_check)
1387 jmp SYMBOL(art_quick_throw_null_pointer_exception)
Ian Rogersa9a82542013-10-04 11:17:26 -07001388END_FUNCTION art_quick_aput_obj_with_null_and_bound_check
1389
1390DEFINE_FUNCTION art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001391 movl MIRROR_ARRAY_LENGTH_OFFSET(%eax), %ebx
Ian Rogersa9a82542013-10-04 11:17:26 -07001392 cmpl %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001393 jb SYMBOL(art_quick_aput_obj)
Ian Rogersa9a82542013-10-04 11:17:26 -07001394 mov %ecx, %eax
1395 mov %ebx, %ecx
Dan Albert3bed41c2014-08-07 17:39:34 -07001396 jmp SYMBOL(art_quick_throw_array_bounds)
Ian Rogersa9a82542013-10-04 11:17:26 -07001397END_FUNCTION art_quick_aput_obj_with_bound_check
1398
1399DEFINE_FUNCTION art_quick_aput_obj
1400 test %edx, %edx // store of null
Ian Rogers8016a122014-02-21 20:37:21 -08001401 jz .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001402 READ_BARRIER eax, MIRROR_OBJECT_CLASS_OFFSET, ebx, true
1403 READ_BARRIER ebx, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, ebx, true
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001404 // value's type == array's component type - trivial assignability
Man Cao1aee9002015-07-14 22:31:42 -07001405#if defined(USE_READ_BARRIER)
1406 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, false
1407 cmpl %eax, %ebx
1408 POP eax // restore eax from the push in the beginning of READ_BARRIER macro
Man Cao63069212015-08-21 15:51:39 -07001409 // This asymmetric push/pop saves a push of eax and maintains stack alignment.
Man Cao1aee9002015-07-14 22:31:42 -07001410#elif defined(USE_HEAP_POISONING)
1411 PUSH eax // save eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001412 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
1413 UNPOISON_HEAP_REF eax
1414 cmpl %eax, %ebx
Man Cao1aee9002015-07-14 22:31:42 -07001415 POP eax // restore eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001416#else
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001417 cmpl MIRROR_OBJECT_CLASS_OFFSET(%edx), %ebx
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001418#endif
Ian Rogers8016a122014-02-21 20:37:21 -08001419 jne .Lcheck_assignability
1420.Ldo_aput:
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001421 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001422 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001423 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1424 shrl LITERAL(7), %eax
1425 movb %dl, (%edx, %eax)
1426 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001427.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001428 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001429 ret
Ian Rogers8016a122014-02-21 20:37:21 -08001430.Lcheck_assignability:
Andreas Gampe4360be22015-07-14 23:34:44 -07001431 PUSH eax // save arguments
Ian Rogersa9a82542013-10-04 11:17:26 -07001432 PUSH ecx
1433 PUSH edx
Man Cao63069212015-08-21 15:51:39 -07001434#if defined(USE_READ_BARRIER)
1435 subl LITERAL(4), %esp // alignment padding
1436 CFI_ADJUST_CFA_OFFSET(4)
1437 READ_BARRIER edx, MIRROR_OBJECT_CLASS_OFFSET, eax, true
1438 subl LITERAL(4), %esp // alignment padding
1439 CFI_ADJUST_CFA_OFFSET(4)
1440 PUSH eax // pass arg2 - type of the value to be stored
1441#elif defined(USE_HEAP_POISONING)
Andreas Gampe4360be22015-07-14 23:34:44 -07001442 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001443 CFI_ADJUST_CFA_OFFSET(8)
Man Cao63069212015-08-21 15:51:39 -07001444 movl MIRROR_OBJECT_CLASS_OFFSET(%edx), %eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001445 UNPOISON_HEAP_REF eax
Man Cao63069212015-08-21 15:51:39 -07001446 PUSH eax // pass arg2 - type of the value to be stored
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001447#else
Man Cao63069212015-08-21 15:51:39 -07001448 subl LITERAL(8), %esp // alignment padding
1449 CFI_ADJUST_CFA_OFFSET(8)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001450 pushl MIRROR_OBJECT_CLASS_OFFSET(%edx) // pass arg2 - type of the value to be stored
Mark Mendell3f2d0312014-01-20 17:20:27 -08001451 CFI_ADJUST_CFA_OFFSET(4)
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001452#endif
Mathieu Chartier27386392015-06-27 15:42:27 -07001453 PUSH ebx // pass arg1 - component type of the array
Andreas Gampe29b38412014-08-13 00:15:43 -07001454 call SYMBOL(artIsAssignableFromCode) // (Class* a, Class* b)
Mathieu Chartier27386392015-06-27 15:42:27 -07001455 addl LITERAL(16), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001456 CFI_ADJUST_CFA_OFFSET(-16)
Ian Rogersa9a82542013-10-04 11:17:26 -07001457 testl %eax, %eax
Ian Rogers8016a122014-02-21 20:37:21 -08001458 jz .Lthrow_array_store_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001459 POP edx
1460 POP ecx
1461 POP eax
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001462 POISON_HEAP_REF edx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001463 movl %edx, MIRROR_OBJECT_ARRAY_DATA_OFFSET(%eax, %ecx, 4) // do the aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001464 movl %fs:THREAD_CARD_TABLE_OFFSET, %edx
1465 shrl LITERAL(7), %eax
1466 movb %dl, (%edx, %eax)
1467 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001468 CFI_ADJUST_CFA_OFFSET(12) // 3 POP after the jz for unwinding.
Ian Rogers8016a122014-02-21 20:37:21 -08001469.Lthrow_array_store_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001470 POP edx
1471 POP ecx
1472 POP eax
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001473 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx // save all registers as basis for long jump context
Ian Rogersa9a82542013-10-04 11:17:26 -07001474 // Outgoing argument set up
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001475 PUSH eax // alignment padding
Ian Rogersa9a82542013-10-04 11:17:26 -07001476 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001477 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersa9a82542013-10-04 11:17:26 -07001478 PUSH edx // pass arg2 - value
1479 PUSH eax // pass arg1 - array
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001480 call SYMBOL(artThrowArrayStoreException) // (array, value, Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001481 UNREACHABLE
Ian Rogersa9a82542013-10-04 11:17:26 -07001482END_FUNCTION art_quick_aput_obj
1483
Logan Chien8dbb7082013-01-25 20:31:17 +08001484DEFINE_FUNCTION art_quick_memcpy
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001485 SETUP_GOT_NOSAVE ebx // clobbers EBX
Ian Rogersaeeada42013-02-13 11:28:34 -08001486 PUSH edx // pass arg3
1487 PUSH ecx // pass arg2
1488 PUSH eax // pass arg1
Mark Mendell3f2d0312014-01-20 17:20:27 -08001489 call PLT_SYMBOL(memcpy) // (void*, const void*, size_t)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001490 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001491 CFI_ADJUST_CFA_OFFSET(-12)
Ian Rogers7caad772012-03-30 01:07:54 -07001492 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08001493END_FUNCTION art_quick_memcpy
Ian Rogers7caad772012-03-30 01:07:54 -07001494
Vladimir Marko952dbb12016-07-28 12:01:51 +01001495DEFINE_FUNCTION art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001496 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx // save everything for GC
Vladimir Marko952dbb12016-07-28 12:01:51 +01001497 // Outgoing argument set up
1498 subl MACRO_LITERAL(12), %esp // push padding
1499 CFI_ADJUST_CFA_OFFSET(12)
1500 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
1501 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Marko603b7ca2016-08-04 16:46:51 +01001502 call SYMBOL(artTestSuspendFromCode) // (Thread*)
Vladimir Marko952dbb12016-07-28 12:01:51 +01001503 addl MACRO_LITERAL(16), %esp // pop arguments
1504 CFI_ADJUST_CFA_OFFSET(-16)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001505 RESTORE_SAVE_EVERYTHING_FRAME // restore frame up to return address
Vladimir Marko952dbb12016-07-28 12:01:51 +01001506 ret // return
1507END_FUNCTION art_quick_test_suspend
Ian Rogers7caad772012-03-30 01:07:54 -07001508
Ian Rogers468532e2013-08-05 10:56:33 -07001509DEFINE_FUNCTION art_quick_d2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001510 subl LITERAL(12), %esp // alignment padding, room for argument
1511 CFI_ADJUST_CFA_OFFSET(12)
1512 movsd %xmm0, 0(%esp) // arg a
1513 call SYMBOL(art_d2l) // (jdouble a)
jeffhao41005dd2012-05-09 17:58:52 -07001514 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001515 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001516 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001517END_FUNCTION art_quick_d2l
jeffhao41005dd2012-05-09 17:58:52 -07001518
Ian Rogers468532e2013-08-05 10:56:33 -07001519DEFINE_FUNCTION art_quick_f2l
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001520 subl LITERAL(12), %esp // alignment padding
1521 CFI_ADJUST_CFA_OFFSET(12)
1522 movss %xmm0, 0(%esp) // arg a
1523 call SYMBOL(art_f2l) // (jfloat a)
jeffhao41005dd2012-05-09 17:58:52 -07001524 addl LITERAL(12), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001525 CFI_ADJUST_CFA_OFFSET(-12)
jeffhao41005dd2012-05-09 17:58:52 -07001526 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001527END_FUNCTION art_quick_f2l
jeffhao41005dd2012-05-09 17:58:52 -07001528
Ian Rogers468532e2013-08-05 10:56:33 -07001529DEFINE_FUNCTION art_quick_ldiv
Andreas Gampe4360be22015-07-14 23:34:44 -07001530 subl LITERAL(12), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001531 CFI_ADJUST_CFA_OFFSET(12)
Andreas Gampe4360be22015-07-14 23:34:44 -07001532 PUSH ebx // pass arg4 b.hi
1533 PUSH edx // pass arg3 b.lo
1534 PUSH ecx // pass arg2 a.hi
1535 PUSH eax // pass arg1 a.lo
1536 call SYMBOL(artLdiv) // (jlong a, jlong b)
1537 addl LITERAL(28), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001538 CFI_ADJUST_CFA_OFFSET(-28)
Ian Rogers55bd45f2012-04-04 17:31:20 -07001539 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001540END_FUNCTION art_quick_ldiv
Ian Rogers55bd45f2012-04-04 17:31:20 -07001541
Ian Rogersa9a82542013-10-04 11:17:26 -07001542DEFINE_FUNCTION art_quick_lmod
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(artLmod) // (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 Rogersa9a82542013-10-04 11:17:26 -07001553END_FUNCTION art_quick_lmod
Ian Rogers55bd45f2012-04-04 17:31:20 -07001554
Ian Rogers468532e2013-08-05 10:56:33 -07001555DEFINE_FUNCTION art_quick_lmul
Andreas Gampe4360be22015-07-14 23:34:44 -07001556 imul %eax, %ebx // ebx = a.lo(eax) * b.hi(ebx)
1557 imul %edx, %ecx // ecx = b.lo(edx) * a.hi(ecx)
1558 mul %edx // edx:eax = a.lo(eax) * b.lo(edx)
Ian Rogers5793fea2013-02-14 13:33:34 -08001559 add %ebx, %ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001560 add %ecx, %edx // edx += (a.lo * b.hi) + (b.lo * a.hi)
jeffhao644d5312012-05-03 19:04:49 -07001561 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001562END_FUNCTION art_quick_lmul
jeffhao644d5312012-05-03 19:04:49 -07001563
Ian Rogers468532e2013-08-05 10:56:33 -07001564DEFINE_FUNCTION art_quick_lshl
jeffhao644d5312012-05-03 19:04:49 -07001565 // ecx:eax << edx
Ian Rogers141d6222012-04-05 12:23:06 -07001566 xchg %edx, %ecx
1567 shld %cl,%eax,%edx
1568 shl %cl,%eax
1569 test LITERAL(32), %cl
1570 jz 1f
1571 mov %eax, %edx
1572 xor %eax, %eax
15731:
1574 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001575END_FUNCTION art_quick_lshl
Ian Rogers141d6222012-04-05 12:23:06 -07001576
Ian Rogers468532e2013-08-05 10:56:33 -07001577DEFINE_FUNCTION art_quick_lshr
jeffhao644d5312012-05-03 19:04:49 -07001578 // ecx:eax >> edx
Ian Rogers141d6222012-04-05 12:23:06 -07001579 xchg %edx, %ecx
jeffhao644d5312012-05-03 19:04:49 -07001580 shrd %cl,%edx,%eax
1581 sar %cl,%edx
Ian Rogers141d6222012-04-05 12:23:06 -07001582 test LITERAL(32),%cl
1583 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001584 mov %edx, %eax
1585 sar LITERAL(31), %edx
Ian Rogers141d6222012-04-05 12:23:06 -070015861:
1587 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001588END_FUNCTION art_quick_lshr
Ian Rogers141d6222012-04-05 12:23:06 -07001589
Ian Rogers468532e2013-08-05 10:56:33 -07001590DEFINE_FUNCTION art_quick_lushr
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 shr %cl,%edx
1595 test LITERAL(32),%cl
Ian Rogers141d6222012-04-05 12:23:06 -07001596 jz 1f
jeffhao5121e0b2012-05-08 18:23:38 -07001597 mov %edx, %eax
1598 xor %edx, %edx
Ian Rogers141d6222012-04-05 12:23:06 -070015991:
1600 ret
Ian Rogers468532e2013-08-05 10:56:33 -07001601END_FUNCTION art_quick_lushr
Ian Rogers141d6222012-04-05 12:23:06 -07001602
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001603ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1604ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1605ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1606ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1607ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1608ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1609ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001610
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001611TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1612TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1613TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1614TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1615TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1616TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
1617TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION
Fred Shih37f05ef2014-07-16 18:38:08 -07001618
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001619TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_EAX_ZERO
1620TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_EAX_ZERO
1621TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_EAX_ZERO
1622TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_EAX_ZERO
jeffhao9dbb23e2012-05-18 17:03:57 -07001623
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001624THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_EAX_ZERO
1625THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_EAX_ZERO
1626THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_EAX_ZERO
1627THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_EAX_ZERO
1628
1629// Call artSet64InstanceFromCode with 4 word size arguments and the referrer.
Ian Rogers468532e2013-08-05 10:56:33 -07001630DEFINE_FUNCTION art_quick_set64_instance
Serguei Katkove0b46a72014-11-05 16:13:18 +06001631 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001632 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Serguei Katkove0b46a72014-11-05 16:13:18 +06001633 movd %xmm0, %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001634 // Outgoing argument set up
jeffhao1ff4cd72012-05-21 11:17:48 -07001635 subl LITERAL(8), %esp // alignment padding
Mark Mendell3f2d0312014-01-20 17:20:27 -08001636 CFI_ADJUST_CFA_OFFSET(8)
jeffhao9dbb23e2012-05-18 17:03:57 -07001637 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001638 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001639 pushl (FRAME_SIZE_SAVE_REFS_ONLY+12)(%esp) // pass referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001640 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001641 PUSH ebx // pass high half of new_val
1642 PUSH edx // pass low half of new_val
1643 PUSH ecx // pass object
1644 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001645 call SYMBOL(artSet64InstanceFromCode) // (field_idx, Object*, new_val, referrer, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001646 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001647 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001648 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001649 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001650END_FUNCTION art_quick_set64_instance
jeffhao9dbb23e2012-05-18 17:03:57 -07001651
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001652// Call artSet64StaticFromCode with 3 word size arguments plus with the referrer in the 2nd position
1653// so that new_val is aligned on even registers were we passing arguments in registers.
Ian Rogers468532e2013-08-05 10:56:33 -07001654DEFINE_FUNCTION art_quick_set64_static
Calin Juravlee460d1d2015-09-29 04:52:17 +01001655 // TODO: Implement SETUP_GOT_NOSAVE for got_reg = ecx to avoid moving around the registers.
1656 movd %ebx, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001657 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx // save ref containing registers for GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001658 movd %xmm0, %ebx
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001659 mov FRAME_SIZE_SAVE_REFS_ONLY(%esp), %ecx // get referrer
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001660 subl LITERAL(12), %esp // alignment padding
1661 CFI_ADJUST_CFA_OFFSET(12)
jeffhao9dbb23e2012-05-18 17:03:57 -07001662 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001663 CFI_ADJUST_CFA_OFFSET(4)
Calin Juravlee460d1d2015-09-29 04:52:17 +01001664 PUSH ebx // pass high half of new_val
1665 PUSH edx // pass low half of new_val
1666 PUSH ecx // pass referrer
Ian Rogersaeeada42013-02-13 11:28:34 -08001667 PUSH eax // pass field_idx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001668 call SYMBOL(artSet64StaticFromCode) // (field_idx, referrer, new_val, Thread*)
jeffhao1ff4cd72012-05-21 11:17:48 -07001669 addl LITERAL(32), %esp // pop arguments
Mark Mendell3f2d0312014-01-20 17:20:27 -08001670 CFI_ADJUST_CFA_OFFSET(-32)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001671 RESTORE_SAVE_REFS_ONLY_FRAME // restore frame up to return address
jeffhao9dbb23e2012-05-18 17:03:57 -07001672 RETURN_IF_EAX_ZERO // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001673END_FUNCTION art_quick_set64_static
jeffhao9dbb23e2012-05-18 17:03:57 -07001674
Logan Chien8dbb7082013-01-25 20:31:17 +08001675DEFINE_FUNCTION art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001676 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Ian Rogersaeeada42013-02-13 11:28:34 -08001677 PUSH esp // pass SP
jeffhaod66a8752012-05-22 15:30:16 -07001678 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001679 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001680 PUSH ecx // pass receiver
1681 PUSH eax // pass proxy method
Andreas Gampe29b38412014-08-13 00:15:43 -07001682 call SYMBOL(artQuickProxyInvokeHandler) // (proxy method, receiver, Thread*, SP)
Ian Rogersaf6e67a2013-01-16 08:38:37 -08001683 movd %eax, %xmm0 // place return value also into floating point return value
1684 movd %edx, %xmm1
1685 punpckldq %xmm1, %xmm0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001686 addl LITERAL(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY), %esp
1687 CFI_ADJUST_CFA_OFFSET(-(16 + FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY))
1688 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhaod66a8752012-05-22 15:30:16 -07001689 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogersaeeada42013-02-13 11:28:34 -08001690END_FUNCTION art_quick_proxy_invoke_handler
jeffhao9dbb23e2012-05-18 17:03:57 -07001691
Jeff Hao88474b42013-10-23 16:24:40 -07001692 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001693 * Called to resolve an imt conflict.
1694 * eax is the conflict ArtMethod.
1695 * xmm7 is a hidden argument that holds the target interface method's dex method index.
1696 *
1697 * Note that this stub writes to eax.
1698 * Because of lack of free registers, it also saves and restores edi.
Jeff Hao88474b42013-10-23 16:24:40 -07001699 */
1700DEFINE_FUNCTION art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001701 PUSH EDI
1702 movl 8(%esp), %edi // Load referrer
1703 movl ART_METHOD_DEX_CACHE_METHODS_OFFSET_32(%edi), %edi // Load dex cache methods array
1704 pushl ART_METHOD_JNI_OFFSET_32(%eax) // Push ImtConflictTable.
1705 CFI_ADJUST_CFA_OFFSET(4)
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001706 movd %xmm7, %eax // get target method index stored in xmm7
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001707 movl 0(%edi, %eax, __SIZEOF_POINTER__), %edi // Load interface method
1708 popl %eax // Pop ImtConflictTable.
1709 CFI_ADJUST_CFA_OFFSET(-4)
1710.Limt_table_iterate:
1711 cmpl %edi, 0(%eax)
1712 jne .Limt_table_next_entry
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001713 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001714 // and jump to it.
1715 POP EDI
1716 movl __SIZEOF_POINTER__(%eax), %eax
1717 jmp *ART_METHOD_QUICK_CODE_OFFSET_32(%eax)
1718.Limt_table_next_entry:
1719 // If the entry is null, the interface method is not in the ImtConflictTable.
1720 cmpl LITERAL(0), 0(%eax)
1721 jz .Lconflict_trampoline
1722 // Iterate over the entries of the ImtConflictTable.
1723 addl LITERAL(2 * __SIZEOF_POINTER__), %eax
1724 jmp .Limt_table_iterate
1725.Lconflict_trampoline:
1726 // Call the runtime stub to populate the ImtConflictTable and jump to the
1727 // resolved method.
1728 POP EDI
Andreas Gampe55978b82015-07-14 17:57:43 -07001729 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001730END_FUNCTION art_quick_imt_conflict_trampoline
1731
Ian Rogers468532e2013-08-05 10:56:33 -07001732DEFINE_FUNCTION art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001733 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx
Tong Shen35e1e6a2014-07-30 09:31:22 -07001734 movl %esp, %edi
1735 PUSH EDI // pass SP. do not just PUSH ESP; that messes up unwinding
Ian Rogers468532e2013-08-05 10:56:33 -07001736 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001737 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers468532e2013-08-05 10:56:33 -07001738 PUSH ecx // pass receiver
1739 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001740 call SYMBOL(artQuickResolutionTrampoline) // (Method* called, receiver, Thread*, SP)
Ian Rogers468532e2013-08-05 10:56:33 -07001741 movl %eax, %edi // remember code pointer in EDI
1742 addl LITERAL(16), %esp // pop arguments
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001743 CFI_ADJUST_CFA_OFFSET(-16)
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001744 test %eax, %eax // if code pointer is null goto deliver pending exception
Ian Rogers468532e2013-08-05 10:56:33 -07001745 jz 1f
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001746 RESTORE_SAVE_REFS_AND_ARGS_FRAME_AND_JUMP
Ian Rogers468532e2013-08-05 10:56:33 -070017471:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001748 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001749 DELIVER_PENDING_EXCEPTION
1750END_FUNCTION art_quick_resolution_trampoline
1751
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001752DEFINE_FUNCTION art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001753 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_EAX
Andreas Gampe4360be22015-07-14 23:34:44 -07001754 movl %esp, %ebp // save SP at callee-save frame
Andreas Gampec200a4a2014-06-16 18:39:09 -07001755 CFI_DEF_CFA_REGISTER(ebp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001756 subl LITERAL(5120), %esp
1757 // prepare for artQuickGenericJniTrampoline call
1758 // (Thread*, SP)
1759 // (esp) 4(esp) <= C calling convention
1760 // fs:... ebp <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001761
1762 subl LITERAL(8), %esp // Padding for 16B alignment.
1763 pushl %ebp // Pass SP (to ArtMethod).
1764 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001765 call SYMBOL(artQuickGenericJniTrampoline) // (Thread*, sp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001766
Andreas Gampec200a4a2014-06-16 18:39:09 -07001767 // The C call will have registered the complete save-frame on success.
1768 // The result of the call is:
1769 // eax: pointer to native code, 0 on error.
1770 // edx: pointer to the bottom of the used area of the alloca, can restore stack till there.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001771
Andreas Gampec200a4a2014-06-16 18:39:09 -07001772 // Check for error = 0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001773 test %eax, %eax
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001774 jz .Lexception_in_native
Andreas Gampe779f8c92014-06-09 18:29:38 -07001775
Andreas Gampec200a4a2014-06-16 18:39:09 -07001776 // Release part of the alloca.
1777 movl %edx, %esp
Andreas Gampe779f8c92014-06-09 18:29:38 -07001778
1779 // On x86 there are no registers passed, so nothing to pop here.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001780 // Native call.
1781 call *%eax
1782
Andreas Gampe779f8c92014-06-09 18:29:38 -07001783 // result sign extension is handled in C code
1784 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001785 // (Thread*, result, result_f)
1786 // (esp) 4(esp) 12(esp) <= C calling convention
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001787 // fs:... eax:edx fp0 <= where they are
Andreas Gampe779f8c92014-06-09 18:29:38 -07001788
Andreas Gampe4360be22015-07-14 23:34:44 -07001789 subl LITERAL(20), %esp // Padding & pass float result.
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001790 fstpl (%esp)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001791 pushl %edx // Pass int result.
1792 pushl %eax
Andreas Gampe779f8c92014-06-09 18:29:38 -07001793 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Andreas Gampe29b38412014-08-13 00:15:43 -07001794 call SYMBOL(artQuickGenericJniEndTrampoline)
Andreas Gampe779f8c92014-06-09 18:29:38 -07001795
Andreas Gampe779f8c92014-06-09 18:29:38 -07001796 // Pending exceptions possible.
1797 mov %fs:THREAD_EXCEPTION_OFFSET, %ebx
1798 testl %ebx, %ebx
1799 jnz .Lexception_in_native
1800
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001801 // Tear down the alloca.
1802 movl %ebp, %esp
1803 CFI_DEF_CFA_REGISTER(esp)
1804
1805
Andreas Gampe779f8c92014-06-09 18:29:38 -07001806 // Tear down the callee-save frame.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001807 // Remove space for FPR args and EAX
1808 addl LITERAL(4 + 4 * 8), %esp
1809 CFI_ADJUST_CFA_OFFSET(-(4 + 4 * 8))
1810
Andreas Gampe779f8c92014-06-09 18:29:38 -07001811 POP ecx
Andreas Gampe4360be22015-07-14 23:34:44 -07001812 addl LITERAL(4), %esp // Avoid edx, as it may be part of the result.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001813 CFI_ADJUST_CFA_OFFSET(-4)
1814 POP ebx
1815 POP ebp // Restore callee saves
1816 POP esi
1817 POP edi
Nicolas Geoffray54accbc2014-08-13 03:40:45 +01001818 // Quick expects the return value to be in xmm0.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001819 movd %eax, %xmm0
1820 movd %edx, %xmm1
1821 punpckldq %xmm1, %xmm0
1822 ret
Andreas Gampe779f8c92014-06-09 18:29:38 -07001823.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001824 movl %fs:THREAD_TOP_QUICK_FRAME_OFFSET, %esp
1825 // Do a call to push a new save-all frame required by the runtime.
1826 call .Lexception_call
1827.Lexception_call:
Andreas Gampe779f8c92014-06-09 18:29:38 -07001828 DELIVER_PENDING_EXCEPTION
Andreas Gampe2da88232014-02-27 12:26:20 -08001829END_FUNCTION art_quick_generic_jni_trampoline
1830
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001831DEFINE_FUNCTION art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001832 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, ebx // save frame
Ian Rogersaeeada42013-02-13 11:28:34 -08001833 mov %esp, %edx // remember SP
1834 PUSH eax // alignment padding
1835 PUSH edx // pass SP
Ian Rogers7db619b2013-01-16 18:35:48 -08001836 pushl %fs:THREAD_SELF_OFFSET // pass Thread::Current()
Mark Mendell3f2d0312014-01-20 17:20:27 -08001837 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogersaeeada42013-02-13 11:28:34 -08001838 PUSH eax // pass method
Andreas Gampe29b38412014-08-13 00:15:43 -07001839 call SYMBOL(artQuickToInterpreterBridge) // (method, Thread*, SP)
Vladimir Marko949c91f2015-01-27 10:48:44 +00001840 addl LITERAL(16), %esp // pop arguments
1841 CFI_ADJUST_CFA_OFFSET(-16)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001842
1843 // Return eax:edx in xmm0 also.
1844 movd %eax, %xmm0
1845 movd %edx, %xmm1
1846 punpckldq %xmm1, %xmm0
1847
1848 addl LITERAL(48), %esp // Remove FPRs and EAX, ECX, EDX, EBX.
1849 CFI_ADJUST_CFA_OFFSET(-48)
1850
Andreas Gampe4360be22015-07-14 23:34:44 -07001851 POP ebp // Restore callee saves
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001852 POP esi
1853 POP edi
1854
Ian Rogers7db619b2013-01-16 18:35:48 -08001855 RETURN_OR_DELIVER_PENDING_EXCEPTION // return or deliver exception
Ian Rogers468532e2013-08-05 10:56:33 -07001856END_FUNCTION art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001857
jeffhao7e4fcb82013-01-10 18:11:08 -08001858 /*
1859 * Routine that intercepts method calls and returns.
1860 */
Ian Rogers468532e2013-08-05 10:56:33 -07001861DEFINE_FUNCTION art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001862 SETUP_SAVE_REFS_AND_ARGS_FRAME ebx, edx
Ian Rogers62d6c772013-02-27 08:32:07 -08001863 PUSH eax // Save eax which will be clobbered by the callee-save method.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001864 subl LITERAL(12), %esp // Align stack.
1865 CFI_ADJUST_CFA_OFFSET(12)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001866 pushl FRAME_SIZE_SAVE_REFS_AND_ARGS-4+16(%esp) // Pass LR.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001867 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001868 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001869 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001870 PUSH ecx // Pass receiver.
1871 PUSH eax // Pass Method*.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001872 call SYMBOL(artInstrumentationMethodEntryFromCode) // (Method*, Object*, Thread*, LR)
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001873 addl LITERAL(28), %esp // Pop arguments upto saved Method*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001874 CFI_ADJUST_CFA_OFFSET(-28)
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001875 movl 60(%esp), %edi // Restore edi.
1876 movl %eax, 60(%esp) // Place code* over edi, just under return pc.
Elliott Hughes7ac7e322014-06-27 17:20:59 -07001877 movl SYMBOL(art_quick_instrumentation_exit)@GOT(%ebx), %ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001878 // Place instrumentation exit as return pc. ebx holds the GOT computed on entry.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001879 movl %ebx, 64(%esp)
1880 movl 0(%esp), %eax // Restore eax.
1881 // Restore FPRs (extra 4 bytes of offset due to EAX push at top).
1882 movsd 8(%esp), %xmm0
1883 movsd 16(%esp), %xmm1
1884 movsd 24(%esp), %xmm2
1885 movsd 32(%esp), %xmm3
1886
1887 // Restore GPRs.
1888 movl 40(%esp), %ecx // Restore ecx.
Sebastien Hertzf551d1b2015-02-19 10:30:48 +01001889 movl 44(%esp), %edx // Restore edx.
Mark P Mendell966c3ae2015-01-27 15:45:27 +00001890 movl 48(%esp), %ebx // Restore ebx.
1891 movl 52(%esp), %ebp // Restore ebp.
1892 movl 56(%esp), %esi // Restore esi.
1893 addl LITERAL(60), %esp // Wind stack back upto code*.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001894 CFI_ADJUST_CFA_OFFSET(-60)
Ian Rogers62d6c772013-02-27 08:32:07 -08001895 ret // Call method (and pop).
Ian Rogers468532e2013-08-05 10:56:33 -07001896END_FUNCTION art_quick_instrumentation_entry
Ian Rogers62d6c772013-02-27 08:32:07 -08001897
Ian Rogers468532e2013-08-05 10:56:33 -07001898DEFINE_FUNCTION art_quick_instrumentation_exit
Ian Rogers62d6c772013-02-27 08:32:07 -08001899 pushl LITERAL(0) // Push a fake return PC as there will be none on the stack.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001900 CFI_ADJUST_CFA_OFFSET(4)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001901 SETUP_SAVE_REFS_ONLY_FRAME ebx, ebx
Ian Rogers62d6c772013-02-27 08:32:07 -08001902 mov %esp, %ecx // Remember SP
1903 subl LITERAL(8), %esp // Save float return value.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001904 CFI_ADJUST_CFA_OFFSET(8)
Andreas Gampefea29012014-07-23 10:05:02 -07001905 movq %xmm0, (%esp)
Ian Rogers62d6c772013-02-27 08:32:07 -08001906 PUSH edx // Save gpr return value.
1907 PUSH eax
Jeff Haocf2e7b02014-07-22 18:38:42 -07001908 subl LITERAL(16), %esp // Align stack
1909 CFI_ADJUST_CFA_OFFSET(16)
Andreas Gampefea29012014-07-23 10:05:02 -07001910 movq %xmm0, (%esp) // Pass float return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001911 PUSH edx // Pass gpr return value.
1912 PUSH eax
1913 PUSH ecx // Pass SP.
1914 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001915 CFI_ADJUST_CFA_OFFSET(4)
Andreas Gampe29b38412014-08-13 00:15:43 -07001916 call SYMBOL(artInstrumentationMethodExitFromCode) // (Thread*, SP, gpr_result, fpr_result)
Ian Rogers62d6c772013-02-27 08:32:07 -08001917 mov %eax, %ecx // Move returned link register.
1918 addl LITERAL(32), %esp // Pop arguments.
Mark Mendell3f2d0312014-01-20 17:20:27 -08001919 CFI_ADJUST_CFA_OFFSET(-32)
Ian Rogers62d6c772013-02-27 08:32:07 -08001920 movl %edx, %ebx // Move returned link register for deopt
1921 // (ebx is pretending to be our LR).
1922 POP eax // Restore gpr return value.
1923 POP edx
Andreas Gampefea29012014-07-23 10:05:02 -07001924 movq (%esp), %xmm0 // Restore fpr return value.
Ian Rogers62d6c772013-02-27 08:32:07 -08001925 addl LITERAL(8), %esp
Mark Mendell3f2d0312014-01-20 17:20:27 -08001926 CFI_ADJUST_CFA_OFFSET(-8)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001927 RESTORE_SAVE_REFS_ONLY_FRAME
Ian Rogers62d6c772013-02-27 08:32:07 -08001928 addl LITERAL(4), %esp // Remove fake return pc.
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001929 CFI_ADJUST_CFA_OFFSET(-4)
Ian Rogers62d6c772013-02-27 08:32:07 -08001930 jmp *%ecx // Return.
Ian Rogers468532e2013-08-05 10:56:33 -07001931END_FUNCTION art_quick_instrumentation_exit
jeffhao162fd332013-01-08 16:21:01 -08001932
jeffhao7e4fcb82013-01-10 18:11:08 -08001933 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001934 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1935 * will long jump to the upcall with a special exception of -1.
jeffhao7e4fcb82013-01-10 18:11:08 -08001936 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001937DEFINE_FUNCTION art_quick_deoptimize
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07001938 PUSH ebx // Entry point for a jump. Fake that we were called.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001939 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME ebx, ebx
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001940 subl LITERAL(12), %esp // Align stack.
1941 CFI_ADJUST_CFA_OFFSET(12)
Ian Rogers62d6c772013-02-27 08:32:07 -08001942 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
Mark Mendell3f2d0312014-01-20 17:20:27 -08001943 CFI_ADJUST_CFA_OFFSET(4)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001944 call SYMBOL(artDeoptimize) // artDeoptimize(Thread*)
Andreas Gampe4360be22015-07-14 23:34:44 -07001945 UNREACHABLE
Ian Rogersaeeada42013-02-13 11:28:34 -08001946END_FUNCTION art_quick_deoptimize
jeffhao162fd332013-01-08 16:21:01 -08001947
jeffhao86e46712012-08-08 17:30:59 -07001948 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00001949 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
Andreas Gampe639bdd12015-06-03 11:22:45 -07001950 * will long jump to the interpreter bridge.
Sebastien Hertz07474662015-08-25 15:12:33 +00001951 */
1952DEFINE_FUNCTION art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01001953 SETUP_SAVE_EVERYTHING_FRAME ebx, ebx
Sebastien Hertz07474662015-08-25 15:12:33 +00001954 subl LITERAL(12), %esp // Align stack.
1955 CFI_ADJUST_CFA_OFFSET(12)
1956 pushl %fs:THREAD_SELF_OFFSET // Pass Thread::Current().
1957 CFI_ADJUST_CFA_OFFSET(4)
1958 call SYMBOL(artDeoptimizeFromCompiledCode) // artDeoptimizeFromCompiledCode(Thread*)
1959 UNREACHABLE
1960END_FUNCTION art_quick_deoptimize_from_compiled_code
1961
1962 /*
jeffhao86e46712012-08-08 17:30:59 -07001963 * String's compareTo.
1964 *
1965 * On entry:
1966 * eax: this string object (known non-null)
1967 * ecx: comp string object (known non-null)
1968 */
Logan Chien8dbb7082013-01-25 20:31:17 +08001969DEFINE_FUNCTION art_quick_string_compareto
Andreas Gampe4360be22015-07-14 23:34:44 -07001970 PUSH esi // push callee save reg
1971 PUSH edi // push callee save reg
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001972 mov MIRROR_STRING_COUNT_OFFSET(%eax), %edx
1973 mov MIRROR_STRING_COUNT_OFFSET(%ecx), %ebx
Jeff Hao848f70a2014-01-15 13:49:50 -08001974 lea MIRROR_STRING_VALUE_OFFSET(%eax), %esi
1975 lea MIRROR_STRING_VALUE_OFFSET(%ecx), %edi
jeffhao86e46712012-08-08 17:30:59 -07001976 /* Calculate min length and count diff */
1977 mov %edx, %ecx
1978 mov %edx, %eax
1979 subl %ebx, %eax
1980 cmovg %ebx, %ecx
1981 /*
1982 * At this point we have:
1983 * eax: value to return if first part of strings are equal
1984 * ecx: minimum among the lengths of the two strings
1985 * esi: pointer to this string data
1986 * edi: pointer to comp string data
1987 */
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001988 jecxz .Lkeep_length
jeffhao86e46712012-08-08 17:30:59 -07001989 repe cmpsw // find nonmatching chars in [%esi] and [%edi], up to length %ecx
Ian Rogers8016a122014-02-21 20:37:21 -08001990 jne .Lnot_equal
Alexei Zavjalov4554bfd2014-02-26 17:28:35 +07001991.Lkeep_length:
Ian Rogersaeeada42013-02-13 11:28:34 -08001992 POP edi // pop callee save reg
1993 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07001994 ret
1995 .balign 16
Ian Rogers8016a122014-02-21 20:37:21 -08001996.Lnot_equal:
Ian Rogers1b09b092012-08-20 15:35:52 -07001997 movzwl -2(%esi), %eax // get last compared char from this string
1998 movzwl -2(%edi), %ecx // get last compared char from comp string
jeffhao86e46712012-08-08 17:30:59 -07001999 subl %ecx, %eax // return the difference
Ian Rogersaeeada42013-02-13 11:28:34 -08002000 POP edi // pop callee save reg
2001 POP esi // pop callee save reg
jeffhao86e46712012-08-08 17:30:59 -07002002 ret
Ian Rogersaeeada42013-02-13 11:28:34 -08002003END_FUNCTION art_quick_string_compareto
jeffhao86e46712012-08-08 17:30:59 -07002004
Dave Allison8ce6b902014-08-26 11:07:58 -07002005// Return from a nested signal:
2006// Entry:
2007// eax: address of jmp_buf in TLS
2008
2009DEFINE_FUNCTION art_nested_signal_return
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002010 SETUP_GOT_NOSAVE ebx // sets %ebx for call into PLT
Dave Allison8ce6b902014-08-26 11:07:58 -07002011 movl LITERAL(1), %ecx
Christopher Ferris9f5e1d92015-07-13 12:21:00 -07002012 PUSH ecx // second arg to longjmp (1)
2013 PUSH eax // first arg to longjmp (jmp_buf)
Dave Allison8ce6b902014-08-26 11:07:58 -07002014 call PLT_SYMBOL(longjmp)
Andreas Gampe4360be22015-07-14 23:34:44 -07002015 UNREACHABLE
Dave Allison8ce6b902014-08-26 11:07:58 -07002016END_FUNCTION art_nested_signal_return
2017
Roland Levillain02b75802016-07-13 11:54:35 +01002018// Create a function `name` calling the ReadBarrier::Mark routine,
2019// getting its argument and returning its result through register
Roland Levillain4359e612016-07-20 11:32:19 +01002020// `reg`, saving and restoring all caller-save registers.
2021//
2022// If `reg` is different from `eax`, the generated function follows a
2023// non-standard runtime calling convention:
2024// - register `reg` is used to pass the (sole) argument of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002025// (instead of EAX);
Roland Levillain4359e612016-07-20 11:32:19 +01002026// - register `reg` is used to return the result of this function
2027// (instead of EAX);
Roland Levillain02b75802016-07-13 11:54:35 +01002028// - EAX is treated like a normal (non-argument) caller-save register;
2029// - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002030// convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002031MACRO2(READ_BARRIER_MARK_REG, name, reg)
2032 DEFINE_FUNCTION VAR(name)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002033 // Null check so that we can load the lock word.
2034 test REG_VAR(reg), REG_VAR(reg)
2035 jz .Lret_rb_\name
2036 // Check the mark bit, if it is 1 return.
2037 testl LITERAL(LOCK_WORD_MARK_BIT_MASK_SHIFTED), MIRROR_OBJECT_LOCK_WORD_OFFSET(REG_VAR(reg))
2038 jz .Lslow_rb_\name
2039 ret
2040.Lslow_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002041 // Save all potentially live caller-save core registers.
2042 PUSH eax
2043 PUSH ecx
2044 PUSH edx
2045 PUSH ebx
2046 // 8-byte align the stack to improve (8-byte) XMM register saving and restoring.
2047 // and create space for caller-save floating-point registers.
2048 subl MACRO_LITERAL(4 + 8 * 8), %esp
2049 CFI_ADJUST_CFA_OFFSET(4 + 8 * 8)
2050 // Save all potentially live caller-save floating-point registers.
2051 movsd %xmm0, 0(%esp)
2052 movsd %xmm1, 8(%esp)
2053 movsd %xmm2, 16(%esp)
2054 movsd %xmm3, 24(%esp)
2055 movsd %xmm4, 32(%esp)
2056 movsd %xmm5, 40(%esp)
2057 movsd %xmm6, 48(%esp)
2058 movsd %xmm7, 56(%esp)
2059
2060 subl LITERAL(4), %esp // alignment padding
2061 CFI_ADJUST_CFA_OFFSET(4)
Roland Levillain02b75802016-07-13 11:54:35 +01002062 PUSH RAW_VAR(reg) // pass arg1 - obj from `reg`
2063 call SYMBOL(artReadBarrierMark) // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002064 .ifnc RAW_VAR(reg), eax
2065 movl %eax, REG_VAR(reg) // return result into `reg`
2066 .endif
2067 addl LITERAL(8), %esp // pop argument and remove padding
2068 CFI_ADJUST_CFA_OFFSET(-8)
2069
2070 // Restore floating-point registers.
2071 movsd 0(%esp), %xmm0
2072 movsd 8(%esp), %xmm1
2073 movsd 16(%esp), %xmm2
2074 movsd 24(%esp), %xmm3
2075 movsd 32(%esp), %xmm4
2076 movsd 40(%esp), %xmm5
2077 movsd 48(%esp), %xmm6
2078 movsd 56(%esp), %xmm7
2079 // Remove floating-point registers and padding.
2080 addl MACRO_LITERAL(8 * 8 + 4), %esp
2081 CFI_ADJUST_CFA_OFFSET(-(8 * 8 + 4))
2082 // Restore core regs, except `reg`, as it is used to return the
2083 // result of this function (simply remove it from the stack instead).
2084 POP_REG_NE ebx, RAW_VAR(reg)
2085 POP_REG_NE edx, RAW_VAR(reg)
2086 POP_REG_NE ecx, RAW_VAR(reg)
2087 POP_REG_NE eax, RAW_VAR(reg)
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002088.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002089 ret
2090 END_FUNCTION VAR(name)
2091END_MACRO
2092
Roland Levillain4359e612016-07-20 11:32:19 +01002093READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, eax
Roland Levillain02b75802016-07-13 11:54:35 +01002094READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, ecx
2095READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, edx
2096READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, ebx
2097READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, ebp
2098// Note: There is no art_quick_read_barrier_mark_reg04, as register 4 (ESP)
2099// cannot be used to pass arguments.
2100READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, esi
2101READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, edi
Roland Levillain7c1559a2015-12-15 10:55:36 +00002102
Man Cao1aee9002015-07-14 22:31:42 -07002103DEFINE_FUNCTION art_quick_read_barrier_slow
Roland Levillain0d5a2812015-11-13 10:07:31 +00002104 PUSH edx // pass arg3 - offset
2105 PUSH ecx // pass arg2 - obj
2106 PUSH eax // pass arg1 - ref
2107 call SYMBOL(artReadBarrierSlow) // artReadBarrierSlow(ref, obj, offset)
2108 addl LITERAL(12), %esp // pop arguments
Man Cao1aee9002015-07-14 22:31:42 -07002109 CFI_ADJUST_CFA_OFFSET(-12)
2110 ret
2111END_FUNCTION art_quick_read_barrier_slow
2112
Roland Levillain0d5a2812015-11-13 10:07:31 +00002113DEFINE_FUNCTION art_quick_read_barrier_for_root_slow
Roland Levillaina7821bf2016-06-30 16:21:31 +01002114 subl LITERAL(8), %esp // alignment padding
2115 CFI_ADJUST_CFA_OFFSET(8)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002116 PUSH eax // pass arg1 - root
2117 call SYMBOL(artReadBarrierForRootSlow) // artReadBarrierForRootSlow(root)
Roland Levillaina7821bf2016-06-30 16:21:31 +01002118 addl LITERAL(12), %esp // pop argument and remove padding
2119 CFI_ADJUST_CFA_OFFSET(-12)
Roland Levillain0d5a2812015-11-13 10:07:31 +00002120 ret
2121END_FUNCTION art_quick_read_barrier_for_root_slow
2122
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00002123 /*
2124 * On stack replacement stub.
2125 * On entry:
2126 * [sp] = return address
2127 * [sp + 4] = stack to copy
2128 * [sp + 8] = size of stack
2129 * [sp + 12] = pc to call
2130 * [sp + 16] = JValue* result
2131 * [sp + 20] = shorty
2132 * [sp + 24] = thread
2133 */
2134DEFINE_FUNCTION art_quick_osr_stub
2135 // Save native callee saves.
2136 PUSH ebp
2137 PUSH ebx
2138 PUSH esi
2139 PUSH edi
2140 mov 4+16(%esp), %esi // ESI = argument array
2141 mov 8+16(%esp), %ecx // ECX = size of args
2142 mov 12+16(%esp), %ebx // EBX = pc to call
2143 mov %esp, %ebp // Save stack pointer
2144 andl LITERAL(0xFFFFFFF0), %esp // Align stack
2145 PUSH ebp // Save old stack pointer
2146 subl LITERAL(12), %esp // Align stack
2147 movl LITERAL(0), (%esp) // Store null for ArtMethod* slot
2148 call .Losr_entry
2149
2150 // Restore stack pointer.
2151 addl LITERAL(12), %esp
2152 POP ebp
2153 mov %ebp, %esp
2154
2155 // Restore callee saves.
2156 POP edi
2157 POP esi
2158 POP ebx
2159 POP ebp
2160 mov 16(%esp), %ecx // Get JValue result
2161 mov %eax, (%ecx) // Store the result assuming it is a long, int or Object*
2162 mov %edx, 4(%ecx) // Store the other half of the result
2163 mov 20(%esp), %edx // Get the shorty
2164 cmpb LITERAL(68), (%edx) // Test if result type char == 'D'
2165 je .Losr_return_double_quick
2166 cmpb LITERAL(70), (%edx) // Test if result type char == 'F'
2167 je .Losr_return_float_quick
2168 ret
2169.Losr_return_double_quick:
2170 movsd %xmm0, (%ecx) // Store the floating point result
2171 ret
2172.Losr_return_float_quick:
2173 movss %xmm0, (%ecx) // Store the floating point result
2174 ret
2175.Losr_entry:
2176 subl LITERAL(4), %ecx // Given stack size contains pushed frame pointer, substract it.
2177 subl %ecx, %esp
2178 mov %esp, %edi // EDI = beginning of stack
2179 rep movsb // while (ecx--) { *edi++ = *esi++ }
2180 jmp *%ebx
2181END_FUNCTION art_quick_osr_stub
2182
Elliott Hughes787ec202012-03-29 17:14:15 -07002183 // TODO: implement these!
Logan Chien8dbb7082013-01-25 20:31:17 +08002184UNIMPLEMENTED art_quick_memcmp16