blob: 770073b5ba7a5304326c4825eea6d1e0b96e102a [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
Nicolas Geoffray48088462014-12-12 10:29:38 +0000502SAVE_SIZE=15*8 // x4, x5, x20, x21, x22, x23, x24, x25, x26, x27, x28, 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
Nicolas Geoffray48088462014-12-12 10:29:38 +0000518 str x28, [x10, #112]
519 .cfi_rel_offset x28, 112
520
521 stp x26, x27, [x10, #96]
522 .cfi_rel_offset x26, 96
523 .cfi_rel_offset x27, 104
524
525 stp x24, x25, [x10, #80]
526 .cfi_rel_offset x24, 80
527 .cfi_rel_offset x25, 88
528
529 stp x22, x23, [x10, #64]
530 .cfi_rel_offset x22, 64
531 .cfi_rel_offset x23, 72
532
533 stp x20, x21, [x10, #48]
534 .cfi_rel_offset x20, 48
535 .cfi_rel_offset x21, 56
536
Zheng Xub551fdc2014-07-25 11:49:42 +0800537 stp x9, xSUSPEND, [x10, #32] // Save old stack pointer and xSUSPEND
Andreas Gampe03906cf2014-04-07 12:08:28 -0700538 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700539 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700540
Zheng Xu48241e72014-05-23 11:52:42 +0800541 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700542 .cfi_rel_offset x4, 16
543 .cfi_rel_offset x5, 24
544
Zheng Xu48241e72014-05-23 11:52:42 +0800545 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700546 .cfi_rel_offset x29, 0
547 .cfi_rel_offset x30, 8
548
Zheng Xu48241e72014-05-23 11:52:42 +0800549 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700550 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800551 mov xSELF, x3 // Move thread pointer into SELF register.
552 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to suspend check interval
Andreas Gampe03906cf2014-04-07 12:08:28 -0700553
554 // Copy arguments into stack frame.
555 // Use simple copy routine for now.
556 // 4 bytes per slot.
557 // X1 - source address
558 // W2 - args length
559 // X9 - destination address.
560 // W10 - temporary
Andreas Gampecf4035a2014-05-28 22:43:01 -0700561 add x9, sp, #4 // Destination address is bottom of stack + NULL.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700562
563 // Use \@ to differentiate between macro invocations.
564.LcopyParams\@:
565 cmp w2, #0
566 beq .LendCopyParams\@
567 sub w2, w2, #4 // Need 65536 bytes of range.
568 ldr w10, [x1, x2]
569 str w10, [x9, x2]
570
571 b .LcopyParams\@
572
573.LendCopyParams\@:
574
Andreas Gampecf4035a2014-05-28 22:43:01 -0700575 // Store NULL into StackReference<Method>* at bottom of frame.
576 str wzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700577
Andreas Gampecf4035a2014-05-28 22:43:01 -0700578#if (STACK_REFERENCE_SIZE != 4)
579#error "STACK_REFERENCE_SIZE(ARM64) size not as expected."
580#endif
Andreas Gampe03906cf2014-04-07 12:08:28 -0700581.endm
582
583.macro INVOKE_STUB_CALL_AND_RETURN
584
585 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartier2d721012014-11-10 11:08:06 -0800586 ldr x9, [x0 , #MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700587 // Branch to method.
588 blr x9
589
590 // Restore return value address and shorty address.
591 ldp x4,x5, [xFP, #16]
592 .cfi_restore x4
593 .cfi_restore x5
594
Nicolas Geoffray48088462014-12-12 10:29:38 +0000595 ldr x28, [xFP, #112]
596 .cfi_restore x28
597
598 ldp x26, x27, [xFP, #96]
599 .cfi_restore x26
600 .cfi_restore x27
601
602 ldp x24, x25, [xFP, #80]
603 .cfi_restore x24
604 .cfi_restore x25
605
606 ldp x22, x23, [xFP, #64]
607 .cfi_restore x22
608 .cfi_restore x23
609
610 ldp x20, x21, [xFP, #48]
611 .cfi_restore x20
612 .cfi_restore x21
613
Andreas Gampe03906cf2014-04-07 12:08:28 -0700614 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
615 ldrb w10, [x5]
616
617 // Don't set anything for a void type.
618 cmp w10, #'V'
619 beq .Lexit_art_quick_invoke_stub\@
620
621 cmp w10, #'D'
622 bne .Lreturn_is_float\@
623 str d0, [x4]
624 b .Lexit_art_quick_invoke_stub\@
625
626.Lreturn_is_float\@:
627 cmp w10, #'F'
628 bne .Lreturn_is_int\@
629 str s0, [x4]
630 b .Lexit_art_quick_invoke_stub\@
631
632 // Just store x0. Doesn't matter if it is 64 or 32 bits.
633.Lreturn_is_int\@:
634 str x0, [x4]
635
636.Lexit_art_quick_invoke_stub\@:
Zheng Xub551fdc2014-07-25 11:49:42 +0800637 ldp x2, xSUSPEND, [xFP, #32] // Restore stack pointer and xSUSPEND.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700638 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700639 mov sp, x2
640 .cfi_restore sp
641
Andreas Gamped58342c2014-06-05 14:18:08 -0700642 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700643 .cfi_restore x29
644 .cfi_restore x30
645
646 ret
647
648.endm
649
650
Stuart Monteithb95a5342014-03-12 13:32:32 +0000651/*
652 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
653 * uint32_t *args, x1
654 * uint32_t argsize, w2
655 * Thread *self, x3
656 * JValue *result, x4
657 * char *shorty); x5
658 * +----------------------+
659 * | |
660 * | C/C++ frame |
661 * | LR'' |
662 * | FP'' | <- SP'
663 * +----------------------+
664 * +----------------------+
Zheng Xub551fdc2014-07-25 11:49:42 +0800665 * | x19 | <- Used as wSUSPEND, won't be restored by managed code.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000666 * | SP' |
667 * | X5 |
668 * | X4 | Saved registers
669 * | LR' |
670 * | FP' | <- FP
671 * +----------------------+
672 * | uint32_t out[n-1] |
673 * | : : | Outs
674 * | uint32_t out[0] |
Andreas Gampecf4035a2014-05-28 22:43:01 -0700675 * | StackRef<ArtMethod> | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000676 * +----------------------+
677 *
678 * Outgoing registers:
679 * x0 - Method*
680 * x1-x7 - integer parameters.
681 * d0-d7 - Floating point parameters.
682 * xSELF = self
Zheng Xu48241e72014-05-23 11:52:42 +0800683 * wSUSPEND = suspend count
Stuart Monteithb95a5342014-03-12 13:32:32 +0000684 * SP = & of ArtMethod*
685 * x1 = "this" pointer.
686 *
687 */
688ENTRY art_quick_invoke_stub
689 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700690 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000691
692 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
693 // Parse the passed shorty to determine which register to load.
694 // Load addresses for routines that load WXSD registers.
695 adr x11, .LstoreW2
696 adr x12, .LstoreX2
697 adr x13, .LstoreS0
698 adr x14, .LstoreD0
699
700 // Initialize routine offsets to 0 for integers and floats.
701 // x8 for integers, x15 for floating point.
702 mov x8, #0
703 mov x15, #0
704
705 add x10, x5, #1 // Load shorty address, plus one to skip return value.
706 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
707
708 // Loop to fill registers.
709.LfillRegisters:
710 ldrb w17, [x10], #1 // Load next character in signature, and increment.
711 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
712
713 cmp w17, #'F' // is this a float?
714 bne .LisDouble
715
716 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700717 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000718
719 add x17, x13, x15 // Calculate subroutine to jump to.
720 br x17
721
722.LisDouble:
723 cmp w17, #'D' // is this a double?
724 bne .LisLong
725
726 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700727 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000728
729 add x17, x14, x15 // Calculate subroutine to jump to.
730 br x17
731
732.LisLong:
733 cmp w17, #'J' // is this a long?
734 bne .LisOther
735
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700736 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700737 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000738
739 add x17, x12, x8 // Calculate subroutine to jump to.
740 br x17
741
Stuart Monteithb95a5342014-03-12 13:32:32 +0000742.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700743 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700744 beq .Ladvance4
745
Stuart Monteithb95a5342014-03-12 13:32:32 +0000746 add x17, x11, x8 // Calculate subroutine to jump to.
747 br x17
748
Andreas Gampe03906cf2014-04-07 12:08:28 -0700749.Ladvance4:
750 add x9, x9, #4
751 b .LfillRegisters
752
753.Ladvance8:
754 add x9, x9, #8
755 b .LfillRegisters
756
Stuart Monteithb95a5342014-03-12 13:32:32 +0000757// Macro for loading a parameter into a register.
758// counter - the register with offset into these tables
759// size - the size of the register - 4 or 8 bytes.
760// register - the name of the register to be loaded.
761.macro LOADREG counter size register return
762 ldr \register , [x9], #\size
763 add \counter, \counter, 12
764 b \return
765.endm
766
767// Store ints.
768.LstoreW2:
769 LOADREG x8 4 w2 .LfillRegisters
770 LOADREG x8 4 w3 .LfillRegisters
771 LOADREG x8 4 w4 .LfillRegisters
772 LOADREG x8 4 w5 .LfillRegisters
773 LOADREG x8 4 w6 .LfillRegisters
774 LOADREG x8 4 w7 .LfillRegisters
775
776// Store longs.
777.LstoreX2:
778 LOADREG x8 8 x2 .LfillRegisters
779 LOADREG x8 8 x3 .LfillRegisters
780 LOADREG x8 8 x4 .LfillRegisters
781 LOADREG x8 8 x5 .LfillRegisters
782 LOADREG x8 8 x6 .LfillRegisters
783 LOADREG x8 8 x7 .LfillRegisters
784
785// Store singles.
786.LstoreS0:
787 LOADREG x15 4 s0 .LfillRegisters
788 LOADREG x15 4 s1 .LfillRegisters
789 LOADREG x15 4 s2 .LfillRegisters
790 LOADREG x15 4 s3 .LfillRegisters
791 LOADREG x15 4 s4 .LfillRegisters
792 LOADREG x15 4 s5 .LfillRegisters
793 LOADREG x15 4 s6 .LfillRegisters
794 LOADREG x15 4 s7 .LfillRegisters
795
796// Store doubles.
797.LstoreD0:
798 LOADREG x15 8 d0 .LfillRegisters
799 LOADREG x15 8 d1 .LfillRegisters
800 LOADREG x15 8 d2 .LfillRegisters
801 LOADREG x15 8 d3 .LfillRegisters
802 LOADREG x15 8 d4 .LfillRegisters
803 LOADREG x15 8 d5 .LfillRegisters
804 LOADREG x15 8 d6 .LfillRegisters
805 LOADREG x15 8 d7 .LfillRegisters
806
807
808.LcallFunction:
809
Andreas Gampe03906cf2014-04-07 12:08:28 -0700810 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000811
Stuart Monteithb95a5342014-03-12 13:32:32 +0000812END art_quick_invoke_stub
813
814/* extern"C"
815 * void art_quick_invoke_static_stub(ArtMethod *method, x0
816 * uint32_t *args, x1
817 * uint32_t argsize, w2
818 * Thread *self, x3
819 * JValue *result, x4
820 * char *shorty); x5
821 */
822ENTRY art_quick_invoke_static_stub
823 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700824 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000825
826 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
827 // Parse the passed shorty to determine which register to load.
828 // Load addresses for routines that load WXSD registers.
829 adr x11, .LstoreW1_2
830 adr x12, .LstoreX1_2
831 adr x13, .LstoreS0_2
832 adr x14, .LstoreD0_2
833
834 // Initialize routine offsets to 0 for integers and floats.
835 // x8 for integers, x15 for floating point.
836 mov x8, #0
837 mov x15, #0
838
839 add x10, x5, #1 // Load shorty address, plus one to skip return value.
840
841 // Loop to fill registers.
842.LfillRegisters2:
843 ldrb w17, [x10], #1 // Load next character in signature, and increment.
844 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
845
846 cmp w17, #'F' // is this a float?
847 bne .LisDouble2
848
849 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700850 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000851
852 add x17, x13, x15 // Calculate subroutine to jump to.
853 br x17
854
855.LisDouble2:
856 cmp w17, #'D' // is this a double?
857 bne .LisLong2
858
859 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700860 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000861
862 add x17, x14, x15 // Calculate subroutine to jump to.
863 br x17
864
865.LisLong2:
866 cmp w17, #'J' // is this a long?
867 bne .LisOther2
868
869 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700870 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000871
872 add x17, x12, x8 // Calculate subroutine to jump to.
873 br x17
874
Stuart Monteithb95a5342014-03-12 13:32:32 +0000875.LisOther2: // Everything else takes one vReg.
876 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700877 beq .Ladvance4_2
878
Stuart Monteithb95a5342014-03-12 13:32:32 +0000879 add x17, x11, x8 // Calculate subroutine to jump to.
880 br x17
881
Andreas Gampe03906cf2014-04-07 12:08:28 -0700882.Ladvance4_2:
883 add x9, x9, #4
884 b .LfillRegisters2
885
886.Ladvance8_2:
887 add x9, x9, #8
888 b .LfillRegisters2
889
Stuart Monteithb95a5342014-03-12 13:32:32 +0000890// Store ints.
891.LstoreW1_2:
892 LOADREG x8 4 w1 .LfillRegisters2
893 LOADREG x8 4 w2 .LfillRegisters2
894 LOADREG x8 4 w3 .LfillRegisters2
895 LOADREG x8 4 w4 .LfillRegisters2
896 LOADREG x8 4 w5 .LfillRegisters2
897 LOADREG x8 4 w6 .LfillRegisters2
898 LOADREG x8 4 w7 .LfillRegisters2
899
900// Store longs.
901.LstoreX1_2:
902 LOADREG x8 8 x1 .LfillRegisters2
903 LOADREG x8 8 x2 .LfillRegisters2
904 LOADREG x8 8 x3 .LfillRegisters2
905 LOADREG x8 8 x4 .LfillRegisters2
906 LOADREG x8 8 x5 .LfillRegisters2
907 LOADREG x8 8 x6 .LfillRegisters2
908 LOADREG x8 8 x7 .LfillRegisters2
909
910// Store singles.
911.LstoreS0_2:
912 LOADREG x15 4 s0 .LfillRegisters2
913 LOADREG x15 4 s1 .LfillRegisters2
914 LOADREG x15 4 s2 .LfillRegisters2
915 LOADREG x15 4 s3 .LfillRegisters2
916 LOADREG x15 4 s4 .LfillRegisters2
917 LOADREG x15 4 s5 .LfillRegisters2
918 LOADREG x15 4 s6 .LfillRegisters2
919 LOADREG x15 4 s7 .LfillRegisters2
920
921// Store doubles.
922.LstoreD0_2:
923 LOADREG x15 8 d0 .LfillRegisters2
924 LOADREG x15 8 d1 .LfillRegisters2
925 LOADREG x15 8 d2 .LfillRegisters2
926 LOADREG x15 8 d3 .LfillRegisters2
927 LOADREG x15 8 d4 .LfillRegisters2
928 LOADREG x15 8 d5 .LfillRegisters2
929 LOADREG x15 8 d6 .LfillRegisters2
930 LOADREG x15 8 d7 .LfillRegisters2
931
932
933.LcallFunction2:
934
Andreas Gampe03906cf2014-04-07 12:08:28 -0700935 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000936
Stuart Monteithb95a5342014-03-12 13:32:32 +0000937END art_quick_invoke_static_stub
938
Andreas Gampe03906cf2014-04-07 12:08:28 -0700939
Stuart Monteithb95a5342014-03-12 13:32:32 +0000940
941 /*
942 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
943 */
944
945ENTRY art_quick_do_long_jump
946 // Load FPRs
947 ldp d0, d1, [x1], #16
948 ldp d2, d3, [x1], #16
949 ldp d4, d5, [x1], #16
950 ldp d6, d7, [x1], #16
951 ldp d8, d9, [x1], #16
952 ldp d10, d11, [x1], #16
953 ldp d12, d13, [x1], #16
954 ldp d14, d15, [x1], #16
955 ldp d16, d17, [x1], #16
956 ldp d18, d19, [x1], #16
957 ldp d20, d21, [x1], #16
958 ldp d22, d23, [x1], #16
959 ldp d24, d25, [x1], #16
960 ldp d26, d27, [x1], #16
961 ldp d28, d29, [x1], #16
962 ldp d30, d31, [x1]
963
964 // Load GPRs
965 // TODO: lots of those are smashed, could optimize.
966 add x0, x0, #30*8
967 ldp x30, x1, [x0], #-16
968 ldp x28, x29, [x0], #-16
969 ldp x26, x27, [x0], #-16
970 ldp x24, x25, [x0], #-16
971 ldp x22, x23, [x0], #-16
972 ldp x20, x21, [x0], #-16
973 ldp x18, x19, [x0], #-16
974 ldp x16, x17, [x0], #-16
975 ldp x14, x15, [x0], #-16
976 ldp x12, x13, [x0], #-16
977 ldp x10, x11, [x0], #-16
978 ldp x8, x9, [x0], #-16
979 ldp x6, x7, [x0], #-16
980 ldp x4, x5, [x0], #-16
981 ldp x2, x3, [x0], #-16
982 mov sp, x1
983
984 // TODO: Is it really OK to use LR for the target PC?
985 mov x0, #0
986 mov x1, #0
987 br xLR
988END art_quick_do_long_jump
989
Andreas Gampef4e910b2014-04-29 16:55:52 -0700990 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700991 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
992 * possibly null object to lock.
993 *
994 * Derived from arm32 code.
995 */
996 .extern artLockObjectFromCode
997ENTRY art_quick_lock_object
998 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700999 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001000.Lretry_lock:
1001 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1002 ldxr w1, [x4]
1003 cbnz w1, .Lnot_unlocked // already thin locked
1004 stxr w3, w2, [x4]
1005 cbnz w3, .Lstrex_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001006 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001007 ret
1008.Lstrex_fail:
1009 b .Lretry_lock // unlikely forward branch, need to reload and recheck r1/r2
1010.Lnot_unlocked:
1011 lsr w3, w1, 30
1012 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1013 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1014 uxth w2, w2 // zero top 16 bits
1015 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1016 // else contention, go to slow path
1017 add w2, w1, #65536 // increment count in lock word placing in w2 for storing
1018 lsr w1, w2, 30 // if either of the top two bits are set, we overflowed.
1019 cbnz w1, .Lslow_lock // if we overflow the count go slow path
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001020 str w2, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] // no need for stxr as we hold the lock
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001021 ret
1022.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001023 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001024 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001025 bl artLockObjectFromCode // (Object* obj, Thread*)
1026 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001027 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1028END art_quick_lock_object
1029
1030 /*
1031 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1032 * x0 holds the possibly null object to lock.
1033 *
1034 * Derived from arm32 code.
1035 */
1036 .extern artUnlockObjectFromCode
1037ENTRY art_quick_unlock_object
1038 cbz x0, .Lslow_unlock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001039 ldr w1, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001040 lsr w2, w1, 30
1041 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1042 ldr w2, [xSELF, #THREAD_ID_OFFSET]
1043 eor w3, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1044 uxth w3, w3 // zero top 16 bits
1045 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
1046 cmp w1, #65536
1047 bpl .Lrecursive_thin_unlock
1048 // transition to unlocked, w3 holds 0
Andreas Gampe675967d2014-05-14 16:28:34 -07001049 dmb ish // full (LoadStore|StoreStore) memory barrier
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001050 str w3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001051 ret
1052.Lrecursive_thin_unlock:
1053 sub w1, w1, #65536
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001054 str w1, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001055 ret
1056.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001057 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001058 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001059 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1060 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001061 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1062END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001063
1064 /*
1065 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1066 * artThrowClassCastException.
1067 */
1068 .extern artThrowClassCastException
1069ENTRY art_quick_check_cast
1070 // Store arguments and link register
1071 sub sp, sp, #32 // Stack needs to be 16b aligned on calls
1072 .cfi_adjust_cfa_offset 32
1073 stp x0, x1, [sp]
1074 .cfi_rel_offset x0, 0
1075 .cfi_rel_offset x1, 8
1076 stp xSELF, xLR, [sp, #16]
1077 .cfi_rel_offset x18, 16
1078 .cfi_rel_offset x30, 24
1079
1080 // Call runtime code
1081 bl artIsAssignableFromCode
1082
1083 // Check for exception
1084 cbz x0, .Lthrow_class_cast_exception
1085
1086 // Restore and return
1087 ldp x0, x1, [sp]
1088 .cfi_restore x0
1089 .cfi_restore x1
1090 ldp xSELF, xLR, [sp, #16]
1091 .cfi_restore x18
1092 .cfi_restore x30
1093 add sp, sp, #32
1094 .cfi_adjust_cfa_offset -32
1095 ret
1096
1097.Lthrow_class_cast_exception:
1098 // Restore
1099 ldp x0, x1, [sp]
1100 .cfi_restore x0
1101 .cfi_restore x1
1102 ldp xSELF, xLR, [sp, #16]
1103 .cfi_restore x18
1104 .cfi_restore x30
1105 add sp, sp, #32
1106 .cfi_adjust_cfa_offset -32
1107
1108 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1109 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001110 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001111 brk 0 // We should not return here...
1112END art_quick_check_cast
1113
Andreas Gampef4e910b2014-04-29 16:55:52 -07001114 /*
1115 * Entry from managed code for array put operations of objects where the value being stored
1116 * needs to be checked for compatibility.
1117 * x0 = array, x1 = index, x2 = value
1118 *
1119 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1120 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1121 * using index-zero-extension in load/stores.
1122 *
1123 * Temporaries: x3, x4
1124 * TODO: x4 OK? ip seems wrong here.
1125 */
1126ENTRY art_quick_aput_obj_with_null_and_bound_check
1127 tst x0, x0
1128 bne art_quick_aput_obj_with_bound_check
1129 b art_quick_throw_null_pointer_exception
1130END art_quick_aput_obj_with_null_and_bound_check
1131
1132ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001133 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001134 cmp w3, w1
1135 bhi art_quick_aput_obj
1136 mov x0, x1
1137 mov x1, x3
1138 b art_quick_throw_array_bounds
1139END art_quick_aput_obj_with_bound_check
1140
1141ENTRY art_quick_aput_obj
1142 cbz x2, .Ldo_aput_null
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001143 ldr w3, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001144 // This also zero-extends to x3
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001145 ldr w4, [x2, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001146 // This also zero-extends to x4
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001147 ldr w3, [x3, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001148 // This also zero-extends to x3
1149 cmp w3, w4 // value's type == array's component type - trivial assignability
1150 bne .Lcheck_assignability
1151.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001152 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001153 // "Compress" = do nothing
1154 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1155 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1156 lsr x0, x0, #7
1157 strb w3, [x3, x0]
1158 ret
1159.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001160 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001161 // "Compress" = do nothing
1162 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1163 ret
1164.Lcheck_assignability:
1165 // Store arguments and link register
1166 sub sp, sp, #48 // Stack needs to be 16b aligned on calls
1167 .cfi_adjust_cfa_offset 48
1168 stp x0, x1, [sp]
1169 .cfi_rel_offset x0, 0
1170 .cfi_rel_offset x1, 8
1171 stp x2, xSELF, [sp, #16]
1172 .cfi_rel_offset x2, 16
1173 .cfi_rel_offset x18, 24
1174 str xLR, [sp, #32]
1175 .cfi_rel_offset x30, 32
1176
1177 // Call runtime code
1178 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1179 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1180 bl artIsAssignableFromCode
1181
1182 // Check for exception
1183 cbz x0, .Lthrow_array_store_exception
1184
1185 // Restore
1186 ldp x0, x1, [sp]
1187 .cfi_restore x0
1188 .cfi_restore x1
1189 ldp x2, xSELF, [sp, #16]
1190 .cfi_restore x2
1191 .cfi_restore x18
1192 ldr xLR, [sp, #32]
1193 .cfi_restore x30
1194 add sp, sp, #48
1195 .cfi_adjust_cfa_offset -48
1196
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001197 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001198 // "Compress" = do nothing
1199 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1200 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1201 lsr x0, x0, #7
1202 strb w3, [x3, x0]
1203 ret
1204.Lthrow_array_store_exception:
1205 ldp x0, x1, [sp]
1206 .cfi_restore x0
1207 .cfi_restore x1
1208 ldp x2, xSELF, [sp, #16]
1209 .cfi_restore x2
1210 .cfi_restore x18
1211 ldr xLR, [sp, #32]
1212 .cfi_restore x30
1213 add sp, sp, #48
1214 .cfi_adjust_cfa_offset -48
1215
1216 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1217 mov x1, x2 // Pass value.
1218 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001219 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001220 brk 0 // Unreached.
1221END art_quick_aput_obj
1222
Stuart Monteithb95a5342014-03-12 13:32:32 +00001223// Macro to facilitate adding new allocation entrypoints.
1224.macro TWO_ARG_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 Gampe00c1e6d2014-04-25 15:47:13 -07001228 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001229 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1230 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001231 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001232END \name
1233.endm
1234
1235// Macro to facilitate adding new array allocation entrypoints.
1236.macro THREE_ARG_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 Gampe00c1e6d2014-04-25 15:47:13 -07001240 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001241 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001242 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001243 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001244END \name
1245.endm
1246
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001247// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001248.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1249 .extern \entrypoint
1250ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001251 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001252 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001253 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001254 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001255 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001256 \return
1257END \name
1258.endm
1259
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001260.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1261 .extern \entrypoint
1262ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001263 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001264 ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001265 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001266 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001267 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001268 \return
1269END \name
1270.endm
1271
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001272.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1273 .extern \entrypoint
1274ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001275 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001276 ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001277 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001278 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001279 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001280 \return
1281END \name
1282.endm
1283
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001284.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1285 cbz w0, 1f // result zero branch over
1286 ret // return
12871:
1288 DELIVER_PENDING_EXCEPTION
1289.endm
1290
Matteo Franchindfd891a2014-04-30 12:17:17 +01001291 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001292 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1293 * failure.
1294 */
1295TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1296
1297 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001298 * Entry from managed code when uninitialized static storage, this stub will run the class
1299 * initializer and deliver the exception on error. On success the static storage base is
1300 * returned.
1301 */
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001302TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001303
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001304TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1305TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001306
Fred Shih37f05ef2014-07-16 18:38:08 -07001307ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1308ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1309ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1310ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001311ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1312ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1313ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1314
Fred Shih37f05ef2014-07-16 18:38:08 -07001315TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1316TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1317TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1318TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001319TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1320TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1321TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1322
Fred Shih37f05ef2014-07-16 18:38:08 -07001323TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1324TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001325TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1326TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1327
Fred Shih37f05ef2014-07-16 18:38:08 -07001328THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1329THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001330THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001331THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001332THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1333
1334// This is separated out as the argument order is different.
1335 .extern artSet64StaticFromCode
1336ENTRY art_quick_set64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001337 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001338 mov x3, x1 // Store value
Andreas Gampecf4035a2014-05-28 22:43:01 -07001339 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001340 mov x2, x3 // Put value param
1341 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001342 bl artSet64StaticFromCode
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001343 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001344 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1345END art_quick_set64_static
1346
Matteo Franchindfd891a2014-04-30 12:17:17 +01001347 /*
1348 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1349 * exception on error. On success the String is returned. x0 holds the referring method,
1350 * w1 holds the string index. The fast path check for hit in strings cache has already been
1351 * performed.
1352 */
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001353TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001354
Stuart Monteithb95a5342014-03-12 13:32:32 +00001355// Generate the allocation entrypoints for each allocator.
1356GENERATE_ALL_ALLOC_ENTRYPOINTS
1357
Zheng Xu48241e72014-05-23 11:52:42 +08001358 /*
1359 * Called by managed code when the value in wSUSPEND has been decremented to 0.
1360 */
1361 .extern artTestSuspendFromCode
1362ENTRY art_quick_test_suspend
1363 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
1364 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to SUSPEND_CHECK_INTERVAL
1365 cbnz w0, .Lneed_suspend // check flags == 0
1366 ret // return if flags == 0
1367.Lneed_suspend:
1368 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001369 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1370 bl artTestSuspendFromCode // (Thread*)
1371 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +08001372END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001373
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001374ENTRY art_quick_implicit_suspend
1375 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001376 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1377 bl artTestSuspendFromCode // (Thread*)
1378 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001379END art_quick_implicit_suspend
1380
Andreas Gampee62a07e2014-03-26 14:53:21 -07001381 /*
1382 * Called by managed code that is attempting to call a method on a proxy class. On entry
1383 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1384 * method agrees with a ref and args callee save frame.
1385 */
1386 .extern artQuickProxyInvokeHandler
1387ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001388 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001389 mov x2, xSELF // pass Thread::Current
1390 mov x3, sp // pass SP
1391 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +08001392 // Use xETR as xSELF might be scratched by native function above.
1393 ldr x2, [xETR, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001394 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001395 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07001396 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001397 ret // return on success
1398.Lexception_in_proxy:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001399 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001400 DELIVER_PENDING_EXCEPTION
1401END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001402
Andreas Gampe51f76352014-05-21 08:28:48 -07001403 /*
Zheng Xub551fdc2014-07-25 11:49:42 +08001404 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's
Andreas Gampe51f76352014-05-21 08:28:48 -07001405 * dex method index.
1406 */
1407ENTRY art_quick_imt_conflict_trampoline
Andreas Gampecf4035a2014-05-28 22:43:01 -07001408 ldr w0, [sp, #0] // load caller Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001409 ldr w0, [x0, #MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods
1410 add x0, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET // get starting address of data
Zheng Xub551fdc2014-07-25 11:49:42 +08001411 ldr w0, [x0, xIP1, lsl 2] // load the target method
Andreas Gampe51f76352014-05-21 08:28:48 -07001412 b art_quick_invoke_interface_trampoline
1413END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001414
1415ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001416 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001417 mov x2, xSELF
1418 mov x3, sp
1419 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001420 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001421 mov xIP0, x0 // Remember returned code pointer in xIP0.
Andreas Gampecf4035a2014-05-28 22:43:01 -07001422 ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001423 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001424 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000014251:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001426 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001427 DELIVER_PENDING_EXCEPTION
1428END art_quick_resolution_trampoline
1429
1430/*
1431 * Generic JNI frame layout:
1432 *
1433 * #-------------------#
1434 * | |
1435 * | caller method... |
1436 * #-------------------# <--- SP on entry
1437 * | Return X30/LR |
1438 * | X29/FP | callee save
1439 * | X28 | callee save
1440 * | X27 | callee save
1441 * | X26 | callee save
1442 * | X25 | callee save
1443 * | X24 | callee save
1444 * | X23 | callee save
1445 * | X22 | callee save
1446 * | X21 | callee save
1447 * | X20 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001448 * | X7 | arg7
1449 * | X6 | arg6
1450 * | X5 | arg5
1451 * | X4 | arg4
1452 * | X3 | arg3
1453 * | X2 | arg2
1454 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001455 * | D7 | float arg 8
1456 * | D6 | float arg 7
1457 * | D5 | float arg 6
1458 * | D4 | float arg 5
1459 * | D3 | float arg 4
1460 * | D2 | float arg 3
1461 * | D1 | float arg 2
1462 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001463 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001464 * #-------------------#
1465 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001466 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001467 * #-------------------#
1468 * | JNI Call Stack |
1469 * #-------------------# <--- SP on native call
1470 * | |
1471 * | Stack for Regs | The trampoline assembly will pop these values
1472 * | | into registers for native call
1473 * #-------------------#
1474 * | Native code ptr |
1475 * #-------------------#
1476 * | Free scratch |
1477 * #-------------------#
1478 * | Ptr to (1) | <--- SP
1479 * #-------------------#
1480 */
1481 /*
1482 * Called to do a generic JNI down-call
1483 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001484ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001485 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001486
1487 // Save SP , so we can have static CFI info.
1488 mov x28, sp
1489 .cfi_def_cfa_register x28
1490
1491 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001492 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001493 mov xFP, sp
1494
Zheng Xub551fdc2014-07-25 11:49:42 +08001495 mov xIP0, #5120
1496 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001497
1498 // prepare for artQuickGenericJniTrampoline call
1499 // (Thread*, SP)
1500 // x0 x1 <= C calling convention
1501 // xSELF xFP <= where they are
1502
1503 mov x0, xSELF // Thread*
1504 mov x1, xFP
1505 bl artQuickGenericJniTrampoline // (Thread*, sp)
1506
Andreas Gampec200a4a2014-06-16 18:39:09 -07001507 // The C call will have registered the complete save-frame on success.
1508 // The result of the call is:
1509 // x0: pointer to native code, 0 on error.
1510 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001511
Andreas Gampec200a4a2014-06-16 18:39:09 -07001512 // Check for error = 0.
1513 cbz x0, .Lentry_error
Stuart Monteithb95a5342014-03-12 13:32:32 +00001514
Andreas Gampec200a4a2014-06-16 18:39:09 -07001515 // Release part of the alloca.
1516 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001517
Andreas Gampec200a4a2014-06-16 18:39:09 -07001518 // Save the code pointer
1519 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001520
1521 // Load parameters from frame into registers.
1522 // TODO Check with artQuickGenericJniTrampoline.
1523 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001524 ldp x0, x1, [sp]
1525 ldp x2, x3, [sp, #16]
1526 ldp x4, x5, [sp, #32]
1527 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001528
Andreas Gampec200a4a2014-06-16 18:39:09 -07001529 ldp d0, d1, [sp, #64]
1530 ldp d2, d3, [sp, #80]
1531 ldp d4, d5, [sp, #96]
1532 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001533
Andreas Gampec200a4a2014-06-16 18:39:09 -07001534 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001535
Zheng Xub551fdc2014-07-25 11:49:42 +08001536 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001537
1538 // result sign extension is handled in C code
1539 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001540 // (Thread*, result, result_f)
1541 // x0 x1 x2 <= C calling convention
1542 mov x1, x0 // Result (from saved)
Zheng Xub551fdc2014-07-25 11:49:42 +08001543 mov x0, xETR // Thread register, original xSELF might be scratched by native code.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001544 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001545
1546 bl artQuickGenericJniEndTrampoline
1547
1548 // Tear down the alloca.
1549 mov sp, x28
1550 .cfi_def_cfa_register sp
1551
Stuart Monteithb95a5342014-03-12 13:32:32 +00001552 // Pending exceptions possible.
Zheng Xub551fdc2014-07-25 11:49:42 +08001553 // Use xETR as xSELF might be scratched by native code
1554 ldr x1, [xETR, THREAD_EXCEPTION_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001555 cbnz x1, .Lexception_in_native
1556
1557 // Tear down the callee-save frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001558 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001559
1560 // store into fpr, for when it's a fpr return...
1561 fmov d0, x0
1562 ret
1563
1564.Lentry_error:
1565 mov sp, x28
1566 .cfi_def_cfa_register sp
Stuart Monteithb95a5342014-03-12 13:32:32 +00001567.Lexception_in_native:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001568 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001569 DELIVER_PENDING_EXCEPTION
1570
1571END art_quick_generic_jni_trampoline
1572
1573/*
1574 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1575 * of a quick call:
1576 * x0 = method being called/to bridge to.
1577 * x1..x7, d0..d7 = arguments to that method.
1578 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001579ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001580 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001581
1582 // x0 will contain mirror::ArtMethod* method.
1583 mov x1, xSELF // How to get Thread::Current() ???
1584 mov x2, sp
1585
1586 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1587 // mirror::ArtMethod** sp)
1588 bl artQuickToInterpreterBridge
1589
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001590 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001591
1592 fmov d0, x0
1593
1594 RETURN_OR_DELIVER_PENDING_EXCEPTION
1595END art_quick_to_interpreter_bridge
1596
Andreas Gamped58342c2014-06-05 14:18:08 -07001597
1598//
1599// Instrumentation-related stubs
1600//
1601 .extern artInstrumentationMethodEntryFromCode
1602ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001603 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001604
Zheng Xub551fdc2014-07-25 11:49:42 +08001605 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07001606
1607 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001608 mov x3, xLR
1609 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07001610
Zheng Xub551fdc2014-07-25 11:49:42 +08001611 mov xIP0, x0 // x0 = result of call.
1612 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07001613
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001614 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07001615 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08001616 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07001617END art_quick_instrumentation_entry
1618
1619 .extern artInstrumentationMethodExitFromCode
1620ENTRY art_quick_instrumentation_exit
1621 mov xLR, #0 // Clobber LR for later checks.
1622
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001623 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001624
1625 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
1626 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
1627 // easier to have an extra small stack area.
1628
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001629 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07001630 .cfi_adjust_cfa_offset 16
1631 str d0, [sp, #8] // Save floating-point result.
1632
Andreas Gamped58342c2014-06-05 14:18:08 -07001633 add x1, sp, #16 // Pass SP.
1634 mov x2, x0 // Pass integer result.
1635 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001636 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07001637 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
1638
Zheng Xub551fdc2014-07-25 11:49:42 +08001639 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07001640 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
1641
1642 ldr d0, [sp, #8] // Restore floating-point result.
1643 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
1644 .cfi_adjust_cfa_offset 16
1645
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001646 POP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001647
Zheng Xub551fdc2014-07-25 11:49:42 +08001648 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07001649END art_quick_instrumentation_exit
1650
1651 /*
1652 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1653 * will long jump to the upcall with a special exception of -1.
1654 */
1655 .extern artDeoptimize
1656ENTRY art_quick_deoptimize
1657 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1658 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001659 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01001660 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07001661END art_quick_deoptimize
1662
1663
Serban Constantinescu169489b2014-06-11 16:43:35 +01001664 /*
1665 * String's indexOf.
1666 *
1667 * TODO: Not very optimized.
1668 * On entry:
1669 * x0: string object (known non-null)
1670 * w1: char to match (known <= 0xFFFF)
1671 * w2: Starting offset in string data
1672 */
1673ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001674 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
1675 ldr w4, [x0, #MIRROR_STRING_OFFSET_OFFSET]
1676 ldr w0, [x0, #MIRROR_STRING_VALUE_OFFSET] // x0 ?
Serban Constantinescu169489b2014-06-11 16:43:35 +01001677
1678 /* Clamp start to [0..count] */
1679 cmp w2, #0
1680 csel w2, wzr, w2, lt
1681 cmp w2, w3
1682 csel w2, w3, w2, gt
1683
1684 /* Build a pointer to the start of the string data */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001685 add x0, x0, #MIRROR_CHAR_ARRAY_DATA_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01001686 add x0, x0, x4, lsl #1
1687
1688 /* Save a copy to compute result */
1689 mov x5, x0
1690
1691 /* Build pointer to start of data to compare and pre-bias */
1692 add x0, x0, x2, lsl #1
1693 sub x0, x0, #2
1694
1695 /* Compute iteration count */
1696 sub w2, w3, w2
1697
1698 /*
1699 * At this point we have:
1700 * x0: start of the data to test
1701 * w1: char to compare
1702 * w2: iteration count
1703 * x5: original start of string data
1704 */
1705
1706 subs w2, w2, #4
1707 b.lt .Lindexof_remainder
1708
1709.Lindexof_loop4:
1710 ldrh w6, [x0, #2]!
1711 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08001712 ldrh wIP0, [x0, #2]!
1713 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01001714 cmp w6, w1
1715 b.eq .Lmatch_0
1716 cmp w7, w1
1717 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08001718 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001719 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08001720 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001721 b.eq .Lmatch_3
1722 subs w2, w2, #4
1723 b.ge .Lindexof_loop4
1724
1725.Lindexof_remainder:
1726 adds w2, w2, #4
1727 b.eq .Lindexof_nomatch
1728
1729.Lindexof_loop1:
1730 ldrh w6, [x0, #2]!
1731 cmp w6, w1
1732 b.eq .Lmatch_3
1733 subs w2, w2, #1
1734 b.ne .Lindexof_loop1
1735
1736.Lindexof_nomatch:
1737 mov x0, #-1
1738 ret
1739
1740.Lmatch_0:
1741 sub x0, x0, #6
1742 sub x0, x0, x5
1743 asr x0, x0, #1
1744 ret
1745.Lmatch_1:
1746 sub x0, x0, #4
1747 sub x0, x0, x5
1748 asr x0, x0, #1
1749 ret
1750.Lmatch_2:
1751 sub x0, x0, #2
1752 sub x0, x0, x5
1753 asr x0, x0, #1
1754 ret
1755.Lmatch_3:
1756 sub x0, x0, x5
1757 asr x0, x0, #1
1758 ret
1759END art_quick_indexof
Andreas Gampe266340d2014-05-02 07:55:24 -07001760
1761 /*
1762 * String's compareTo.
1763 *
1764 * TODO: Not very optimized.
1765 *
1766 * On entry:
1767 * x0: this object pointer
1768 * x1: comp object pointer
1769 *
1770 */
Serban Constantinescu86797a72014-06-19 16:17:56 +01001771 .extern __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001772ENTRY art_quick_string_compareto
1773 mov x2, x0 // x0 is return, use x2 for first input.
1774 sub x0, x2, x1 // Same string object?
1775 cbnz x0,1f
1776 ret
17771: // Different string objects.
1778
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001779 ldr w6, [x2, #MIRROR_STRING_OFFSET_OFFSET]
1780 ldr w5, [x1, #MIRROR_STRING_OFFSET_OFFSET]
1781 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET]
1782 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET]
1783 ldr w2, [x2, #MIRROR_STRING_VALUE_OFFSET]
1784 ldr w1, [x1, #MIRROR_STRING_VALUE_OFFSET]
Andreas Gampe266340d2014-05-02 07:55:24 -07001785
1786 /*
1787 * Now: CharArray* Offset Count
1788 * first arg x2 w6 w4
1789 * second arg x1 w5 w3
1790 */
1791
1792 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4.
1793 subs x0, x4, x3
1794 // Min(count1, count2) into w3.
1795 csel x3, x3, x4, ge
1796
1797 // Build pointer into string data.
1798
1799 // Add offset in array (substr etc.) (sign extend and << 1).
1800 add x2, x2, w6, sxtw #1
1801 add x1, x1, w5, sxtw #1
1802
1803 // Add offset in CharArray to array.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001804 add x2, x2, #MIRROR_CHAR_ARRAY_DATA_OFFSET
1805 add x1, x1, #MIRROR_CHAR_ARRAY_DATA_OFFSET
Andreas Gampe266340d2014-05-02 07:55:24 -07001806
Serban Constantinescu169489b2014-06-11 16:43:35 +01001807 // TODO: Tune this value.
Andreas Gampe266340d2014-05-02 07:55:24 -07001808 // Check for long string, do memcmp16 for them.
1809 cmp w3, #28 // Constant from arm32.
1810 bgt .Ldo_memcmp16
1811
1812 /*
1813 * Now:
1814 * x2: *first string data
1815 * x1: *second string data
1816 * w3: iteration count
1817 * x0: return value if comparison equal
1818 * x4, x5, x6, x7: free
1819 */
1820
1821 // Do a simple unrolled loop.
1822.Lloop:
1823 // At least two more elements?
1824 subs w3, w3, #2
1825 b.lt .Lremainder_or_done
1826
1827 ldrh w4, [x2], #2
1828 ldrh w5, [x1], #2
1829
1830 ldrh w6, [x2], #2
1831 ldrh w7, [x1], #2
1832
1833 subs w4, w4, w5
1834 b.ne .Lw4_result
1835
1836 subs w6, w6, w7
1837 b.ne .Lw6_result
1838
1839 b .Lloop
1840
1841.Lremainder_or_done:
1842 adds w3, w3, #1
1843 b.eq .Lremainder
1844 ret
1845
1846.Lremainder:
1847 ldrh w4, [x2], #2
1848 ldrh w5, [x1], #2
1849 subs w4, w4, w5
1850 b.ne .Lw4_result
1851 ret
1852
1853// Result is in w4
1854.Lw4_result:
1855 sxtw x0, w4
1856 ret
1857
1858// Result is in w6
1859.Lw6_result:
1860 sxtw x0, w6
1861 ret
1862
1863.Ldo_memcmp16:
Zheng Xu62ddb322014-08-12 17:19:12 +08001864 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps.
1865 mov x15, xLR // TODO: Codify and check that?
Andreas Gampe266340d2014-05-02 07:55:24 -07001866
1867 mov x0, x2
1868 uxtw x2, w3
Serban Constantinescu86797a72014-06-19 16:17:56 +01001869 bl __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001870
Zheng Xu62ddb322014-08-12 17:19:12 +08001871 mov xLR, x15 // Restore LR.
Andreas Gampe266340d2014-05-02 07:55:24 -07001872
Serban Constantinescu86797a72014-06-19 16:17:56 +01001873 cmp x0, #0 // Check the memcmp difference.
Zheng Xu62ddb322014-08-12 17:19:12 +08001874 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1.
Andreas Gampe266340d2014-05-02 07:55:24 -07001875 ret
1876END art_quick_string_compareto
Zheng Xu0210d112014-06-17 12:25:48 +08001877
1878// Macro to facilitate adding new entrypoints which call to native function directly.
1879// Currently, xSELF is the only thing we need to take care of between managed code and AAPCS.
1880// But we might introduce more differences.
1881.macro NATIVE_DOWNCALL name, entrypoint
1882 .extern \entrypoint
1883ENTRY \name
Serban Constantinescu86797a72014-06-19 16:17:56 +01001884 stp xSELF, xLR, [sp, #-16]!
Zheng Xu0210d112014-06-17 12:25:48 +08001885 bl \entrypoint
Serban Constantinescu86797a72014-06-19 16:17:56 +01001886 ldp xSELF, xLR, [sp], #16
Zheng Xu0210d112014-06-17 12:25:48 +08001887 ret
1888END \name
1889.endm
1890
1891NATIVE_DOWNCALL art_quick_fmod fmod
1892NATIVE_DOWNCALL art_quick_fmodf fmodf
1893NATIVE_DOWNCALL art_quick_memcpy memcpy
Serban Constantinescu86797a72014-06-19 16:17:56 +01001894NATIVE_DOWNCALL art_quick_assignable_from_code artIsAssignableFromCode