blob: 44159354ab93daf40bf796c2a3da9d1a46e533ab [file] [log] [blame]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001/*
2 * Copyright (C) 2014 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
17#include "asm_support_arm64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21
22 /*
23 * Macro that sets up the callee save frame to conform with
24 * Runtime::CreateCalleeSaveMethod(kSaveAll)
25 */
26.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080027 adrp xIP0, :got:_ZN3art7Runtime9instance_E
28 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000029
30 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +080031 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +000032
Zheng Xub551fdc2014-07-25 11:49:42 +080033 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -070034 THIS_LOAD_REQUIRES_READ_BARRIER
Zheng Xub551fdc2014-07-25 11:49:42 +080035 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070036
37 sub sp, sp, #176
38 .cfi_adjust_cfa_offset 176
39
40 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +080041#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176)
42#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043#endif
44
45 // FP callee-saves
46 stp d8, d9, [sp, #8]
47 stp d10, d11, [sp, #24]
48 stp d12, d13, [sp, #40]
49 stp d14, d15, [sp, #56]
50
Zheng Xub551fdc2014-07-25 11:49:42 +080051 // Reserved registers
52 stp xSELF, xSUSPEND, [sp, #72]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070053 .cfi_rel_offset x18, 72
54 .cfi_rel_offset x19, 80
55
Zheng Xub551fdc2014-07-25 11:49:42 +080056 // callee-saves
Andreas Gampe5c1e4352014-04-21 19:28:24 -070057 stp x20, x21, [sp, #88]
58 .cfi_rel_offset x20, 88
59 .cfi_rel_offset x21, 96
60
61 stp x22, x23, [sp, #104]
62 .cfi_rel_offset x22, 104
63 .cfi_rel_offset x23, 112
64
65 stp x24, x25, [sp, #120]
66 .cfi_rel_offset x24, 120
67 .cfi_rel_offset x25, 128
68
69 stp x26, x27, [sp, #136]
70 .cfi_rel_offset x26, 136
71 .cfi_rel_offset x27, 144
72
Zheng Xub551fdc2014-07-25 11:49:42 +080073 stp x28, x29, [sp, #152]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070074 .cfi_rel_offset x28, 152
75 .cfi_rel_offset x29, 160
76
77 str xLR, [sp, #168]
78 .cfi_rel_offset x30, 168
79
80 // Loads appropriate callee-save-method
Zheng Xub551fdc2014-07-25 11:49:42 +080081 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070082 // Place sp in Thread::Current()->top_quick_frame.
83 mov xIP0, sp
84 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +000085.endm
86
Zheng Xub551fdc2014-07-25 11:49:42 +080087 /*
88 * Macro that sets up the callee save frame to conform with
89 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
90 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070091.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080092 adrp xIP0, :got:_ZN3art7Runtime9instance_E
93 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
94
95 // Our registers aren't intermixed - just spill in order.
96 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
97
98 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
99 THIS_LOAD_REQUIRES_READ_BARRIER
100 ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
101
102 sub sp, sp, #96
103 .cfi_adjust_cfa_offset 96
104
105 // Ugly compile-time check, but we only have the preprocessor.
106#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96)
107#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
108#endif
109
110 // Callee-saves
111 stp x20, x21, [sp, #8]
112 .cfi_rel_offset x20, 8
113 .cfi_rel_offset x21, 16
114
115 stp x22, x23, [sp, #24]
116 .cfi_rel_offset x22, 24
117 .cfi_rel_offset x23, 32
118
119 stp x24, x25, [sp, #40]
120 .cfi_rel_offset x24, 40
121 .cfi_rel_offset x25, 48
122
123 stp x26, x27, [sp, #56]
124 .cfi_rel_offset x26, 56
125 .cfi_rel_offset x27, 64
126
127 stp x28, x29, [sp, #72]
128 .cfi_rel_offset x28, 72
129 .cfi_rel_offset x29, 80
130
131 // LR
132 str xLR, [sp, #88]
133 .cfi_rel_offset x30, 88
134
135 // Save xSELF to xETR.
136 mov xETR, xSELF
137
138 // Loads appropriate callee-save-method
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700139 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly]
140 // Place sp in Thread::Current()->top_quick_frame.
141 mov xIP0, sp
142 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800143.endm
144
145// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700146.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800147 // Restore xSELF.
148 mov xSELF, xETR
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700149
Zheng Xub551fdc2014-07-25 11:49:42 +0800150 // Callee-saves
151 ldp x20, x21, [sp, #8]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700152 .cfi_restore x20
153 .cfi_restore x21
154
Zheng Xub551fdc2014-07-25 11:49:42 +0800155 ldp x22, x23, [sp, #24]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700156 .cfi_restore x22
157 .cfi_restore x23
158
Zheng Xub551fdc2014-07-25 11:49:42 +0800159 ldp x24, x25, [sp, #40]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700160 .cfi_restore x24
161 .cfi_restore x25
162
Zheng Xub551fdc2014-07-25 11:49:42 +0800163 ldp x26, x27, [sp, #56]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700164 .cfi_restore x26
165 .cfi_restore x27
166
Zheng Xub551fdc2014-07-25 11:49:42 +0800167 ldp x28, x29, [sp, #72]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700168 .cfi_restore x28
169 .cfi_restore x29
170
Zheng Xub551fdc2014-07-25 11:49:42 +0800171 // LR
172 ldr xLR, [sp, #88]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700173 .cfi_restore x30
174
Zheng Xub551fdc2014-07-25 11:49:42 +0800175 add sp, sp, #96
176 .cfi_adjust_cfa_offset -96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000177.endm
178
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700179.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800180 // Restore xSELF as it might be scratched.
181 mov xSELF, xETR
182 // ETR
183 ldr xETR, [sp, #16]
184 .cfi_restore x21
185
186 add sp, sp, #96
187 .cfi_adjust_cfa_offset -96
Andreas Gamped58342c2014-06-05 14:18:08 -0700188.endm
189
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700190.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
191 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800192 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000193.endm
194
195
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700196.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800197 sub sp, sp, #224
198 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000199
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700200 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +0800201#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700202#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
203#endif
204
Zheng Xub551fdc2014-07-25 11:49:42 +0800205 // FP args
206 stp d0, d1, [sp, #16]
207 stp d2, d3, [sp, #32]
208 stp d4, d5, [sp, #48]
209 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000210
Zheng Xub551fdc2014-07-25 11:49:42 +0800211 // args and x20(callee-save)
212 stp x1, x2, [sp, #80]
213 .cfi_rel_offset x1, 80
214 .cfi_rel_offset x2, 88
Stuart Monteithb95a5342014-03-12 13:32:32 +0000215
Zheng Xub551fdc2014-07-25 11:49:42 +0800216 stp x3, x4, [sp, #96]
217 .cfi_rel_offset x3, 96
218 .cfi_rel_offset x4, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700219
Zheng Xub551fdc2014-07-25 11:49:42 +0800220 stp x5, x6, [sp, #112]
221 .cfi_rel_offset x5, 112
222 .cfi_rel_offset x6, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700223
Zheng Xub551fdc2014-07-25 11:49:42 +0800224 stp x7, x20, [sp, #128]
225 .cfi_rel_offset x7, 128
226 .cfi_rel_offset x20, 136
Andreas Gampe03906cf2014-04-07 12:08:28 -0700227
Zheng Xub551fdc2014-07-25 11:49:42 +0800228 // Callee-saves.
229 stp x21, x22, [sp, #144]
230 .cfi_rel_offset x21, 144
231 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700232
Zheng Xub551fdc2014-07-25 11:49:42 +0800233 stp x23, x24, [sp, #160]
234 .cfi_rel_offset x23, 160
235 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700236
Zheng Xub551fdc2014-07-25 11:49:42 +0800237 stp x25, x26, [sp, #176]
238 .cfi_rel_offset x25, 176
239 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700240
Zheng Xub551fdc2014-07-25 11:49:42 +0800241 stp x27, x28, [sp, #192]
242 .cfi_rel_offset x27, 192
243 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700244
Zheng Xub551fdc2014-07-25 11:49:42 +0800245 // x29(callee-save) and LR
246 stp x29, xLR, [sp, #208]
247 .cfi_rel_offset x29, 208
248 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700249
Zheng Xub551fdc2014-07-25 11:49:42 +0800250 // Save xSELF to xETR.
251 mov xETR, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000252.endm
253
254 /*
255 * Macro that sets up the callee save frame to conform with
256 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
257 *
258 * TODO This is probably too conservative - saving FP & LR.
259 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700260.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800261 adrp xIP0, :got:_ZN3art7Runtime9instance_E
262 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000263
264 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +0800265 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +0000266
Zheng Xub551fdc2014-07-25 11:49:42 +0800267 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -0700268 THIS_LOAD_REQUIRES_READ_BARRIER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700269 ldr xIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000270
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700271 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000272
Zheng Xub551fdc2014-07-25 11:49:42 +0800273 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700274 // Place sp in Thread::Current()->top_quick_frame.
275 mov xIP0, sp
276 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
277.endm
278
279.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
280 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
281 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
282 // Place sp in Thread::Current()->top_quick_frame.
283 mov xIP0, sp
284 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000285.endm
286
Zheng Xub551fdc2014-07-25 11:49:42 +0800287// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700288.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800289 // Restore xSELF.
290 mov xSELF, xETR
Stuart Monteithb95a5342014-03-12 13:32:32 +0000291
Zheng Xub551fdc2014-07-25 11:49:42 +0800292 // FP args
293 ldp d0, d1, [sp, #16]
294 ldp d2, d3, [sp, #32]
295 ldp d4, d5, [sp, #48]
296 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000297
Zheng Xub551fdc2014-07-25 11:49:42 +0800298 // args and x20(callee-save)
299 ldp x1, x2, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700300 .cfi_restore x1
301 .cfi_restore x2
302
Zheng Xub551fdc2014-07-25 11:49:42 +0800303 ldp x3, x4, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700304 .cfi_restore x3
305 .cfi_restore x4
306
Zheng Xub551fdc2014-07-25 11:49:42 +0800307 ldp x5, x6, [sp, #112]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700308 .cfi_restore x5
309 .cfi_restore x6
310
Zheng Xub551fdc2014-07-25 11:49:42 +0800311 ldp x7, x20, [sp, #128]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700312 .cfi_restore x7
Andreas Gampe03906cf2014-04-07 12:08:28 -0700313 .cfi_restore x20
314
Zheng Xub551fdc2014-07-25 11:49:42 +0800315 // Callee-saves.
316 ldp x21, x22, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700317 .cfi_restore x21
318 .cfi_restore x22
319
Zheng Xub551fdc2014-07-25 11:49:42 +0800320 ldp x23, x24, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700321 .cfi_restore x23
322 .cfi_restore x24
323
Zheng Xub551fdc2014-07-25 11:49:42 +0800324 ldp x25, x26, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700325 .cfi_restore x25
326 .cfi_restore x26
327
Zheng Xub551fdc2014-07-25 11:49:42 +0800328 ldp x27, x28, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700329 .cfi_restore x27
330 .cfi_restore x28
331
Zheng Xub551fdc2014-07-25 11:49:42 +0800332 // x29(callee-save) and LR
333 ldp x29, xLR, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700334 .cfi_restore x29
335 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000336
Zheng Xub551fdc2014-07-25 11:49:42 +0800337 add sp, sp, #224
338 .cfi_adjust_cfa_offset -224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000339.endm
340
341.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700342 cbnz x0, 1f // result non-zero branch over
343 ret // return
3441:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000345.endm
346
347.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700348 cbz x0, 1f // result zero branch over
349 ret // return
3501:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000351.endm
352
353 /*
354 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
355 * exception is Thread::Current()->exception_
356 */
357.macro DELIVER_PENDING_EXCEPTION
358 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
359 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000360
361 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700362 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000363 brk 0 // Unreached
364.endm
365
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700366.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
367 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
368 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000369 ret
3701:
371 DELIVER_PENDING_EXCEPTION
372.endm
373
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700374.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800375 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700376.endm
377
378// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
379.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
380 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
381.endm
382
383.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
384 cbnz w0, 1f // result non-zero branch over
385 ret // return
3861:
387 DELIVER_PENDING_EXCEPTION
388.endm
389
Stuart Monteithb95a5342014-03-12 13:32:32 +0000390.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
391 .extern \cxx_name
392ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700393 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800394 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700395 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000396END \c_name
397.endm
398
399.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
400 .extern \cxx_name
401ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100402 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800403 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700404 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000405 brk 0
406END \c_name
407.endm
408
409.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
410 .extern \cxx_name
411ENTRY \c_name
412 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800413 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700414 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000415 brk 0
416END \c_name
417.endm
418
419 /*
420 * Called by managed code, saves callee saves and then calls artThrowException
421 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
422 */
423ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
424
425 /*
426 * Called by managed code to create and deliver a NullPointerException.
427 */
428NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
429
430 /*
431 * Called by managed code to create and deliver an ArithmeticException.
432 */
433NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
434
435 /*
436 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
437 * index, arg2 holds limit.
438 */
439TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
440
441 /*
442 * Called by managed code to create and deliver a StackOverflowError.
443 */
444NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
445
446 /*
447 * Called by managed code to create and deliver a NoSuchMethodError.
448 */
449ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
450
451 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000452 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700453 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
454 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000455 * stack and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700456 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000457 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700458 * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting
Stuart Monteithb95a5342014-03-12 13:32:32 +0000459 * of the target Method* in x0 and method->code_ in x1.
460 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700461 * If unsuccessful, the helper will return NULL/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000462 * thread and we branch to another stub to deliver it.
463 *
464 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
465 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700466 *
467 * Adapted from ARM32 code.
468 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800469 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000470 */
471.macro INVOKE_TRAMPOLINE c_name, cxx_name
472 .extern \cxx_name
473ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700474 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700475 // Helper signature is always
476 // (method_idx, *this_object, *caller_method, *self, sp)
477
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700478 ldr w2, [sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE] // pass caller Method*
Andreas Gampe51f76352014-05-21 08:28:48 -0700479 mov x3, xSELF // pass Thread::Current
480 mov x4, sp
481 bl \cxx_name // (method_idx, this, caller, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800482 mov xIP0, x1 // save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700483 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700484 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800485 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07004861:
487 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +0000488END \c_name
489.endm
490
491INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
492INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
493
494INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
495INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
496INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
497INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
498
Andreas Gampe03906cf2014-04-07 12:08:28 -0700499
500.macro INVOKE_STUB_CREATE_FRAME
501
Zheng Xub551fdc2014-07-25 11:49:42 +0800502SAVE_SIZE=6*8 // x4, x5, xSUSPEND, SP, LR & FP saved.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700503SAVE_SIZE_AND_METHOD=SAVE_SIZE+STACK_REFERENCE_SIZE
504
Andreas Gampe03906cf2014-04-07 12:08:28 -0700505
Zheng Xu48241e72014-05-23 11:52:42 +0800506 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700507 .cfi_register sp,x9
508
Zheng Xu48241e72014-05-23 11:52:42 +0800509 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
510 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
511 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
512 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700513
Zheng Xu48241e72014-05-23 11:52:42 +0800514 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
515 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700516 .cfi_adjust_cfa_offset SAVE_SIZE
517
Zheng Xub551fdc2014-07-25 11:49:42 +0800518 stp x9, xSUSPEND, [x10, #32] // Save old stack pointer and xSUSPEND
Andreas Gampe03906cf2014-04-07 12:08:28 -0700519 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700520 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700521
Zheng Xu48241e72014-05-23 11:52:42 +0800522 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700523 .cfi_rel_offset x4, 16
524 .cfi_rel_offset x5, 24
525
Zheng Xu48241e72014-05-23 11:52:42 +0800526 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700527 .cfi_rel_offset x29, 0
528 .cfi_rel_offset x30, 8
529
Zheng Xu48241e72014-05-23 11:52:42 +0800530 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700531 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800532 mov xSELF, x3 // Move thread pointer into SELF register.
533 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to suspend check interval
Andreas Gampe03906cf2014-04-07 12:08:28 -0700534
535 // Copy arguments into stack frame.
536 // Use simple copy routine for now.
537 // 4 bytes per slot.
538 // X1 - source address
539 // W2 - args length
540 // X9 - destination address.
541 // W10 - temporary
Andreas Gampecf4035a2014-05-28 22:43:01 -0700542 add x9, sp, #4 // Destination address is bottom of stack + NULL.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700543
544 // Use \@ to differentiate between macro invocations.
545.LcopyParams\@:
546 cmp w2, #0
547 beq .LendCopyParams\@
548 sub w2, w2, #4 // Need 65536 bytes of range.
549 ldr w10, [x1, x2]
550 str w10, [x9, x2]
551
552 b .LcopyParams\@
553
554.LendCopyParams\@:
555
Andreas Gampecf4035a2014-05-28 22:43:01 -0700556 // Store NULL into StackReference<Method>* at bottom of frame.
557 str wzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700558
Andreas Gampecf4035a2014-05-28 22:43:01 -0700559#if (STACK_REFERENCE_SIZE != 4)
560#error "STACK_REFERENCE_SIZE(ARM64) size not as expected."
561#endif
Andreas Gampe03906cf2014-04-07 12:08:28 -0700562.endm
563
564.macro INVOKE_STUB_CALL_AND_RETURN
565
566 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartier2d721012014-11-10 11:08:06 -0800567 ldr x9, [x0 , #MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700568 // Branch to method.
569 blr x9
570
571 // Restore return value address and shorty address.
572 ldp x4,x5, [xFP, #16]
573 .cfi_restore x4
574 .cfi_restore x5
575
576 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
577 ldrb w10, [x5]
578
579 // Don't set anything for a void type.
580 cmp w10, #'V'
581 beq .Lexit_art_quick_invoke_stub\@
582
583 cmp w10, #'D'
584 bne .Lreturn_is_float\@
585 str d0, [x4]
586 b .Lexit_art_quick_invoke_stub\@
587
588.Lreturn_is_float\@:
589 cmp w10, #'F'
590 bne .Lreturn_is_int\@
591 str s0, [x4]
592 b .Lexit_art_quick_invoke_stub\@
593
594 // Just store x0. Doesn't matter if it is 64 or 32 bits.
595.Lreturn_is_int\@:
596 str x0, [x4]
597
598.Lexit_art_quick_invoke_stub\@:
Zheng Xub551fdc2014-07-25 11:49:42 +0800599 ldp x2, xSUSPEND, [xFP, #32] // Restore stack pointer and xSUSPEND.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700600 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700601 mov sp, x2
602 .cfi_restore sp
603
Andreas Gamped58342c2014-06-05 14:18:08 -0700604 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700605 .cfi_restore x29
606 .cfi_restore x30
607
608 ret
609
610.endm
611
612
Stuart Monteithb95a5342014-03-12 13:32:32 +0000613/*
614 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
615 * uint32_t *args, x1
616 * uint32_t argsize, w2
617 * Thread *self, x3
618 * JValue *result, x4
619 * char *shorty); x5
620 * +----------------------+
621 * | |
622 * | C/C++ frame |
623 * | LR'' |
624 * | FP'' | <- SP'
625 * +----------------------+
626 * +----------------------+
Zheng Xub551fdc2014-07-25 11:49:42 +0800627 * | x19 | <- Used as wSUSPEND, won't be restored by managed code.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000628 * | SP' |
629 * | X5 |
630 * | X4 | Saved registers
631 * | LR' |
632 * | FP' | <- FP
633 * +----------------------+
634 * | uint32_t out[n-1] |
635 * | : : | Outs
636 * | uint32_t out[0] |
Andreas Gampecf4035a2014-05-28 22:43:01 -0700637 * | StackRef<ArtMethod> | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000638 * +----------------------+
639 *
640 * Outgoing registers:
641 * x0 - Method*
642 * x1-x7 - integer parameters.
643 * d0-d7 - Floating point parameters.
644 * xSELF = self
Zheng Xu48241e72014-05-23 11:52:42 +0800645 * wSUSPEND = suspend count
Stuart Monteithb95a5342014-03-12 13:32:32 +0000646 * SP = & of ArtMethod*
647 * x1 = "this" pointer.
648 *
649 */
650ENTRY art_quick_invoke_stub
651 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700652 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000653
654 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
655 // Parse the passed shorty to determine which register to load.
656 // Load addresses for routines that load WXSD registers.
657 adr x11, .LstoreW2
658 adr x12, .LstoreX2
659 adr x13, .LstoreS0
660 adr x14, .LstoreD0
661
662 // Initialize routine offsets to 0 for integers and floats.
663 // x8 for integers, x15 for floating point.
664 mov x8, #0
665 mov x15, #0
666
667 add x10, x5, #1 // Load shorty address, plus one to skip return value.
668 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
669
670 // Loop to fill registers.
671.LfillRegisters:
672 ldrb w17, [x10], #1 // Load next character in signature, and increment.
673 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
674
675 cmp w17, #'F' // is this a float?
676 bne .LisDouble
677
678 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700679 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000680
681 add x17, x13, x15 // Calculate subroutine to jump to.
682 br x17
683
684.LisDouble:
685 cmp w17, #'D' // is this a double?
686 bne .LisLong
687
688 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700689 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000690
691 add x17, x14, x15 // Calculate subroutine to jump to.
692 br x17
693
694.LisLong:
695 cmp w17, #'J' // is this a long?
696 bne .LisOther
697
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700698 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700699 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000700
701 add x17, x12, x8 // Calculate subroutine to jump to.
702 br x17
703
Stuart Monteithb95a5342014-03-12 13:32:32 +0000704.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700705 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700706 beq .Ladvance4
707
Stuart Monteithb95a5342014-03-12 13:32:32 +0000708 add x17, x11, x8 // Calculate subroutine to jump to.
709 br x17
710
Andreas Gampe03906cf2014-04-07 12:08:28 -0700711.Ladvance4:
712 add x9, x9, #4
713 b .LfillRegisters
714
715.Ladvance8:
716 add x9, x9, #8
717 b .LfillRegisters
718
Stuart Monteithb95a5342014-03-12 13:32:32 +0000719// Macro for loading a parameter into a register.
720// counter - the register with offset into these tables
721// size - the size of the register - 4 or 8 bytes.
722// register - the name of the register to be loaded.
723.macro LOADREG counter size register return
724 ldr \register , [x9], #\size
725 add \counter, \counter, 12
726 b \return
727.endm
728
729// Store ints.
730.LstoreW2:
731 LOADREG x8 4 w2 .LfillRegisters
732 LOADREG x8 4 w3 .LfillRegisters
733 LOADREG x8 4 w4 .LfillRegisters
734 LOADREG x8 4 w5 .LfillRegisters
735 LOADREG x8 4 w6 .LfillRegisters
736 LOADREG x8 4 w7 .LfillRegisters
737
738// Store longs.
739.LstoreX2:
740 LOADREG x8 8 x2 .LfillRegisters
741 LOADREG x8 8 x3 .LfillRegisters
742 LOADREG x8 8 x4 .LfillRegisters
743 LOADREG x8 8 x5 .LfillRegisters
744 LOADREG x8 8 x6 .LfillRegisters
745 LOADREG x8 8 x7 .LfillRegisters
746
747// Store singles.
748.LstoreS0:
749 LOADREG x15 4 s0 .LfillRegisters
750 LOADREG x15 4 s1 .LfillRegisters
751 LOADREG x15 4 s2 .LfillRegisters
752 LOADREG x15 4 s3 .LfillRegisters
753 LOADREG x15 4 s4 .LfillRegisters
754 LOADREG x15 4 s5 .LfillRegisters
755 LOADREG x15 4 s6 .LfillRegisters
756 LOADREG x15 4 s7 .LfillRegisters
757
758// Store doubles.
759.LstoreD0:
760 LOADREG x15 8 d0 .LfillRegisters
761 LOADREG x15 8 d1 .LfillRegisters
762 LOADREG x15 8 d2 .LfillRegisters
763 LOADREG x15 8 d3 .LfillRegisters
764 LOADREG x15 8 d4 .LfillRegisters
765 LOADREG x15 8 d5 .LfillRegisters
766 LOADREG x15 8 d6 .LfillRegisters
767 LOADREG x15 8 d7 .LfillRegisters
768
769
770.LcallFunction:
771
Andreas Gampe03906cf2014-04-07 12:08:28 -0700772 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000773
Stuart Monteithb95a5342014-03-12 13:32:32 +0000774END art_quick_invoke_stub
775
776/* extern"C"
777 * void art_quick_invoke_static_stub(ArtMethod *method, x0
778 * uint32_t *args, x1
779 * uint32_t argsize, w2
780 * Thread *self, x3
781 * JValue *result, x4
782 * char *shorty); x5
783 */
784ENTRY art_quick_invoke_static_stub
785 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700786 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000787
788 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
789 // Parse the passed shorty to determine which register to load.
790 // Load addresses for routines that load WXSD registers.
791 adr x11, .LstoreW1_2
792 adr x12, .LstoreX1_2
793 adr x13, .LstoreS0_2
794 adr x14, .LstoreD0_2
795
796 // Initialize routine offsets to 0 for integers and floats.
797 // x8 for integers, x15 for floating point.
798 mov x8, #0
799 mov x15, #0
800
801 add x10, x5, #1 // Load shorty address, plus one to skip return value.
802
803 // Loop to fill registers.
804.LfillRegisters2:
805 ldrb w17, [x10], #1 // Load next character in signature, and increment.
806 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
807
808 cmp w17, #'F' // is this a float?
809 bne .LisDouble2
810
811 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700812 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000813
814 add x17, x13, x15 // Calculate subroutine to jump to.
815 br x17
816
817.LisDouble2:
818 cmp w17, #'D' // is this a double?
819 bne .LisLong2
820
821 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700822 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000823
824 add x17, x14, x15 // Calculate subroutine to jump to.
825 br x17
826
827.LisLong2:
828 cmp w17, #'J' // is this a long?
829 bne .LisOther2
830
831 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700832 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000833
834 add x17, x12, x8 // Calculate subroutine to jump to.
835 br x17
836
Stuart Monteithb95a5342014-03-12 13:32:32 +0000837.LisOther2: // Everything else takes one vReg.
838 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700839 beq .Ladvance4_2
840
Stuart Monteithb95a5342014-03-12 13:32:32 +0000841 add x17, x11, x8 // Calculate subroutine to jump to.
842 br x17
843
Andreas Gampe03906cf2014-04-07 12:08:28 -0700844.Ladvance4_2:
845 add x9, x9, #4
846 b .LfillRegisters2
847
848.Ladvance8_2:
849 add x9, x9, #8
850 b .LfillRegisters2
851
Stuart Monteithb95a5342014-03-12 13:32:32 +0000852// Store ints.
853.LstoreW1_2:
854 LOADREG x8 4 w1 .LfillRegisters2
855 LOADREG x8 4 w2 .LfillRegisters2
856 LOADREG x8 4 w3 .LfillRegisters2
857 LOADREG x8 4 w4 .LfillRegisters2
858 LOADREG x8 4 w5 .LfillRegisters2
859 LOADREG x8 4 w6 .LfillRegisters2
860 LOADREG x8 4 w7 .LfillRegisters2
861
862// Store longs.
863.LstoreX1_2:
864 LOADREG x8 8 x1 .LfillRegisters2
865 LOADREG x8 8 x2 .LfillRegisters2
866 LOADREG x8 8 x3 .LfillRegisters2
867 LOADREG x8 8 x4 .LfillRegisters2
868 LOADREG x8 8 x5 .LfillRegisters2
869 LOADREG x8 8 x6 .LfillRegisters2
870 LOADREG x8 8 x7 .LfillRegisters2
871
872// Store singles.
873.LstoreS0_2:
874 LOADREG x15 4 s0 .LfillRegisters2
875 LOADREG x15 4 s1 .LfillRegisters2
876 LOADREG x15 4 s2 .LfillRegisters2
877 LOADREG x15 4 s3 .LfillRegisters2
878 LOADREG x15 4 s4 .LfillRegisters2
879 LOADREG x15 4 s5 .LfillRegisters2
880 LOADREG x15 4 s6 .LfillRegisters2
881 LOADREG x15 4 s7 .LfillRegisters2
882
883// Store doubles.
884.LstoreD0_2:
885 LOADREG x15 8 d0 .LfillRegisters2
886 LOADREG x15 8 d1 .LfillRegisters2
887 LOADREG x15 8 d2 .LfillRegisters2
888 LOADREG x15 8 d3 .LfillRegisters2
889 LOADREG x15 8 d4 .LfillRegisters2
890 LOADREG x15 8 d5 .LfillRegisters2
891 LOADREG x15 8 d6 .LfillRegisters2
892 LOADREG x15 8 d7 .LfillRegisters2
893
894
895.LcallFunction2:
896
Andreas Gampe03906cf2014-04-07 12:08:28 -0700897 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000898
Stuart Monteithb95a5342014-03-12 13:32:32 +0000899END art_quick_invoke_static_stub
900
Andreas Gampe03906cf2014-04-07 12:08:28 -0700901
Stuart Monteithb95a5342014-03-12 13:32:32 +0000902
903 /*
904 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
905 */
906
907ENTRY art_quick_do_long_jump
908 // Load FPRs
909 ldp d0, d1, [x1], #16
910 ldp d2, d3, [x1], #16
911 ldp d4, d5, [x1], #16
912 ldp d6, d7, [x1], #16
913 ldp d8, d9, [x1], #16
914 ldp d10, d11, [x1], #16
915 ldp d12, d13, [x1], #16
916 ldp d14, d15, [x1], #16
917 ldp d16, d17, [x1], #16
918 ldp d18, d19, [x1], #16
919 ldp d20, d21, [x1], #16
920 ldp d22, d23, [x1], #16
921 ldp d24, d25, [x1], #16
922 ldp d26, d27, [x1], #16
923 ldp d28, d29, [x1], #16
924 ldp d30, d31, [x1]
925
926 // Load GPRs
927 // TODO: lots of those are smashed, could optimize.
928 add x0, x0, #30*8
929 ldp x30, x1, [x0], #-16
930 ldp x28, x29, [x0], #-16
931 ldp x26, x27, [x0], #-16
932 ldp x24, x25, [x0], #-16
933 ldp x22, x23, [x0], #-16
934 ldp x20, x21, [x0], #-16
935 ldp x18, x19, [x0], #-16
936 ldp x16, x17, [x0], #-16
937 ldp x14, x15, [x0], #-16
938 ldp x12, x13, [x0], #-16
939 ldp x10, x11, [x0], #-16
940 ldp x8, x9, [x0], #-16
941 ldp x6, x7, [x0], #-16
942 ldp x4, x5, [x0], #-16
943 ldp x2, x3, [x0], #-16
944 mov sp, x1
945
946 // TODO: Is it really OK to use LR for the target PC?
947 mov x0, #0
948 mov x1, #0
949 br xLR
950END art_quick_do_long_jump
951
Andreas Gampef4e910b2014-04-29 16:55:52 -0700952 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700953 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
954 * possibly null object to lock.
955 *
956 * Derived from arm32 code.
957 */
958 .extern artLockObjectFromCode
959ENTRY art_quick_lock_object
960 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700961 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700962.Lretry_lock:
963 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
964 ldxr w1, [x4]
965 cbnz w1, .Lnot_unlocked // already thin locked
966 stxr w3, w2, [x4]
967 cbnz w3, .Lstrex_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700968 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700969 ret
970.Lstrex_fail:
971 b .Lretry_lock // unlikely forward branch, need to reload and recheck r1/r2
972.Lnot_unlocked:
973 lsr w3, w1, 30
974 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
975 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
976 uxth w2, w2 // zero top 16 bits
977 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
978 // else contention, go to slow path
979 add w2, w1, #65536 // increment count in lock word placing in w2 for storing
980 lsr w1, w2, 30 // if either of the top two bits are set, we overflowed.
981 cbnz w1, .Lslow_lock // if we overflow the count go slow path
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700982 str w2, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] // no need for stxr as we hold the lock
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700983 ret
984.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700985 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700986 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700987 bl artLockObjectFromCode // (Object* obj, Thread*)
988 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700989 RETURN_IF_W0_IS_ZERO_OR_DELIVER
990END art_quick_lock_object
991
992 /*
993 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
994 * x0 holds the possibly null object to lock.
995 *
996 * Derived from arm32 code.
997 */
998 .extern artUnlockObjectFromCode
999ENTRY art_quick_unlock_object
1000 cbz x0, .Lslow_unlock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001001 ldr w1, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001002 lsr w2, w1, 30
1003 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1004 ldr w2, [xSELF, #THREAD_ID_OFFSET]
1005 eor w3, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1006 uxth w3, w3 // zero top 16 bits
1007 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
1008 cmp w1, #65536
1009 bpl .Lrecursive_thin_unlock
1010 // transition to unlocked, w3 holds 0
Andreas Gampe675967d2014-05-14 16:28:34 -07001011 dmb ish // full (LoadStore|StoreStore) memory barrier
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001012 str w3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001013 ret
1014.Lrecursive_thin_unlock:
1015 sub w1, w1, #65536
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001016 str w1, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001017 ret
1018.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001019 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001020 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001021 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1022 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001023 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1024END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001025
1026 /*
1027 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1028 * artThrowClassCastException.
1029 */
1030 .extern artThrowClassCastException
1031ENTRY art_quick_check_cast
1032 // Store arguments and link register
1033 sub sp, sp, #32 // Stack needs to be 16b aligned on calls
1034 .cfi_adjust_cfa_offset 32
1035 stp x0, x1, [sp]
1036 .cfi_rel_offset x0, 0
1037 .cfi_rel_offset x1, 8
1038 stp xSELF, xLR, [sp, #16]
1039 .cfi_rel_offset x18, 16
1040 .cfi_rel_offset x30, 24
1041
1042 // Call runtime code
1043 bl artIsAssignableFromCode
1044
1045 // Check for exception
1046 cbz x0, .Lthrow_class_cast_exception
1047
1048 // Restore and return
1049 ldp x0, x1, [sp]
1050 .cfi_restore x0
1051 .cfi_restore x1
1052 ldp xSELF, xLR, [sp, #16]
1053 .cfi_restore x18
1054 .cfi_restore x30
1055 add sp, sp, #32
1056 .cfi_adjust_cfa_offset -32
1057 ret
1058
1059.Lthrow_class_cast_exception:
1060 // Restore
1061 ldp x0, x1, [sp]
1062 .cfi_restore x0
1063 .cfi_restore x1
1064 ldp xSELF, xLR, [sp, #16]
1065 .cfi_restore x18
1066 .cfi_restore x30
1067 add sp, sp, #32
1068 .cfi_adjust_cfa_offset -32
1069
1070 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1071 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001072 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001073 brk 0 // We should not return here...
1074END art_quick_check_cast
1075
Andreas Gampef4e910b2014-04-29 16:55:52 -07001076 /*
1077 * Entry from managed code for array put operations of objects where the value being stored
1078 * needs to be checked for compatibility.
1079 * x0 = array, x1 = index, x2 = value
1080 *
1081 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1082 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1083 * using index-zero-extension in load/stores.
1084 *
1085 * Temporaries: x3, x4
1086 * TODO: x4 OK? ip seems wrong here.
1087 */
1088ENTRY art_quick_aput_obj_with_null_and_bound_check
1089 tst x0, x0
1090 bne art_quick_aput_obj_with_bound_check
1091 b art_quick_throw_null_pointer_exception
1092END art_quick_aput_obj_with_null_and_bound_check
1093
1094ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001095 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001096 cmp w3, w1
1097 bhi art_quick_aput_obj
1098 mov x0, x1
1099 mov x1, x3
1100 b art_quick_throw_array_bounds
1101END art_quick_aput_obj_with_bound_check
1102
1103ENTRY art_quick_aput_obj
1104 cbz x2, .Ldo_aput_null
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001105 ldr w3, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001106 // This also zero-extends to x3
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001107 ldr w4, [x2, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001108 // This also zero-extends to x4
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001109 ldr w3, [x3, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001110 // This also zero-extends to x3
1111 cmp w3, w4 // value's type == array's component type - trivial assignability
1112 bne .Lcheck_assignability
1113.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001114 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001115 // "Compress" = do nothing
1116 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1117 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1118 lsr x0, x0, #7
1119 strb w3, [x3, x0]
1120 ret
1121.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001122 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001123 // "Compress" = do nothing
1124 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1125 ret
1126.Lcheck_assignability:
1127 // Store arguments and link register
1128 sub sp, sp, #48 // Stack needs to be 16b aligned on calls
1129 .cfi_adjust_cfa_offset 48
1130 stp x0, x1, [sp]
1131 .cfi_rel_offset x0, 0
1132 .cfi_rel_offset x1, 8
1133 stp x2, xSELF, [sp, #16]
1134 .cfi_rel_offset x2, 16
1135 .cfi_rel_offset x18, 24
1136 str xLR, [sp, #32]
1137 .cfi_rel_offset x30, 32
1138
1139 // Call runtime code
1140 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1141 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1142 bl artIsAssignableFromCode
1143
1144 // Check for exception
1145 cbz x0, .Lthrow_array_store_exception
1146
1147 // Restore
1148 ldp x0, x1, [sp]
1149 .cfi_restore x0
1150 .cfi_restore x1
1151 ldp x2, xSELF, [sp, #16]
1152 .cfi_restore x2
1153 .cfi_restore x18
1154 ldr xLR, [sp, #32]
1155 .cfi_restore x30
1156 add sp, sp, #48
1157 .cfi_adjust_cfa_offset -48
1158
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001159 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001160 // "Compress" = do nothing
1161 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1162 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1163 lsr x0, x0, #7
1164 strb w3, [x3, x0]
1165 ret
1166.Lthrow_array_store_exception:
1167 ldp x0, x1, [sp]
1168 .cfi_restore x0
1169 .cfi_restore x1
1170 ldp x2, xSELF, [sp, #16]
1171 .cfi_restore x2
1172 .cfi_restore x18
1173 ldr xLR, [sp, #32]
1174 .cfi_restore x30
1175 add sp, sp, #48
1176 .cfi_adjust_cfa_offset -48
1177
1178 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1179 mov x1, x2 // Pass value.
1180 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001181 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001182 brk 0 // Unreached.
1183END art_quick_aput_obj
1184
Stuart Monteithb95a5342014-03-12 13:32:32 +00001185// Macro to facilitate adding new allocation entrypoints.
1186.macro TWO_ARG_DOWNCALL name, entrypoint, return
1187 .extern \entrypoint
1188ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001189 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001190 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001191 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1192 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001193 \return
1194 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001195END \name
1196.endm
1197
1198// Macro to facilitate adding new array allocation entrypoints.
1199.macro THREE_ARG_DOWNCALL name, entrypoint, return
1200 .extern \entrypoint
1201ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001202 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001203 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001204 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001205 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001206 \return
1207 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001208END \name
1209.endm
1210
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001211// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001212.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1213 .extern \entrypoint
1214ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001215 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001216 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001217 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001218 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001219 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001220 \return
1221END \name
1222.endm
1223
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001224.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1225 .extern \entrypoint
1226ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001227 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001228 ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001229 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001230 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001231 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001232 \return
1233END \name
1234.endm
1235
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001236.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1237 .extern \entrypoint
1238ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001239 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001240 ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001241 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001242 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001243 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001244 \return
1245END \name
1246.endm
1247
Matteo Franchindfd891a2014-04-30 12:17:17 +01001248 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001249 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1250 * failure.
1251 */
1252TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1253
1254 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001255 * Entry from managed code when uninitialized static storage, this stub will run the class
1256 * initializer and deliver the exception on error. On success the static storage base is
1257 * returned.
1258 */
1259TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO
1260
Andreas Gampe6aac3552014-06-09 14:55:53 -07001261TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO
1262TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Matteo Franchindfd891a2014-04-30 12:17:17 +01001263
Fred Shih37f05ef2014-07-16 18:38:08 -07001264ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1265ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1266ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1267ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001268ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1269ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1270ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1271
Fred Shih37f05ef2014-07-16 18:38:08 -07001272TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1273TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1274TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1275TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001276TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1277TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1278TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1279
Fred Shih37f05ef2014-07-16 18:38:08 -07001280TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1281TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001282TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1283TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1284
Fred Shih37f05ef2014-07-16 18:38:08 -07001285THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1286THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001287THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001288THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001289THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1290
1291// This is separated out as the argument order is different.
1292 .extern artSet64StaticFromCode
1293ENTRY art_quick_set64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001294 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001295 mov x3, x1 // Store value
Andreas Gampecf4035a2014-05-28 22:43:01 -07001296 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001297 mov x2, x3 // Put value param
1298 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001299 bl artSet64StaticFromCode
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001300 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001301 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1302END art_quick_set64_static
1303
Matteo Franchindfd891a2014-04-30 12:17:17 +01001304 /*
1305 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1306 * exception on error. On success the String is returned. x0 holds the referring method,
1307 * w1 holds the string index. The fast path check for hit in strings cache has already been
1308 * performed.
1309 */
1310TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001311
Stuart Monteithb95a5342014-03-12 13:32:32 +00001312// Generate the allocation entrypoints for each allocator.
1313GENERATE_ALL_ALLOC_ENTRYPOINTS
1314
Zheng Xu48241e72014-05-23 11:52:42 +08001315 /*
1316 * Called by managed code when the value in wSUSPEND has been decremented to 0.
1317 */
1318 .extern artTestSuspendFromCode
1319ENTRY art_quick_test_suspend
1320 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
1321 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to SUSPEND_CHECK_INTERVAL
1322 cbnz w0, .Lneed_suspend // check flags == 0
1323 ret // return if flags == 0
1324.Lneed_suspend:
1325 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001326 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1327 bl artTestSuspendFromCode // (Thread*)
1328 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +08001329END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001330
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001331ENTRY art_quick_implicit_suspend
1332 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001333 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1334 bl artTestSuspendFromCode // (Thread*)
1335 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001336END art_quick_implicit_suspend
1337
Andreas Gampee62a07e2014-03-26 14:53:21 -07001338 /*
1339 * Called by managed code that is attempting to call a method on a proxy class. On entry
1340 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1341 * method agrees with a ref and args callee save frame.
1342 */
1343 .extern artQuickProxyInvokeHandler
1344ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001345 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001346 mov x2, xSELF // pass Thread::Current
1347 mov x3, sp // pass SP
1348 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +08001349 // Use xETR as xSELF might be scratched by native function above.
1350 ldr x2, [xETR, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001351 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001352 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07001353 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001354 ret // return on success
1355.Lexception_in_proxy:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001356 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001357 DELIVER_PENDING_EXCEPTION
1358END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001359
Andreas Gampe51f76352014-05-21 08:28:48 -07001360 /*
Zheng Xub551fdc2014-07-25 11:49:42 +08001361 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's
Andreas Gampe51f76352014-05-21 08:28:48 -07001362 * dex method index.
1363 */
1364ENTRY art_quick_imt_conflict_trampoline
Andreas Gampecf4035a2014-05-28 22:43:01 -07001365 ldr w0, [sp, #0] // load caller Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001366 ldr w0, [x0, #MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods
1367 add x0, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET // get starting address of data
Zheng Xub551fdc2014-07-25 11:49:42 +08001368 ldr w0, [x0, xIP1, lsl 2] // load the target method
Andreas Gampe51f76352014-05-21 08:28:48 -07001369 b art_quick_invoke_interface_trampoline
1370END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001371
1372ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001373 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001374 mov x2, xSELF
1375 mov x3, sp
1376 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001377 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001378 mov xIP0, x0 // Remember returned code pointer in xIP0.
Andreas Gampecf4035a2014-05-28 22:43:01 -07001379 ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001380 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001381 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000013821:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001383 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001384 DELIVER_PENDING_EXCEPTION
1385END art_quick_resolution_trampoline
1386
1387/*
1388 * Generic JNI frame layout:
1389 *
1390 * #-------------------#
1391 * | |
1392 * | caller method... |
1393 * #-------------------# <--- SP on entry
1394 * | Return X30/LR |
1395 * | X29/FP | callee save
1396 * | X28 | callee save
1397 * | X27 | callee save
1398 * | X26 | callee save
1399 * | X25 | callee save
1400 * | X24 | callee save
1401 * | X23 | callee save
1402 * | X22 | callee save
1403 * | X21 | callee save
1404 * | X20 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001405 * | X7 | arg7
1406 * | X6 | arg6
1407 * | X5 | arg5
1408 * | X4 | arg4
1409 * | X3 | arg3
1410 * | X2 | arg2
1411 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001412 * | D7 | float arg 8
1413 * | D6 | float arg 7
1414 * | D5 | float arg 6
1415 * | D4 | float arg 5
1416 * | D3 | float arg 4
1417 * | D2 | float arg 3
1418 * | D1 | float arg 2
1419 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001420 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001421 * #-------------------#
1422 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001423 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001424 * #-------------------#
1425 * | JNI Call Stack |
1426 * #-------------------# <--- SP on native call
1427 * | |
1428 * | Stack for Regs | The trampoline assembly will pop these values
1429 * | | into registers for native call
1430 * #-------------------#
1431 * | Native code ptr |
1432 * #-------------------#
1433 * | Free scratch |
1434 * #-------------------#
1435 * | Ptr to (1) | <--- SP
1436 * #-------------------#
1437 */
1438 /*
1439 * Called to do a generic JNI down-call
1440 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001441ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001442 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001443
1444 // Save SP , so we can have static CFI info.
1445 mov x28, sp
1446 .cfi_def_cfa_register x28
1447
1448 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001449 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001450 mov xFP, sp
1451
Zheng Xub551fdc2014-07-25 11:49:42 +08001452 mov xIP0, #5120
1453 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001454
1455 // prepare for artQuickGenericJniTrampoline call
1456 // (Thread*, SP)
1457 // x0 x1 <= C calling convention
1458 // xSELF xFP <= where they are
1459
1460 mov x0, xSELF // Thread*
1461 mov x1, xFP
1462 bl artQuickGenericJniTrampoline // (Thread*, sp)
1463
Andreas Gampec200a4a2014-06-16 18:39:09 -07001464 // The C call will have registered the complete save-frame on success.
1465 // The result of the call is:
1466 // x0: pointer to native code, 0 on error.
1467 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001468
Andreas Gampec200a4a2014-06-16 18:39:09 -07001469 // Check for error = 0.
1470 cbz x0, .Lentry_error
Stuart Monteithb95a5342014-03-12 13:32:32 +00001471
Andreas Gampec200a4a2014-06-16 18:39:09 -07001472 // Release part of the alloca.
1473 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001474
Andreas Gampec200a4a2014-06-16 18:39:09 -07001475 // Save the code pointer
1476 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001477
1478 // Load parameters from frame into registers.
1479 // TODO Check with artQuickGenericJniTrampoline.
1480 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001481 ldp x0, x1, [sp]
1482 ldp x2, x3, [sp, #16]
1483 ldp x4, x5, [sp, #32]
1484 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001485
Andreas Gampec200a4a2014-06-16 18:39:09 -07001486 ldp d0, d1, [sp, #64]
1487 ldp d2, d3, [sp, #80]
1488 ldp d4, d5, [sp, #96]
1489 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001490
Andreas Gampec200a4a2014-06-16 18:39:09 -07001491 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001492
Zheng Xub551fdc2014-07-25 11:49:42 +08001493 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001494
1495 // result sign extension is handled in C code
1496 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001497 // (Thread*, result, result_f)
1498 // x0 x1 x2 <= C calling convention
1499 mov x1, x0 // Result (from saved)
Zheng Xub551fdc2014-07-25 11:49:42 +08001500 mov x0, xETR // Thread register, original xSELF might be scratched by native code.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001501 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001502
1503 bl artQuickGenericJniEndTrampoline
1504
1505 // Tear down the alloca.
1506 mov sp, x28
1507 .cfi_def_cfa_register sp
1508
Stuart Monteithb95a5342014-03-12 13:32:32 +00001509 // Pending exceptions possible.
Zheng Xub551fdc2014-07-25 11:49:42 +08001510 // Use xETR as xSELF might be scratched by native code
1511 ldr x1, [xETR, THREAD_EXCEPTION_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001512 cbnz x1, .Lexception_in_native
1513
1514 // Tear down the callee-save frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001515 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001516
1517 // store into fpr, for when it's a fpr return...
1518 fmov d0, x0
1519 ret
1520
1521.Lentry_error:
1522 mov sp, x28
1523 .cfi_def_cfa_register sp
Stuart Monteithb95a5342014-03-12 13:32:32 +00001524.Lexception_in_native:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001525 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001526 DELIVER_PENDING_EXCEPTION
1527
1528END art_quick_generic_jni_trampoline
1529
1530/*
1531 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1532 * of a quick call:
1533 * x0 = method being called/to bridge to.
1534 * x1..x7, d0..d7 = arguments to that method.
1535 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001536ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001537 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001538
1539 // x0 will contain mirror::ArtMethod* method.
1540 mov x1, xSELF // How to get Thread::Current() ???
1541 mov x2, sp
1542
1543 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1544 // mirror::ArtMethod** sp)
1545 bl artQuickToInterpreterBridge
1546
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001547 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001548
1549 fmov d0, x0
1550
1551 RETURN_OR_DELIVER_PENDING_EXCEPTION
1552END art_quick_to_interpreter_bridge
1553
Andreas Gamped58342c2014-06-05 14:18:08 -07001554
1555//
1556// Instrumentation-related stubs
1557//
1558 .extern artInstrumentationMethodEntryFromCode
1559ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001560 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001561
Zheng Xub551fdc2014-07-25 11:49:42 +08001562 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07001563
1564 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001565 mov x3, xLR
1566 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07001567
Zheng Xub551fdc2014-07-25 11:49:42 +08001568 mov xIP0, x0 // x0 = result of call.
1569 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07001570
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001571 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07001572 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08001573 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07001574END art_quick_instrumentation_entry
1575
1576 .extern artInstrumentationMethodExitFromCode
1577ENTRY art_quick_instrumentation_exit
1578 mov xLR, #0 // Clobber LR for later checks.
1579
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001580 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001581
1582 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
1583 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
1584 // easier to have an extra small stack area.
1585
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001586 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07001587 .cfi_adjust_cfa_offset 16
1588 str d0, [sp, #8] // Save floating-point result.
1589
Andreas Gamped58342c2014-06-05 14:18:08 -07001590 add x1, sp, #16 // Pass SP.
1591 mov x2, x0 // Pass integer result.
1592 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001593 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07001594 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
1595
Zheng Xub551fdc2014-07-25 11:49:42 +08001596 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07001597 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
1598
1599 ldr d0, [sp, #8] // Restore floating-point result.
1600 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
1601 .cfi_adjust_cfa_offset 16
1602
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001603 POP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001604
Zheng Xub551fdc2014-07-25 11:49:42 +08001605 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07001606END art_quick_instrumentation_exit
1607
1608 /*
1609 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1610 * will long jump to the upcall with a special exception of -1.
1611 */
1612 .extern artDeoptimize
1613ENTRY art_quick_deoptimize
1614 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1615 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001616 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01001617 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07001618END art_quick_deoptimize
1619
1620
Serban Constantinescu169489b2014-06-11 16:43:35 +01001621 /*
1622 * String's indexOf.
1623 *
1624 * TODO: Not very optimized.
1625 * On entry:
1626 * x0: string object (known non-null)
1627 * w1: char to match (known <= 0xFFFF)
1628 * w2: Starting offset in string data
1629 */
1630ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001631 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
1632 ldr w4, [x0, #MIRROR_STRING_OFFSET_OFFSET]
1633 ldr w0, [x0, #MIRROR_STRING_VALUE_OFFSET] // x0 ?
Serban Constantinescu169489b2014-06-11 16:43:35 +01001634
1635 /* Clamp start to [0..count] */
1636 cmp w2, #0
1637 csel w2, wzr, w2, lt
1638 cmp w2, w3
1639 csel w2, w3, w2, gt
1640
1641 /* Build a pointer to the start of the string data */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001642 add x0, x0, #MIRROR_CHAR_ARRAY_DATA_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01001643 add x0, x0, x4, lsl #1
1644
1645 /* Save a copy to compute result */
1646 mov x5, x0
1647
1648 /* Build pointer to start of data to compare and pre-bias */
1649 add x0, x0, x2, lsl #1
1650 sub x0, x0, #2
1651
1652 /* Compute iteration count */
1653 sub w2, w3, w2
1654
1655 /*
1656 * At this point we have:
1657 * x0: start of the data to test
1658 * w1: char to compare
1659 * w2: iteration count
1660 * x5: original start of string data
1661 */
1662
1663 subs w2, w2, #4
1664 b.lt .Lindexof_remainder
1665
1666.Lindexof_loop4:
1667 ldrh w6, [x0, #2]!
1668 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08001669 ldrh wIP0, [x0, #2]!
1670 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01001671 cmp w6, w1
1672 b.eq .Lmatch_0
1673 cmp w7, w1
1674 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08001675 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001676 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08001677 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001678 b.eq .Lmatch_3
1679 subs w2, w2, #4
1680 b.ge .Lindexof_loop4
1681
1682.Lindexof_remainder:
1683 adds w2, w2, #4
1684 b.eq .Lindexof_nomatch
1685
1686.Lindexof_loop1:
1687 ldrh w6, [x0, #2]!
1688 cmp w6, w1
1689 b.eq .Lmatch_3
1690 subs w2, w2, #1
1691 b.ne .Lindexof_loop1
1692
1693.Lindexof_nomatch:
1694 mov x0, #-1
1695 ret
1696
1697.Lmatch_0:
1698 sub x0, x0, #6
1699 sub x0, x0, x5
1700 asr x0, x0, #1
1701 ret
1702.Lmatch_1:
1703 sub x0, x0, #4
1704 sub x0, x0, x5
1705 asr x0, x0, #1
1706 ret
1707.Lmatch_2:
1708 sub x0, x0, #2
1709 sub x0, x0, x5
1710 asr x0, x0, #1
1711 ret
1712.Lmatch_3:
1713 sub x0, x0, x5
1714 asr x0, x0, #1
1715 ret
1716END art_quick_indexof
Andreas Gampe266340d2014-05-02 07:55:24 -07001717
1718 /*
1719 * String's compareTo.
1720 *
1721 * TODO: Not very optimized.
1722 *
1723 * On entry:
1724 * x0: this object pointer
1725 * x1: comp object pointer
1726 *
1727 */
Serban Constantinescu86797a72014-06-19 16:17:56 +01001728 .extern __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001729ENTRY art_quick_string_compareto
1730 mov x2, x0 // x0 is return, use x2 for first input.
1731 sub x0, x2, x1 // Same string object?
1732 cbnz x0,1f
1733 ret
17341: // Different string objects.
1735
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001736 ldr w6, [x2, #MIRROR_STRING_OFFSET_OFFSET]
1737 ldr w5, [x1, #MIRROR_STRING_OFFSET_OFFSET]
1738 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET]
1739 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET]
1740 ldr w2, [x2, #MIRROR_STRING_VALUE_OFFSET]
1741 ldr w1, [x1, #MIRROR_STRING_VALUE_OFFSET]
Andreas Gampe266340d2014-05-02 07:55:24 -07001742
1743 /*
1744 * Now: CharArray* Offset Count
1745 * first arg x2 w6 w4
1746 * second arg x1 w5 w3
1747 */
1748
1749 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4.
1750 subs x0, x4, x3
1751 // Min(count1, count2) into w3.
1752 csel x3, x3, x4, ge
1753
1754 // Build pointer into string data.
1755
1756 // Add offset in array (substr etc.) (sign extend and << 1).
1757 add x2, x2, w6, sxtw #1
1758 add x1, x1, w5, sxtw #1
1759
1760 // Add offset in CharArray to array.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001761 add x2, x2, #MIRROR_CHAR_ARRAY_DATA_OFFSET
1762 add x1, x1, #MIRROR_CHAR_ARRAY_DATA_OFFSET
Andreas Gampe266340d2014-05-02 07:55:24 -07001763
Serban Constantinescu169489b2014-06-11 16:43:35 +01001764 // TODO: Tune this value.
Andreas Gampe266340d2014-05-02 07:55:24 -07001765 // Check for long string, do memcmp16 for them.
1766 cmp w3, #28 // Constant from arm32.
1767 bgt .Ldo_memcmp16
1768
1769 /*
1770 * Now:
1771 * x2: *first string data
1772 * x1: *second string data
1773 * w3: iteration count
1774 * x0: return value if comparison equal
1775 * x4, x5, x6, x7: free
1776 */
1777
1778 // Do a simple unrolled loop.
1779.Lloop:
1780 // At least two more elements?
1781 subs w3, w3, #2
1782 b.lt .Lremainder_or_done
1783
1784 ldrh w4, [x2], #2
1785 ldrh w5, [x1], #2
1786
1787 ldrh w6, [x2], #2
1788 ldrh w7, [x1], #2
1789
1790 subs w4, w4, w5
1791 b.ne .Lw4_result
1792
1793 subs w6, w6, w7
1794 b.ne .Lw6_result
1795
1796 b .Lloop
1797
1798.Lremainder_or_done:
1799 adds w3, w3, #1
1800 b.eq .Lremainder
1801 ret
1802
1803.Lremainder:
1804 ldrh w4, [x2], #2
1805 ldrh w5, [x1], #2
1806 subs w4, w4, w5
1807 b.ne .Lw4_result
1808 ret
1809
1810// Result is in w4
1811.Lw4_result:
1812 sxtw x0, w4
1813 ret
1814
1815// Result is in w6
1816.Lw6_result:
1817 sxtw x0, w6
1818 ret
1819
1820.Ldo_memcmp16:
Zheng Xu62ddb322014-08-12 17:19:12 +08001821 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps.
1822 mov x15, xLR // TODO: Codify and check that?
Andreas Gampe266340d2014-05-02 07:55:24 -07001823
1824 mov x0, x2
1825 uxtw x2, w3
Serban Constantinescu86797a72014-06-19 16:17:56 +01001826 bl __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001827
Zheng Xu62ddb322014-08-12 17:19:12 +08001828 mov xLR, x15 // Restore LR.
Andreas Gampe266340d2014-05-02 07:55:24 -07001829
Serban Constantinescu86797a72014-06-19 16:17:56 +01001830 cmp x0, #0 // Check the memcmp difference.
Zheng Xu62ddb322014-08-12 17:19:12 +08001831 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1.
Andreas Gampe266340d2014-05-02 07:55:24 -07001832 ret
1833END art_quick_string_compareto
Zheng Xu0210d112014-06-17 12:25:48 +08001834
1835// Macro to facilitate adding new entrypoints which call to native function directly.
1836// Currently, xSELF is the only thing we need to take care of between managed code and AAPCS.
1837// But we might introduce more differences.
1838.macro NATIVE_DOWNCALL name, entrypoint
1839 .extern \entrypoint
1840ENTRY \name
Serban Constantinescu86797a72014-06-19 16:17:56 +01001841 stp xSELF, xLR, [sp, #-16]!
Zheng Xu0210d112014-06-17 12:25:48 +08001842 bl \entrypoint
Serban Constantinescu86797a72014-06-19 16:17:56 +01001843 ldp xSELF, xLR, [sp], #16
Zheng Xu0210d112014-06-17 12:25:48 +08001844 ret
1845END \name
1846.endm
1847
1848NATIVE_DOWNCALL art_quick_fmod fmod
1849NATIVE_DOWNCALL art_quick_fmodf fmodf
1850NATIVE_DOWNCALL art_quick_memcpy memcpy
Serban Constantinescu86797a72014-06-19 16:17:56 +01001851NATIVE_DOWNCALL art_quick_assignable_from_code artIsAssignableFromCode