blob: 1fba09bae3ff3c68be0f568264b84f51f669c807 [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] .
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010034 // Loads appropriate callee-save-method.
Mathieu Chartiere401d142015-04-22 13:56:20 -070035 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
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010045 // Stack alignment filler [sp, #8].
46 // FP callee-saves.
47 stp d8, d9, [sp, #16]
48 stp d10, d11, [sp, #32]
49 stp d12, d13, [sp, #48]
50 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070051
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010052 // GP callee-saves
53 stp x19, x20, [sp, #80]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070054 .cfi_rel_offset x19, 80
Andreas Gampe5c1e4352014-04-21 19:28:24 -070055 .cfi_rel_offset x20, 88
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010056
57 stp x21, x22, [sp, #96]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070058 .cfi_rel_offset x21, 96
Andreas Gampe5c1e4352014-04-21 19:28:24 -070059 .cfi_rel_offset x22, 104
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010060
61 stp x23, x24, [sp, #112]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070062 .cfi_rel_offset x23, 112
Andreas Gampe5c1e4352014-04-21 19:28:24 -070063 .cfi_rel_offset x24, 120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010064
65 stp x25, x26, [sp, #128]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070066 .cfi_rel_offset x25, 128
Andreas Gampe5c1e4352014-04-21 19:28:24 -070067 .cfi_rel_offset x26, 136
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010068
69 stp x27, x28, [sp, #144]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070070 .cfi_rel_offset x27, 144
Andreas Gampe5c1e4352014-04-21 19:28:24 -070071 .cfi_rel_offset x28, 152
Andreas Gampe5c1e4352014-04-21 19:28:24 -070072
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010073 stp x29, xLR, [sp, #160]
74 .cfi_rel_offset x29, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -070075 .cfi_rel_offset x30, 168
76
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010077 // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs].
78 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070079 // Place sp in Thread::Current()->top_quick_frame.
80 mov xIP0, sp
81 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +000082.endm
83
Zheng Xub551fdc2014-07-25 11:49:42 +080084 /*
85 * Macro that sets up the callee save frame to conform with
86 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
87 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070088.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080089 adrp xIP0, :got:_ZN3art7Runtime9instance_E
90 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
91
92 // Our registers aren't intermixed - just spill in order.
93 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
94
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010095 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefOnly] .
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010096 // Loads appropriate callee-save-method.
Mathieu Chartiere401d142015-04-22 13:56:20 -070097 ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
Zheng Xub551fdc2014-07-25 11:49:42 +080098
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010099 sub sp, sp, #96
100 .cfi_adjust_cfa_offset 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800101
102 // Ugly compile-time check, but we only have the preprocessor.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96)
Zheng Xub551fdc2014-07-25 11:49:42 +0800104#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
105#endif
106
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100107 // GP callee-saves.
108 // x20 paired with ArtMethod* - see below.
109 stp x21, x22, [sp, #16]
110 .cfi_rel_offset x21, 16
111 .cfi_rel_offset x22, 24
Zheng Xub551fdc2014-07-25 11:49:42 +0800112
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100113 stp x23, x24, [sp, #32]
114 .cfi_rel_offset x23, 32
115 .cfi_rel_offset x24, 40
Zheng Xub551fdc2014-07-25 11:49:42 +0800116
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100117 stp x25, x26, [sp, #48]
118 .cfi_rel_offset x25, 48
119 .cfi_rel_offset x26, 56
Zheng Xub551fdc2014-07-25 11:49:42 +0800120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100121 stp x27, x28, [sp, #64]
122 .cfi_rel_offset x27, 64
123 .cfi_rel_offset x28, 72
Zheng Xub551fdc2014-07-25 11:49:42 +0800124
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100125 stp x29, xLR, [sp, #80]
126 .cfi_rel_offset x29, 80
127 .cfi_rel_offset x30, 88
Zheng Xub551fdc2014-07-25 11:49:42 +0800128
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100129 // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly].
130 stp xIP0, x20, [sp]
131 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800132
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700133 // Place sp in Thread::Current()->top_quick_frame.
134 mov xIP0, sp
135 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800136.endm
137
138// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700139.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100140 // Callee-saves.
141 ldr x20, [sp, #8]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700142 .cfi_restore x20
Zheng Xu69a50302015-04-14 20:04:41 +0800143
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100144 ldp x21, x22, [sp, #16]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700145 .cfi_restore x21
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700146 .cfi_restore x22
Zheng Xu69a50302015-04-14 20:04:41 +0800147
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100148 ldp x23, x24, [sp, #32]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700149 .cfi_restore x23
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700150 .cfi_restore x24
Zheng Xu69a50302015-04-14 20:04:41 +0800151
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100152 ldp x25, x26, [sp, #48]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700153 .cfi_restore x25
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700154 .cfi_restore x26
Zheng Xu69a50302015-04-14 20:04:41 +0800155
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100156 ldp x27, x28, [sp, #64]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700157 .cfi_restore x27
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700158 .cfi_restore x28
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700159
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100160 ldp x29, xLR, [sp, #80]
Zheng Xu69a50302015-04-14 20:04:41 +0800161 .cfi_restore x29
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700162 .cfi_restore x30
163
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100164 add sp, sp, #96
165 .cfi_adjust_cfa_offset -96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000166.endm
167
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700168.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100169 add sp, sp, #96
170 .cfi_adjust_cfa_offset - 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700171.endm
172
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700173.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
174 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800175 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000176.endm
177
178
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700179.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800180 sub sp, sp, #224
181 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000182
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700183 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +0800184#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700185#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
186#endif
187
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100188 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800189 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100190 stp d0, d1, [sp, #16]
191 stp d2, d3, [sp, #32]
192 stp d4, d5, [sp, #48]
193 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000194
Zheng Xu69a50302015-04-14 20:04:41 +0800195 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100196 stp x1, x2, [sp, #80]
197 .cfi_rel_offset x1, 80
198 .cfi_rel_offset x2, 88
Stuart Monteithb95a5342014-03-12 13:32:32 +0000199
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100200 stp x3, x4, [sp, #96]
201 .cfi_rel_offset x3, 96
202 .cfi_rel_offset x4, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700203
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100204 stp x5, x6, [sp, #112]
205 .cfi_rel_offset x5, 112
206 .cfi_rel_offset x6, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700207
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100208 // x7, Callee-saves.
209 stp x7, x20, [sp, #128]
210 .cfi_rel_offset x7, 128
Zheng Xu69a50302015-04-14 20:04:41 +0800211 .cfi_rel_offset x20, 136
212
Zheng Xub551fdc2014-07-25 11:49:42 +0800213 stp x21, x22, [sp, #144]
214 .cfi_rel_offset x21, 144
215 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700216
Zheng Xub551fdc2014-07-25 11:49:42 +0800217 stp x23, x24, [sp, #160]
218 .cfi_rel_offset x23, 160
219 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700220
Zheng Xub551fdc2014-07-25 11:49:42 +0800221 stp x25, x26, [sp, #176]
222 .cfi_rel_offset x25, 176
223 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700224
Zheng Xub551fdc2014-07-25 11:49:42 +0800225 stp x27, x28, [sp, #192]
226 .cfi_rel_offset x27, 192
227 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700228
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100229 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800230 stp x29, xLR, [sp, #208]
231 .cfi_rel_offset x29, 208
232 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700233
Stuart Monteithb95a5342014-03-12 13:32:32 +0000234.endm
235
236 /*
237 * Macro that sets up the callee save frame to conform with
238 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
239 *
240 * TODO This is probably too conservative - saving FP & LR.
241 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700242.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800243 adrp xIP0, :got:_ZN3art7Runtime9instance_E
244 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000245
246 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +0800247 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +0000248
Zheng Xub551fdc2014-07-25 11:49:42 +0800249 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Mathieu Chartiere401d142015-04-22 13:56:20 -0700250 ldr xIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000251
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700252 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000253
Zheng Xub551fdc2014-07-25 11:49:42 +0800254 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700255 // Place sp in Thread::Current()->top_quick_frame.
256 mov xIP0, sp
257 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
258.endm
259
260.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
261 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
262 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
263 // Place sp in Thread::Current()->top_quick_frame.
264 mov xIP0, sp
265 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000266.endm
267
Zheng Xub551fdc2014-07-25 11:49:42 +0800268// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700269.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800270 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100271 ldp d0, d1, [sp, #16]
272 ldp d2, d3, [sp, #32]
273 ldp d4, d5, [sp, #48]
274 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000275
Zheng Xu69a50302015-04-14 20:04:41 +0800276 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100277 ldp x1, x2, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700278 .cfi_restore x1
279 .cfi_restore x2
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100280
281 ldp x3, x4, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700282 .cfi_restore x3
283 .cfi_restore x4
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100284
285 ldp x5, x6, [sp, #112]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700286 .cfi_restore x5
Zheng Xu69a50302015-04-14 20:04:41 +0800287 .cfi_restore x6
Andreas Gampe03906cf2014-04-07 12:08:28 -0700288
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100289 // x7, Callee-saves.
290 ldp x7, x20, [sp, #128]
291 .cfi_restore x7
Zheng Xu69a50302015-04-14 20:04:41 +0800292 .cfi_restore x20
293
Zheng Xub551fdc2014-07-25 11:49:42 +0800294 ldp x21, x22, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700295 .cfi_restore x21
296 .cfi_restore x22
297
Zheng Xub551fdc2014-07-25 11:49:42 +0800298 ldp x23, x24, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700299 .cfi_restore x23
300 .cfi_restore x24
301
Zheng Xub551fdc2014-07-25 11:49:42 +0800302 ldp x25, x26, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700303 .cfi_restore x25
304 .cfi_restore x26
305
Zheng Xub551fdc2014-07-25 11:49:42 +0800306 ldp x27, x28, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700307 .cfi_restore x27
308 .cfi_restore x28
309
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100310 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800311 ldp x29, xLR, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700312 .cfi_restore x29
313 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000314
Zheng Xub551fdc2014-07-25 11:49:42 +0800315 add sp, sp, #224
316 .cfi_adjust_cfa_offset -224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000317.endm
318
319.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700320 cbnz x0, 1f // result non-zero branch over
321 ret // return
3221:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000323.endm
324
325.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700326 cbz x0, 1f // result zero branch over
327 ret // return
3281:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000329.endm
330
331 /*
332 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
333 * exception is Thread::Current()->exception_
334 */
335.macro DELIVER_PENDING_EXCEPTION
336 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
337 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000338
339 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700340 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000341 brk 0 // Unreached
342.endm
343
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700344.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
345 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
346 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000347 ret
3481:
349 DELIVER_PENDING_EXCEPTION
350.endm
351
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700352.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800353 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700354.endm
355
356// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
357.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
358 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
359.endm
360
361.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
362 cbnz w0, 1f // result non-zero branch over
363 ret // return
3641:
365 DELIVER_PENDING_EXCEPTION
366.endm
367
Stuart Monteithb95a5342014-03-12 13:32:32 +0000368.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
369 .extern \cxx_name
370ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700371 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800372 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700373 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000374END \c_name
375.endm
376
377.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
378 .extern \cxx_name
379ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100380 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800381 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700382 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000383 brk 0
384END \c_name
385.endm
386
387.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
388 .extern \cxx_name
389ENTRY \c_name
390 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800391 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700392 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000393 brk 0
394END \c_name
395.endm
396
397 /*
398 * Called by managed code, saves callee saves and then calls artThrowException
399 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
400 */
401ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
402
403 /*
404 * Called by managed code to create and deliver a NullPointerException.
405 */
406NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
407
408 /*
409 * Called by managed code to create and deliver an ArithmeticException.
410 */
411NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
412
413 /*
414 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
415 * index, arg2 holds limit.
416 */
417TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
418
419 /*
420 * Called by managed code to create and deliver a StackOverflowError.
421 */
422NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
423
424 /*
425 * Called by managed code to create and deliver a NoSuchMethodError.
426 */
427ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
428
429 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000430 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700431 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100432 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700433 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000434 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700435 * 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 +0000436 * of the target Method* in x0 and method->code_ in x1.
437 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700438 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000439 * thread and we branch to another stub to deliver it.
440 *
441 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
442 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700443 *
444 * Adapted from ARM32 code.
445 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800446 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000447 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700448.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000449 .extern \cxx_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700450 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700451 // Helper signature is always
452 // (method_idx, *this_object, *caller_method, *self, sp)
453
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100454 mov x2, xSELF // pass Thread::Current
455 mov x3, sp
456 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800457 mov xIP0, x1 // save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700458 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700459 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800460 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07004611:
462 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700463.endm
464.macro INVOKE_TRAMPOLINE c_name, cxx_name
465ENTRY \c_name
466 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000467END \c_name
468.endm
469
Stuart Monteithb95a5342014-03-12 13:32:32 +0000470INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
471
472INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
473INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
474INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
475INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
476
Andreas Gampe03906cf2014-04-07 12:08:28 -0700477
478.macro INVOKE_STUB_CREATE_FRAME
479
Zheng Xu69a50302015-04-14 20:04:41 +0800480SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700481SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
Andreas Gampecf4035a2014-05-28 22:43:01 -0700482
Andreas Gampe03906cf2014-04-07 12:08:28 -0700483
Zheng Xu48241e72014-05-23 11:52:42 +0800484 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700485 .cfi_register sp,x9
486
Zheng Xu48241e72014-05-23 11:52:42 +0800487 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700488 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
Zheng Xu48241e72014-05-23 11:52:42 +0800489 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
490 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700491
Zheng Xu48241e72014-05-23 11:52:42 +0800492 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
493 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700494 .cfi_adjust_cfa_offset SAVE_SIZE
495
Nicolas Geoffray48088462014-12-12 10:29:38 +0000496 str x28, [x10, #112]
497 .cfi_rel_offset x28, 112
498
499 stp x26, x27, [x10, #96]
500 .cfi_rel_offset x26, 96
501 .cfi_rel_offset x27, 104
502
503 stp x24, x25, [x10, #80]
504 .cfi_rel_offset x24, 80
505 .cfi_rel_offset x25, 88
506
507 stp x22, x23, [x10, #64]
508 .cfi_rel_offset x22, 64
509 .cfi_rel_offset x23, 72
510
511 stp x20, x21, [x10, #48]
512 .cfi_rel_offset x20, 48
513 .cfi_rel_offset x21, 56
514
Zheng Xu69a50302015-04-14 20:04:41 +0800515 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700516 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700517 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700518
Zheng Xu48241e72014-05-23 11:52:42 +0800519 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700520 .cfi_rel_offset x4, 16
521 .cfi_rel_offset x5, 24
522
Zheng Xu48241e72014-05-23 11:52:42 +0800523 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700524 .cfi_rel_offset x29, 0
525 .cfi_rel_offset x30, 8
526
Zheng Xu48241e72014-05-23 11:52:42 +0800527 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700528 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800529 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700530
531 // Copy arguments into stack frame.
532 // Use simple copy routine for now.
533 // 4 bytes per slot.
534 // X1 - source address
535 // W2 - args length
536 // X9 - destination address.
537 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700538 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700539
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700540 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
541 // does not have unique-id variables.
5421:
Andreas Gampe03906cf2014-04-07 12:08:28 -0700543 cmp w2, #0
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700544 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700545 sub w2, w2, #4 // Need 65536 bytes of range.
546 ldr w10, [x1, x2]
547 str w10, [x9, x2]
548
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700549 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700550
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07005512:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700552 // Store null into ArtMethod* at bottom of frame.
553 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700554.endm
555
556.macro INVOKE_STUB_CALL_AND_RETURN
557
558 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700559 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700560 // Branch to method.
561 blr x9
562
563 // Restore return value address and shorty address.
564 ldp x4,x5, [xFP, #16]
565 .cfi_restore x4
566 .cfi_restore x5
567
Nicolas Geoffray48088462014-12-12 10:29:38 +0000568 ldr x28, [xFP, #112]
569 .cfi_restore x28
570
571 ldp x26, x27, [xFP, #96]
572 .cfi_restore x26
573 .cfi_restore x27
574
575 ldp x24, x25, [xFP, #80]
576 .cfi_restore x24
577 .cfi_restore x25
578
579 ldp x22, x23, [xFP, #64]
580 .cfi_restore x22
581 .cfi_restore x23
582
583 ldp x20, x21, [xFP, #48]
584 .cfi_restore x20
585 .cfi_restore x21
586
Andreas Gampe03906cf2014-04-07 12:08:28 -0700587 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
588 ldrb w10, [x5]
589
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700590 // Check the return type and store the correct register into the jvalue in memory.
591 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
592
Andreas Gampe03906cf2014-04-07 12:08:28 -0700593 // Don't set anything for a void type.
594 cmp w10, #'V'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700595 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700596
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700597 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700598 cmp w10, #'D'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700599 bne 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700600 str d0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700601 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700602
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006031: // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700604 cmp w10, #'F'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700605 bne 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700606 str s0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700607 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700608
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006092: // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700610 str x0, [x4]
611
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006123: // Finish up.
Zheng Xu69a50302015-04-14 20:04:41 +0800613 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700614 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700615 mov sp, x2
616 .cfi_restore sp
617
Andreas Gamped58342c2014-06-05 14:18:08 -0700618 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700619 .cfi_restore x29
620 .cfi_restore x30
621
622 ret
623
624.endm
625
626
Stuart Monteithb95a5342014-03-12 13:32:32 +0000627/*
628 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
629 * uint32_t *args, x1
630 * uint32_t argsize, w2
631 * Thread *self, x3
632 * JValue *result, x4
633 * char *shorty); x5
634 * +----------------------+
635 * | |
636 * | C/C++ frame |
637 * | LR'' |
638 * | FP'' | <- SP'
639 * +----------------------+
640 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800641 * | x28 | <- TODO: Remove callee-saves.
642 * | : |
643 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000644 * | SP' |
645 * | X5 |
646 * | X4 | Saved registers
647 * | LR' |
648 * | FP' | <- FP
649 * +----------------------+
650 * | uint32_t out[n-1] |
651 * | : : | Outs
652 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700653 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000654 * +----------------------+
655 *
656 * Outgoing registers:
657 * x0 - Method*
658 * x1-x7 - integer parameters.
659 * d0-d7 - Floating point parameters.
660 * xSELF = self
661 * SP = & of ArtMethod*
662 * x1 = "this" pointer.
663 *
664 */
665ENTRY art_quick_invoke_stub
666 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700667 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000668
669 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
670 // Parse the passed shorty to determine which register to load.
671 // Load addresses for routines that load WXSD registers.
672 adr x11, .LstoreW2
673 adr x12, .LstoreX2
674 adr x13, .LstoreS0
675 adr x14, .LstoreD0
676
677 // Initialize routine offsets to 0 for integers and floats.
678 // x8 for integers, x15 for floating point.
679 mov x8, #0
680 mov x15, #0
681
682 add x10, x5, #1 // Load shorty address, plus one to skip return value.
683 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
684
685 // Loop to fill registers.
686.LfillRegisters:
687 ldrb w17, [x10], #1 // Load next character in signature, and increment.
688 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
689
690 cmp w17, #'F' // is this a float?
691 bne .LisDouble
692
693 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700694 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000695
696 add x17, x13, x15 // Calculate subroutine to jump to.
697 br x17
698
699.LisDouble:
700 cmp w17, #'D' // is this a double?
701 bne .LisLong
702
703 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700704 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000705
706 add x17, x14, x15 // Calculate subroutine to jump to.
707 br x17
708
709.LisLong:
710 cmp w17, #'J' // is this a long?
711 bne .LisOther
712
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700713 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700714 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000715
716 add x17, x12, x8 // Calculate subroutine to jump to.
717 br x17
718
Stuart Monteithb95a5342014-03-12 13:32:32 +0000719.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700720 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700721 beq .Ladvance4
722
Stuart Monteithb95a5342014-03-12 13:32:32 +0000723 add x17, x11, x8 // Calculate subroutine to jump to.
724 br x17
725
Andreas Gampe03906cf2014-04-07 12:08:28 -0700726.Ladvance4:
727 add x9, x9, #4
728 b .LfillRegisters
729
730.Ladvance8:
731 add x9, x9, #8
732 b .LfillRegisters
733
Stuart Monteithb95a5342014-03-12 13:32:32 +0000734// Macro for loading a parameter into a register.
735// counter - the register with offset into these tables
736// size - the size of the register - 4 or 8 bytes.
737// register - the name of the register to be loaded.
738.macro LOADREG counter size register return
739 ldr \register , [x9], #\size
740 add \counter, \counter, 12
741 b \return
742.endm
743
744// Store ints.
745.LstoreW2:
746 LOADREG x8 4 w2 .LfillRegisters
747 LOADREG x8 4 w3 .LfillRegisters
748 LOADREG x8 4 w4 .LfillRegisters
749 LOADREG x8 4 w5 .LfillRegisters
750 LOADREG x8 4 w6 .LfillRegisters
751 LOADREG x8 4 w7 .LfillRegisters
752
753// Store longs.
754.LstoreX2:
755 LOADREG x8 8 x2 .LfillRegisters
756 LOADREG x8 8 x3 .LfillRegisters
757 LOADREG x8 8 x4 .LfillRegisters
758 LOADREG x8 8 x5 .LfillRegisters
759 LOADREG x8 8 x6 .LfillRegisters
760 LOADREG x8 8 x7 .LfillRegisters
761
762// Store singles.
763.LstoreS0:
764 LOADREG x15 4 s0 .LfillRegisters
765 LOADREG x15 4 s1 .LfillRegisters
766 LOADREG x15 4 s2 .LfillRegisters
767 LOADREG x15 4 s3 .LfillRegisters
768 LOADREG x15 4 s4 .LfillRegisters
769 LOADREG x15 4 s5 .LfillRegisters
770 LOADREG x15 4 s6 .LfillRegisters
771 LOADREG x15 4 s7 .LfillRegisters
772
773// Store doubles.
774.LstoreD0:
775 LOADREG x15 8 d0 .LfillRegisters
776 LOADREG x15 8 d1 .LfillRegisters
777 LOADREG x15 8 d2 .LfillRegisters
778 LOADREG x15 8 d3 .LfillRegisters
779 LOADREG x15 8 d4 .LfillRegisters
780 LOADREG x15 8 d5 .LfillRegisters
781 LOADREG x15 8 d6 .LfillRegisters
782 LOADREG x15 8 d7 .LfillRegisters
783
784
785.LcallFunction:
786
Andreas Gampe03906cf2014-04-07 12:08:28 -0700787 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000788
Stuart Monteithb95a5342014-03-12 13:32:32 +0000789END art_quick_invoke_stub
790
791/* extern"C"
792 * void art_quick_invoke_static_stub(ArtMethod *method, x0
793 * uint32_t *args, x1
794 * uint32_t argsize, w2
795 * Thread *self, x3
796 * JValue *result, x4
797 * char *shorty); x5
798 */
799ENTRY art_quick_invoke_static_stub
800 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700801 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000802
803 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
804 // Parse the passed shorty to determine which register to load.
805 // Load addresses for routines that load WXSD registers.
806 adr x11, .LstoreW1_2
807 adr x12, .LstoreX1_2
808 adr x13, .LstoreS0_2
809 adr x14, .LstoreD0_2
810
811 // Initialize routine offsets to 0 for integers and floats.
812 // x8 for integers, x15 for floating point.
813 mov x8, #0
814 mov x15, #0
815
816 add x10, x5, #1 // Load shorty address, plus one to skip return value.
817
818 // Loop to fill registers.
819.LfillRegisters2:
820 ldrb w17, [x10], #1 // Load next character in signature, and increment.
821 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
822
823 cmp w17, #'F' // is this a float?
824 bne .LisDouble2
825
826 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700827 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000828
829 add x17, x13, x15 // Calculate subroutine to jump to.
830 br x17
831
832.LisDouble2:
833 cmp w17, #'D' // is this a double?
834 bne .LisLong2
835
836 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700837 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000838
839 add x17, x14, x15 // Calculate subroutine to jump to.
840 br x17
841
842.LisLong2:
843 cmp w17, #'J' // is this a long?
844 bne .LisOther2
845
846 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700847 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000848
849 add x17, x12, x8 // Calculate subroutine to jump to.
850 br x17
851
Stuart Monteithb95a5342014-03-12 13:32:32 +0000852.LisOther2: // Everything else takes one vReg.
853 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700854 beq .Ladvance4_2
855
Stuart Monteithb95a5342014-03-12 13:32:32 +0000856 add x17, x11, x8 // Calculate subroutine to jump to.
857 br x17
858
Andreas Gampe03906cf2014-04-07 12:08:28 -0700859.Ladvance4_2:
860 add x9, x9, #4
861 b .LfillRegisters2
862
863.Ladvance8_2:
864 add x9, x9, #8
865 b .LfillRegisters2
866
Stuart Monteithb95a5342014-03-12 13:32:32 +0000867// Store ints.
868.LstoreW1_2:
869 LOADREG x8 4 w1 .LfillRegisters2
870 LOADREG x8 4 w2 .LfillRegisters2
871 LOADREG x8 4 w3 .LfillRegisters2
872 LOADREG x8 4 w4 .LfillRegisters2
873 LOADREG x8 4 w5 .LfillRegisters2
874 LOADREG x8 4 w6 .LfillRegisters2
875 LOADREG x8 4 w7 .LfillRegisters2
876
877// Store longs.
878.LstoreX1_2:
879 LOADREG x8 8 x1 .LfillRegisters2
880 LOADREG x8 8 x2 .LfillRegisters2
881 LOADREG x8 8 x3 .LfillRegisters2
882 LOADREG x8 8 x4 .LfillRegisters2
883 LOADREG x8 8 x5 .LfillRegisters2
884 LOADREG x8 8 x6 .LfillRegisters2
885 LOADREG x8 8 x7 .LfillRegisters2
886
887// Store singles.
888.LstoreS0_2:
889 LOADREG x15 4 s0 .LfillRegisters2
890 LOADREG x15 4 s1 .LfillRegisters2
891 LOADREG x15 4 s2 .LfillRegisters2
892 LOADREG x15 4 s3 .LfillRegisters2
893 LOADREG x15 4 s4 .LfillRegisters2
894 LOADREG x15 4 s5 .LfillRegisters2
895 LOADREG x15 4 s6 .LfillRegisters2
896 LOADREG x15 4 s7 .LfillRegisters2
897
898// Store doubles.
899.LstoreD0_2:
900 LOADREG x15 8 d0 .LfillRegisters2
901 LOADREG x15 8 d1 .LfillRegisters2
902 LOADREG x15 8 d2 .LfillRegisters2
903 LOADREG x15 8 d3 .LfillRegisters2
904 LOADREG x15 8 d4 .LfillRegisters2
905 LOADREG x15 8 d5 .LfillRegisters2
906 LOADREG x15 8 d6 .LfillRegisters2
907 LOADREG x15 8 d7 .LfillRegisters2
908
909
910.LcallFunction2:
911
Andreas Gampe03906cf2014-04-07 12:08:28 -0700912 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000913
Stuart Monteithb95a5342014-03-12 13:32:32 +0000914END art_quick_invoke_static_stub
915
Andreas Gampe03906cf2014-04-07 12:08:28 -0700916
Stuart Monteithb95a5342014-03-12 13:32:32 +0000917
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +0000918/* extern"C" void art_quick_osr_stub(void** stack, x0
919 * size_t stack_size_in_bytes, x1
920 * const uin8_t* native_pc, x2
921 * JValue *result, x3
922 * char *shorty, x4
923 * Thread *self) x5
924 */
925ENTRY art_quick_osr_stub
926SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
927 mov x9, sp // Save stack pointer.
928 .cfi_register sp,x9
929
930 sub x10, sp, # SAVE_SIZE
931 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
932 mov sp, x10 // Set new SP.
933
934 str x28, [sp, #112]
935 stp x26, x27, [sp, #96]
936 stp x24, x25, [sp, #80]
937 stp x22, x23, [sp, #64]
938 stp x20, x21, [sp, #48]
939 stp x9, x19, [sp, #32] // Save old stack pointer and x19.
940 stp x3, x4, [sp, #16] // Save result and shorty addresses.
941 stp xFP, xLR, [sp] // Store LR & FP.
942 mov xSELF, x5 // Move thread pointer into SELF register.
943
944 sub sp, sp, #16
945 str xzr, [sp] // Store null for ArtMethod* slot
946 // Branch to stub.
947 bl .Losr_entry
948 add sp, sp, #16
949
950 // Restore return value address and shorty address.
951 ldp x3,x4, [sp, #16]
952 ldr x28, [sp, #112]
953 ldp x26, x27, [sp, #96]
954 ldp x24, x25, [sp, #80]
955 ldp x22, x23, [sp, #64]
956 ldp x20, x21, [sp, #48]
957
958 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
959 ldrb w10, [x4]
960
961 // Check the return type and store the correct register into the jvalue in memory.
962
963 // Don't set anything for a void type.
964 cmp w10, #'V'
965 beq .Losr_exit
966
967 // Is it a double?
968 cmp w10, #'D'
969 bne .Lno_double
970 str d0, [x3]
971 b .Losr_exit
972
973.Lno_double: // Is it a float?
974 cmp w10, #'F'
975 bne .Lno_float
976 str s0, [x3]
977 b .Losr_exit
978
979.Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits.
980 str x0, [x3]
981
982.Losr_exit: // Finish up.
983 ldp x2, x19, [sp, #32] // Restore stack pointer and x19.
984 ldp xFP, xLR, [sp] // Restore old frame pointer and link register.
985 mov sp, x2
986 ret
987
988.Losr_entry:
989 // Update stack pointer for the callee
990 sub sp, sp, x1
991
992 // Update link register slot expected by the callee.
993 sub w1, w1, #8
994 str lr, [sp, x1]
995
996 // Copy arguments into stack frame.
997 // Use simple copy routine for now.
998 // 4 bytes per slot.
999 // X0 - source address
1000 // W1 - args length
1001 // SP - destination address.
1002 // W10 - temporary
1003.Losr_loop_entry:
1004 cmp w1, #0
1005 beq .Losr_loop_exit
1006 sub w1, w1, #4
1007 ldr w10, [x0, x1]
1008 str w10, [sp, x1]
1009 b .Losr_loop_entry
1010
1011.Losr_loop_exit:
1012 // Branch to the OSR entry point.
1013 br x2
1014
1015END art_quick_osr_stub
1016
Stuart Monteithb95a5342014-03-12 13:32:32 +00001017 /*
1018 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1019 */
1020
1021ENTRY art_quick_do_long_jump
1022 // Load FPRs
1023 ldp d0, d1, [x1], #16
1024 ldp d2, d3, [x1], #16
1025 ldp d4, d5, [x1], #16
1026 ldp d6, d7, [x1], #16
1027 ldp d8, d9, [x1], #16
1028 ldp d10, d11, [x1], #16
1029 ldp d12, d13, [x1], #16
1030 ldp d14, d15, [x1], #16
1031 ldp d16, d17, [x1], #16
1032 ldp d18, d19, [x1], #16
1033 ldp d20, d21, [x1], #16
1034 ldp d22, d23, [x1], #16
1035 ldp d24, d25, [x1], #16
1036 ldp d26, d27, [x1], #16
1037 ldp d28, d29, [x1], #16
1038 ldp d30, d31, [x1]
1039
1040 // Load GPRs
1041 // TODO: lots of those are smashed, could optimize.
1042 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001043 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001044 ldp x28, x29, [x0], #-16
1045 ldp x26, x27, [x0], #-16
1046 ldp x24, x25, [x0], #-16
1047 ldp x22, x23, [x0], #-16
1048 ldp x20, x21, [x0], #-16
1049 ldp x18, x19, [x0], #-16
1050 ldp x16, x17, [x0], #-16
1051 ldp x14, x15, [x0], #-16
1052 ldp x12, x13, [x0], #-16
1053 ldp x10, x11, [x0], #-16
1054 ldp x8, x9, [x0], #-16
1055 ldp x6, x7, [x0], #-16
1056 ldp x4, x5, [x0], #-16
1057 ldp x2, x3, [x0], #-16
1058 mov sp, x1
1059
Andreas Gampe639bdd12015-06-03 11:22:45 -07001060 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1061 ldr x1, [x0, #33*8]
1062 // And the value of x0.
1063 ldr x0, [x0]
1064
1065 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001066END art_quick_do_long_jump
1067
Andreas Gampef4e910b2014-04-29 16:55:52 -07001068 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001069 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1070 * possibly null object to lock.
1071 *
1072 * Derived from arm32 code.
1073 */
1074 .extern artLockObjectFromCode
1075ENTRY art_quick_lock_object
1076 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001077 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001078.Lretry_lock:
1079 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1080 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001081 mov x3, x1
1082 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1083 cbnz w3, .Lnot_unlocked // already thin locked
1084 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1085 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001086 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001087 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001088 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001089 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001090.Lnot_unlocked: // x1: original lock word
1091 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001092 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1093 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1094 uxth w2, w2 // zero top 16 bits
1095 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1096 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001097 mov x3, x1 // copy the lock word to check count overflow.
1098 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits.
1099 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow
1100 lsr w3, w2, LOCK_WORD_READ_BARRIER_STATE_SHIFT // if either of the upper two bits (28-29) are set, we overflowed.
1101 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1102 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1103 stxr w3, w2, [x4]
1104 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001105 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001106.Llock_stxr_fail:
1107 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001108.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001109 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001110 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001111 bl artLockObjectFromCode // (Object* obj, Thread*)
1112 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001113 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1114END art_quick_lock_object
1115
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001116ENTRY art_quick_lock_object_no_inline
1117 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
1118 mov x1, xSELF // pass Thread::Current
1119 bl artLockObjectFromCode // (Object* obj, Thread*)
1120 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1121 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1122END art_quick_lock_object_no_inline
1123
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001124 /*
1125 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1126 * x0 holds the possibly null object to lock.
1127 *
1128 * Derived from arm32 code.
1129 */
1130 .extern artUnlockObjectFromCode
1131ENTRY art_quick_unlock_object
1132 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001133 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1134.Lretry_unlock:
1135#ifndef USE_READ_BARRIER
1136 ldr w1, [x4]
1137#else
1138 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1139#endif
1140 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001141 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1142 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001143 mov x3, x1 // copy lock word to check thread id equality
1144 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1145 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001146 uxth w3, w3 // zero top 16 bits
1147 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001148 mov x3, x1 // copy lock word to detect transition to unlocked
1149 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1150 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001151 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001152 // transition to unlocked
1153 mov x3, x1
1154 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK // w3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -07001155 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001156#ifndef USE_READ_BARRIER
1157 str w3, [x4]
1158#else
1159 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1160 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1161#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001162 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001163.Lrecursive_thin_unlock: // w1: original lock word
1164 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1165#ifndef USE_READ_BARRIER
1166 str w1, [x4]
1167#else
1168 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1169 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1170#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001171 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001172.Lunlock_stxr_fail:
1173 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001174.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001175 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001176 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001177 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1178 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001179 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1180END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001181
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001182ENTRY art_quick_unlock_object_no_inline
1183 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
1184 mov x1, xSELF // pass Thread::Current
1185 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1186 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1187 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1188END art_quick_unlock_object_no_inline
1189
Andreas Gampe525cde22014-04-22 15:44:50 -07001190 /*
1191 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1192 * artThrowClassCastException.
1193 */
1194 .extern artThrowClassCastException
1195ENTRY art_quick_check_cast
1196 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001197 // Stack needs to be 16B aligned on calls.
1198 stp x0, x1, [sp,#-32]!
Andreas Gampe525cde22014-04-22 15:44:50 -07001199 .cfi_adjust_cfa_offset 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001200 .cfi_rel_offset x0, 0
1201 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001202 str xLR, [sp, #24]
Andreas Gampe525cde22014-04-22 15:44:50 -07001203 .cfi_rel_offset x30, 24
1204
1205 // Call runtime code
1206 bl artIsAssignableFromCode
1207
1208 // Check for exception
1209 cbz x0, .Lthrow_class_cast_exception
1210
1211 // Restore and return
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001212 ldr xLR, [sp, #24]
1213 .cfi_restore x30
1214 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001215 .cfi_restore x0
1216 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001217 .cfi_adjust_cfa_offset -32
1218 ret
1219
Andreas Gampe6b90d422015-06-26 19:49:24 -07001220 .cfi_adjust_cfa_offset 32 // Reset unwind info so following code unwinds.
1221
Andreas Gampe525cde22014-04-22 15:44:50 -07001222.Lthrow_class_cast_exception:
1223 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001224 ldr xLR, [sp, #24]
1225 .cfi_restore x30
1226 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001227 .cfi_restore x0
1228 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001229 .cfi_adjust_cfa_offset -32
1230
1231 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1232 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001233 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001234 brk 0 // We should not return here...
1235END art_quick_check_cast
1236
Man Cao1aee9002015-07-14 22:31:42 -07001237// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1238.macro POP_REG_NE xReg, offset, xExclude
1239 .ifnc \xReg, \xExclude
1240 ldr \xReg, [sp, #\offset] // restore xReg
1241 .cfi_restore \xReg
1242 .endif
1243.endm
1244
1245 /*
1246 * Macro to insert read barrier, only used in art_quick_aput_obj.
1247 * xDest, wDest and xObj are registers, offset is a defined literal such as
1248 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1249 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1250 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1251 */
1252.macro READ_BARRIER xDest, wDest, xObj, offset
1253#ifdef USE_READ_BARRIER
1254 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
1255 stp x0, x1, [sp, #-48]!
1256 .cfi_adjust_cfa_offset 48
1257 .cfi_rel_offset x0, 0
1258 .cfi_rel_offset x1, 8
1259 stp x2, x3, [sp, #16]
1260 .cfi_rel_offset x2, 16
1261 .cfi_rel_offset x3, 24
1262 stp x4, xLR, [sp, #32]
1263 .cfi_rel_offset x4, 32
1264 .cfi_rel_offset x30, 40
1265
Man Cao63069212015-08-21 15:51:39 -07001266 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001267 .ifnc \xObj, x1
1268 mov x1, \xObj // pass xObj
1269 .endif
1270 mov w2, #\offset // pass offset
1271 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1272 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1273 .ifnc \wDest, w0
1274 mov \wDest, w0 // save return value in wDest
1275 .endif
1276
1277 // Conditionally restore saved registers
1278 POP_REG_NE x0, 0, \xDest
1279 POP_REG_NE x1, 8, \xDest
1280 POP_REG_NE x2, 16, \xDest
1281 POP_REG_NE x3, 24, \xDest
1282 POP_REG_NE x4, 32, \xDest
1283 ldr xLR, [sp, #40]
1284 .cfi_restore x30
1285 add sp, sp, #48
1286 .cfi_adjust_cfa_offset -48
1287#else
1288 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1289 UNPOISON_HEAP_REF \wDest
1290#endif // USE_READ_BARRIER
1291.endm
1292
Andreas Gampef4e910b2014-04-29 16:55:52 -07001293 /*
1294 * Entry from managed code for array put operations of objects where the value being stored
1295 * needs to be checked for compatibility.
1296 * x0 = array, x1 = index, x2 = value
1297 *
1298 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1299 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1300 * using index-zero-extension in load/stores.
1301 *
1302 * Temporaries: x3, x4
1303 * TODO: x4 OK? ip seems wrong here.
1304 */
1305ENTRY art_quick_aput_obj_with_null_and_bound_check
1306 tst x0, x0
1307 bne art_quick_aput_obj_with_bound_check
1308 b art_quick_throw_null_pointer_exception
1309END art_quick_aput_obj_with_null_and_bound_check
1310
1311ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001312 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001313 cmp w3, w1
1314 bhi art_quick_aput_obj
1315 mov x0, x1
1316 mov x1, x3
1317 b art_quick_throw_array_bounds
1318END art_quick_aput_obj_with_bound_check
1319
Man Cao1aee9002015-07-14 22:31:42 -07001320#ifdef USE_READ_BARRIER
1321 .extern artReadBarrierSlow
1322#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001323ENTRY art_quick_aput_obj
1324 cbz x2, .Ldo_aput_null
Man Cao1aee9002015-07-14 22:31:42 -07001325 READ_BARRIER x3, w3, x0, MIRROR_OBJECT_CLASS_OFFSET // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001326 // This also zero-extends to x3
Man Cao1aee9002015-07-14 22:31:42 -07001327 READ_BARRIER x4, w4, x2, MIRROR_OBJECT_CLASS_OFFSET // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001328 // This also zero-extends to x4
Man Cao1aee9002015-07-14 22:31:42 -07001329 READ_BARRIER x3, w3, x3, MIRROR_CLASS_COMPONENT_TYPE_OFFSET // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001330 // This also zero-extends to x3
1331 cmp w3, w4 // value's type == array's component type - trivial assignability
1332 bne .Lcheck_assignability
1333.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001334 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001335 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001336 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001337 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1338 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1339 lsr x0, x0, #7
1340 strb w3, [x3, x0]
1341 ret
1342.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001343 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001344 // "Compress" = do nothing
1345 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1346 ret
1347.Lcheck_assignability:
1348 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001349 stp x0, x1, [sp,#-32]!
1350 .cfi_adjust_cfa_offset 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001351 .cfi_rel_offset x0, 0
1352 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001353 stp x2, xLR, [sp, #16]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001354 .cfi_rel_offset x2, 16
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001355 .cfi_rel_offset x30, 24
Andreas Gampef4e910b2014-04-29 16:55:52 -07001356
1357 // Call runtime code
1358 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1359 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1360 bl artIsAssignableFromCode
1361
1362 // Check for exception
1363 cbz x0, .Lthrow_array_store_exception
1364
1365 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001366 ldp x2, x30, [sp, #16]
1367 .cfi_restore x2
1368 .cfi_restore x30
1369 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001370 .cfi_restore x0
1371 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001372 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001373
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001374 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001375 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001376 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001377 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1378 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1379 lsr x0, x0, #7
1380 strb w3, [x3, x0]
1381 ret
Mathieu Chartier27386392015-06-27 15:42:27 -07001382 .cfi_adjust_cfa_offset 32 // 4 restores after cbz for unwinding.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001383.Lthrow_array_store_exception:
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001384 ldp x2, x30, [sp, #16]
1385 .cfi_restore x2
1386 .cfi_restore x30
1387 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001388 .cfi_restore x0
1389 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001390 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001391
1392 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1393 mov x1, x2 // Pass value.
1394 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001395 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001396 brk 0 // Unreached.
1397END art_quick_aput_obj
1398
Stuart Monteithb95a5342014-03-12 13:32:32 +00001399// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001400.macro ONE_ARG_DOWNCALL name, entrypoint, return
1401 .extern \entrypoint
1402ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001403 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001404 mov x1, xSELF // pass Thread::Current
1405 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1406 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1407 \return
1408END \name
1409.endm
1410
1411// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001412.macro TWO_ARG_DOWNCALL name, entrypoint, return
1413 .extern \entrypoint
1414ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001415 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001416 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001417 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1418 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001419 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001420END \name
1421.endm
1422
Jeff Hao848f70a2014-01-15 13:49:50 -08001423// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001424.macro THREE_ARG_DOWNCALL name, entrypoint, return
1425 .extern \entrypoint
1426ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001427 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001428 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001429 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001430 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001431 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001432END \name
1433.endm
1434
Jeff Hao848f70a2014-01-15 13:49:50 -08001435// Macro to facilitate adding new allocation entrypoints.
1436.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1437 .extern \entrypoint
1438ENTRY \name
1439 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1440 mov x4, xSELF // pass Thread::Current
1441 bl \entrypoint //
1442 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1443 \return
1444 DELIVER_PENDING_EXCEPTION
1445END \name
1446.endm
1447
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001448// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001449.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1450 .extern \entrypoint
1451ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001452 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001453 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001454 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001455 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001456 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001457 \return
1458END \name
1459.endm
1460
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001461.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1462 .extern \entrypoint
1463ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001464 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001465 ldr x2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001466 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001467 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001468 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001469 \return
1470END \name
1471.endm
1472
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001473.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1474 .extern \entrypoint
1475ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001476 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001477 ldr x3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001478 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001479 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001480 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001481 \return
1482END \name
1483.endm
1484
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001485.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1486 cbz w0, 1f // result zero branch over
1487 ret // return
14881:
1489 DELIVER_PENDING_EXCEPTION
1490.endm
1491
Matteo Franchindfd891a2014-04-30 12:17:17 +01001492 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001493 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1494 * failure.
1495 */
1496TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1497
1498 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001499 * Entry from managed code when uninitialized static storage, this stub will run the class
1500 * initializer and deliver the exception on error. On success the static storage base is
1501 * returned.
1502 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001503ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001504
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001505ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1506ONE_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 +01001507
Fred Shih37f05ef2014-07-16 18:38:08 -07001508ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1509ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1510ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1511ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001512ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1513ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1514ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1515
Fred Shih37f05ef2014-07-16 18:38:08 -07001516TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1517TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1518TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1519TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001520TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1521TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1522TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1523
Fred Shih37f05ef2014-07-16 18:38:08 -07001524TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1525TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001526TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1527TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1528
Fred Shih37f05ef2014-07-16 18:38:08 -07001529THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1530THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001531THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001532THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001533THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1534
1535// This is separated out as the argument order is different.
1536 .extern artSet64StaticFromCode
1537ENTRY art_quick_set64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001538 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001539 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Calin Juravlee460d1d2015-09-29 04:52:17 +01001540 // x2 contains the parameter
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001541 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001542 bl artSet64StaticFromCode
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001543 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001544 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1545END art_quick_set64_static
1546
Matteo Franchindfd891a2014-04-30 12:17:17 +01001547 /*
1548 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001549 * exception on error. On success the String is returned. w0 holds the string index. The fast
1550 * path check for hit in strings cache has already been performed.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001551 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001552ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001553
Stuart Monteithb95a5342014-03-12 13:32:32 +00001554// Generate the allocation entrypoints for each allocator.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001555GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001556
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001557// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1558ENTRY art_quick_alloc_object_rosalloc
1559 // Fast path rosalloc allocation.
1560 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1561 // x2-x7: free.
1562 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1563 // Load the class (x2)
1564 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1565 cbz x2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
1566 // Check class status.
1567 ldr w3, [x2, #MIRROR_CLASS_STATUS_OFFSET]
1568 cmp x3, #MIRROR_CLASS_STATUS_INITIALIZED
1569 bne .Lart_quick_alloc_object_rosalloc_slow_path
1570 // Add a fake dependence from the
1571 // following access flag and size
1572 // loads to the status load.
1573 // This is to prevent those loads
1574 // from being reordered above the
1575 // status load and reading wrong
1576 // values (an alternative is to use
1577 // a load-acquire for the status).
1578 eor x3, x3, x3
1579 add x2, x2, x3
1580 // Check access flags has
1581 // kAccClassIsFinalizable
1582 ldr w3, [x2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
1583 tst x3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE
1584 bne .Lart_quick_alloc_object_rosalloc_slow_path
1585 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1586 // allocation stack has room.
1587 // ldp won't work due to large offset.
1588 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1589 cmp x3, x4
1590 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1591 ldr w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (x3)
1592 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
1593 // local allocation
1594 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1595 // Compute the rosalloc bracket index
1596 // from the size.
1597 // Align up the size by the rosalloc
1598 // bracket quantum size and divide
1599 // by the quantum size and subtract
1600 // by 1. This code is a shorter but
1601 // equivalent version.
1602 sub x3, x3, #1
1603 lsr x3, x3, #ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT
1604 // Load the rosalloc run (x4)
1605 add x4, xSELF, x3, lsl #POINTER_SIZE_SHIFT
1606 ldr x4, [x4, #THREAD_ROSALLOC_RUNS_OFFSET]
1607 // Load the free list head (x3). This
1608 // will be the return val.
1609 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1610 cbz x3, .Lart_quick_alloc_object_rosalloc_slow_path
1611 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1612 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1613 // and update the list head with the
1614 // next pointer.
1615 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1616 // Store the class pointer in the
1617 // header. This also overwrites the
1618 // next pointer. The offsets are
1619 // asserted to match.
1620#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1621#error "Class pointer needs to overwrite next pointer."
1622#endif
1623 POISON_HEAP_REF w2
1624 str w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
1625 // Push the new object onto the thread
1626 // local allocation stack and
1627 // increment the thread local
1628 // allocation stack top.
1629 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1630 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1631 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1632 // Decrement the size of the free list
1633 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1634 sub x1, x1, #1
1635 // TODO: consider combining this store
1636 // and the list head store above using
1637 // strd.
1638 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1639 // Fence. This is "ish" not "ishst" so
1640 // that the code after this allocation
1641 // site will see the right values in
1642 // the fields of the class.
1643 // Alternatively we could use "ishst"
1644 // if we use load-acquire for the
1645 // class status load.)
1646 dmb ish
1647 mov x0, x3 // Set the return value and return.
1648 ret
1649.Lart_quick_alloc_object_rosalloc_slow_path:
1650 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1651 mov x2, xSELF // pass Thread::Current
1652 bl artAllocObjectFromCodeRosAlloc // (uint32_t type_idx, Method* method, Thread*)
1653 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1654 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1655END art_quick_alloc_object_rosalloc
Stuart Monteithb95a5342014-03-12 13:32:32 +00001656
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001657// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1658//
1659// x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current
1660// x3-x7: free.
1661// Need to preserve x0 and x1 to the slow path.
1662.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1663 cbz x2, \slowPathLabel // Check null class
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001664 // Check class status.
1665 ldr w3, [x2, #MIRROR_CLASS_STATUS_OFFSET]
1666 cmp x3, #MIRROR_CLASS_STATUS_INITIALIZED
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001667 bne \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001668 // Add a fake dependence from the
1669 // following access flag and size
1670 // loads to the status load.
1671 // This is to prevent those loads
1672 // from being reordered above the
1673 // status load and reading wrong
1674 // values (an alternative is to use
1675 // a load-acquire for the status).
1676 eor x3, x3, x3
1677 add x2, x2, x3
1678 // Check access flags has
1679 // kAccClassIsFinalizable.
1680 ldr w3, [x2, #MIRROR_CLASS_ACCESS_FLAGS_OFFSET]
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001681 tbnz x3, #ACCESS_FLAGS_CLASS_IS_FINALIZABLE_BIT, \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001682 // Load thread_local_pos (x4) and
1683 // thread_local_end (x5).
1684 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1685 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
1686 sub x6, x5, x4 // Compute the remaining buf size.
1687 ldr w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_OFFSET] // Load the object size (x7).
1688 cmp x7, x6 // Check if it fits. OK to do this
1689 // before rounding up the object size
1690 // assuming the buf size alignment.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001691 bhi \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001692 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1693 // Round up the object size by the
1694 // object alignment. (addr + 7) & ~7.
1695 add x7, x7, #OBJECT_ALIGNMENT_MASK
1696 and x7, x7, #OBJECT_ALIGNMENT_MASK_TOGGLED
1697 // Move old thread_local_pos to x0
1698 // for the return value.
1699 mov x0, x4
1700 add x5, x0, x7
1701 str x5, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1702 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1703 add x5, x5, #1
1704 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1705 POISON_HEAP_REF w2
1706 str w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1707 // Fence. This is "ish" not "ishst" so
1708 // that the code after this allocation
1709 // site will see the right values in
1710 // the fields of the class.
1711 // Alternatively we could use "ishst"
1712 // if we use load-acquire for the
1713 // class status load.)
1714 dmb ish
1715 ret
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001716.endm
1717
1718// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1719ENTRY art_quick_alloc_object_tlab
1720 // Fast path tlab allocation.
1721 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1722 // x2-x7: free.
1723#if defined(USE_READ_BARRIER)
1724 mvn x0, xzr // Read barrier not supported here.
1725 ret // Return -1.
1726#endif
1727 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1728 // Load the class (x2)
1729 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1730 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001731.Lart_quick_alloc_object_tlab_slow_path:
1732 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // Save callee saves in case of GC.
1733 mov x2, xSELF // Pass Thread::Current.
1734 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
1735 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1736 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1737END art_quick_alloc_object_tlab
1738
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001739// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1740ENTRY art_quick_alloc_object_region_tlab
1741 // Fast path region tlab allocation.
1742 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1743 // x2-x7: free.
1744#if !defined(USE_READ_BARRIER)
1745 mvn x0, xzr // Read barrier must be enabled here.
1746 ret // Return -1.
1747#endif
1748 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1749 // Load the class (x2)
1750 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1751 // Read barrier for class load.
1752 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1753 cbnz x3, .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path
1754.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit:
1755 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_region_tlab_slow_path
1756.Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path:
1757 // The read barrier slow path. Mark
1758 // the class.
1759 stp x0, x1, [sp, #-32]! // Save registers (x0, x1, lr).
1760 str xLR, [sp, #16] // Align sp by 16 bytes.
1761 mov x0, x2 // Pass the class as the first param.
1762 bl artReadBarrierMark
1763 mov x2, x0 // Get the (marked) class back.
1764 ldp x0, x1, [sp, #0] // Restore registers.
1765 ldr xLR, [sp, #16]
1766 add sp, sp, #32
1767 b .Lart_quick_alloc_object_region_tlab_class_load_read_barrier_slow_path_exit
1768.Lart_quick_alloc_object_region_tlab_slow_path:
1769 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // Save callee saves in case of GC.
1770 mov x2, xSELF // Pass Thread::Current.
1771 bl artAllocObjectFromCodeRegionTLAB // (uint32_t type_idx, Method* method, Thread*)
1772 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1773 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1774END art_quick_alloc_object_region_tlab
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001775
Zheng Xu48241e72014-05-23 11:52:42 +08001776 /*
Zheng Xu69a50302015-04-14 20:04:41 +08001777 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08001778 */
1779 .extern artTestSuspendFromCode
1780ENTRY art_quick_test_suspend
1781 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
Zheng Xu48241e72014-05-23 11:52:42 +08001782 cbnz w0, .Lneed_suspend // check flags == 0
1783 ret // return if flags == 0
1784.Lneed_suspend:
1785 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001786 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1787 bl artTestSuspendFromCode // (Thread*)
1788 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +08001789END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001790
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001791ENTRY art_quick_implicit_suspend
1792 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001793 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1794 bl artTestSuspendFromCode // (Thread*)
1795 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001796END art_quick_implicit_suspend
1797
Andreas Gampee62a07e2014-03-26 14:53:21 -07001798 /*
1799 * Called by managed code that is attempting to call a method on a proxy class. On entry
1800 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1801 * method agrees with a ref and args callee save frame.
1802 */
1803 .extern artQuickProxyInvokeHandler
1804ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001805 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001806 mov x2, xSELF // pass Thread::Current
1807 mov x3, sp // pass SP
1808 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001809 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001810 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001811 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07001812 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001813 ret // return on success
1814.Lexception_in_proxy:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001815 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001816 DELIVER_PENDING_EXCEPTION
1817END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001818
Andreas Gampe51f76352014-05-21 08:28:48 -07001819 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001820 * Called to resolve an imt conflict.
1821 * x0 is the conflict ArtMethod.
1822 * xIP1 is a hidden argument that holds the target interface method's dex method index.
1823 *
1824 * Note that this stub writes to xIP0, xIP1, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07001825 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001826 .extern artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07001827ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001828 ldr xIP0, [sp, #0] // Load referrer
1829 ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64] // Load dex cache methods array
1830 ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT] // Load interface method
1831 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
1832 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
1833.Limt_table_iterate:
1834 cmp x0, xIP0
1835 // Branch if found. Benchmarks have shown doing a branch here is better.
1836 beq .Limt_table_found
1837 // If the entry is null, the interface method is not in the ImtConflictTable.
1838 cbz x0, .Lconflict_trampoline
1839 // Iterate over the entries of the ImtConflictTable.
1840 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
1841 b .Limt_table_iterate
1842.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001843 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00001844 // and jump to it.
1845 ldr x0, [xIP1, #__SIZEOF_POINTER__]
1846 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
1847 br xIP0
1848.Lconflict_trampoline:
1849 // Call the runtime stub to populate the ImtConflictTable and jump to the
1850 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001851 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07001852END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001853
1854ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001855 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001856 mov x2, xSELF
1857 mov x3, sp
1858 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001859 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001860 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001861 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001862 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001863 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000018641:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001865 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001866 DELIVER_PENDING_EXCEPTION
1867END art_quick_resolution_trampoline
1868
1869/*
1870 * Generic JNI frame layout:
1871 *
1872 * #-------------------#
1873 * | |
1874 * | caller method... |
1875 * #-------------------# <--- SP on entry
1876 * | Return X30/LR |
1877 * | X29/FP | callee save
1878 * | X28 | callee save
1879 * | X27 | callee save
1880 * | X26 | callee save
1881 * | X25 | callee save
1882 * | X24 | callee save
1883 * | X23 | callee save
1884 * | X22 | callee save
1885 * | X21 | callee save
1886 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08001887 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001888 * | X7 | arg7
1889 * | X6 | arg6
1890 * | X5 | arg5
1891 * | X4 | arg4
1892 * | X3 | arg3
1893 * | X2 | arg2
1894 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001895 * | D7 | float arg 8
1896 * | D6 | float arg 7
1897 * | D5 | float arg 6
1898 * | D4 | float arg 5
1899 * | D3 | float arg 4
1900 * | D2 | float arg 3
1901 * | D1 | float arg 2
1902 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001903 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001904 * #-------------------#
1905 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001906 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001907 * #-------------------#
1908 * | JNI Call Stack |
1909 * #-------------------# <--- SP on native call
1910 * | |
1911 * | Stack for Regs | The trampoline assembly will pop these values
1912 * | | into registers for native call
1913 * #-------------------#
1914 * | Native code ptr |
1915 * #-------------------#
1916 * | Free scratch |
1917 * #-------------------#
1918 * | Ptr to (1) | <--- SP
1919 * #-------------------#
1920 */
1921 /*
1922 * Called to do a generic JNI down-call
1923 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001924ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001925 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001926
1927 // Save SP , so we can have static CFI info.
1928 mov x28, sp
1929 .cfi_def_cfa_register x28
1930
1931 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001932 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001933 mov xFP, sp
1934
Zheng Xub551fdc2014-07-25 11:49:42 +08001935 mov xIP0, #5120
1936 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001937
1938 // prepare for artQuickGenericJniTrampoline call
1939 // (Thread*, SP)
1940 // x0 x1 <= C calling convention
1941 // xSELF xFP <= where they are
1942
1943 mov x0, xSELF // Thread*
1944 mov x1, xFP
1945 bl artQuickGenericJniTrampoline // (Thread*, sp)
1946
Andreas Gampec200a4a2014-06-16 18:39:09 -07001947 // The C call will have registered the complete save-frame on success.
1948 // The result of the call is:
1949 // x0: pointer to native code, 0 on error.
1950 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001951
Andreas Gampec200a4a2014-06-16 18:39:09 -07001952 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001953 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00001954
Andreas Gampec200a4a2014-06-16 18:39:09 -07001955 // Release part of the alloca.
1956 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001957
Andreas Gampec200a4a2014-06-16 18:39:09 -07001958 // Save the code pointer
1959 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001960
1961 // Load parameters from frame into registers.
1962 // TODO Check with artQuickGenericJniTrampoline.
1963 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001964 ldp x0, x1, [sp]
1965 ldp x2, x3, [sp, #16]
1966 ldp x4, x5, [sp, #32]
1967 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001968
Andreas Gampec200a4a2014-06-16 18:39:09 -07001969 ldp d0, d1, [sp, #64]
1970 ldp d2, d3, [sp, #80]
1971 ldp d4, d5, [sp, #96]
1972 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001973
Andreas Gampec200a4a2014-06-16 18:39:09 -07001974 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001975
Zheng Xub551fdc2014-07-25 11:49:42 +08001976 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001977
1978 // result sign extension is handled in C code
1979 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001980 // (Thread*, result, result_f)
1981 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001982 mov x1, x0 // Result (from saved).
1983 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001984 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001985
1986 bl artQuickGenericJniEndTrampoline
1987
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001988 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001989 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001990 cbnz x2, .Lexception_in_native
1991
Stuart Monteithb95a5342014-03-12 13:32:32 +00001992 // Tear down the alloca.
1993 mov sp, x28
1994 .cfi_def_cfa_register sp
1995
Stuart Monteithb95a5342014-03-12 13:32:32 +00001996 // Tear down the callee-save frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001997 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001998
1999 // store into fpr, for when it's a fpr return...
2000 fmov d0, x0
2001 ret
2002
Stuart Monteithb95a5342014-03-12 13:32:32 +00002003.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002004 // Move to x1 then sp to please assembler.
2005 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
2006 mov sp, x1
2007 .cfi_def_cfa_register sp
2008 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002009 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002010END art_quick_generic_jni_trampoline
2011
2012/*
2013 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2014 * of a quick call:
2015 * x0 = method being called/to bridge to.
2016 * x1..x7, d0..d7 = arguments to that method.
2017 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002018ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002019 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002020
2021 // x0 will contain mirror::ArtMethod* method.
2022 mov x1, xSELF // How to get Thread::Current() ???
2023 mov x2, sp
2024
2025 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2026 // mirror::ArtMethod** sp)
2027 bl artQuickToInterpreterBridge
2028
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002029 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002030
2031 fmov d0, x0
2032
2033 RETURN_OR_DELIVER_PENDING_EXCEPTION
2034END art_quick_to_interpreter_bridge
2035
Andreas Gamped58342c2014-06-05 14:18:08 -07002036
2037//
2038// Instrumentation-related stubs
2039//
2040 .extern artInstrumentationMethodEntryFromCode
2041ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002042 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002043
Zheng Xub551fdc2014-07-25 11:49:42 +08002044 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002045
2046 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002047 mov x3, xLR
2048 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07002049
Zheng Xub551fdc2014-07-25 11:49:42 +08002050 mov xIP0, x0 // x0 = result of call.
2051 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002052
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002053 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07002054 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002055 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07002056END art_quick_instrumentation_entry
2057
2058 .extern artInstrumentationMethodExitFromCode
2059ENTRY art_quick_instrumentation_exit
2060 mov xLR, #0 // Clobber LR for later checks.
2061
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002062 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002063
2064 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
2065 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
2066 // easier to have an extra small stack area.
2067
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002068 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07002069 .cfi_adjust_cfa_offset 16
2070 str d0, [sp, #8] // Save floating-point result.
2071
Andreas Gamped58342c2014-06-05 14:18:08 -07002072 add x1, sp, #16 // Pass SP.
2073 mov x2, x0 // Pass integer result.
2074 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002075 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07002076 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
2077
Zheng Xub551fdc2014-07-25 11:49:42 +08002078 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07002079 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
2080
2081 ldr d0, [sp, #8] // Restore floating-point result.
2082 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
2083 .cfi_adjust_cfa_offset 16
2084
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002085 POP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002086
Zheng Xub551fdc2014-07-25 11:49:42 +08002087 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07002088END art_quick_instrumentation_exit
2089
2090 /*
2091 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2092 * will long jump to the upcall with a special exception of -1.
2093 */
2094 .extern artDeoptimize
2095ENTRY art_quick_deoptimize
2096 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
2097 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002098 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002099 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002100END art_quick_deoptimize
2101
Sebastien Hertz07474662015-08-25 15:12:33 +00002102 /*
2103 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2104 * will long jump to the upcall with a special exception of -1.
2105 */
2106 .extern artDeoptimizeFromCompiledCode
2107ENTRY art_quick_deoptimize_from_compiled_code
2108 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
2109 mov x0, xSELF // Pass thread.
2110 bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*)
2111 brk 0
2112END art_quick_deoptimize_from_compiled_code
2113
Andreas Gamped58342c2014-06-05 14:18:08 -07002114
Serban Constantinescu169489b2014-06-11 16:43:35 +01002115 /*
2116 * String's indexOf.
2117 *
2118 * TODO: Not very optimized.
2119 * On entry:
2120 * x0: string object (known non-null)
2121 * w1: char to match (known <= 0xFFFF)
2122 * w2: Starting offset in string data
2123 */
2124ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002125 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08002126 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01002127
2128 /* Clamp start to [0..count] */
2129 cmp w2, #0
2130 csel w2, wzr, w2, lt
2131 cmp w2, w3
2132 csel w2, w3, w2, gt
2133
Serban Constantinescu169489b2014-06-11 16:43:35 +01002134 /* Save a copy to compute result */
2135 mov x5, x0
2136
2137 /* Build pointer to start of data to compare and pre-bias */
2138 add x0, x0, x2, lsl #1
2139 sub x0, x0, #2
2140
2141 /* Compute iteration count */
2142 sub w2, w3, w2
2143
2144 /*
2145 * At this point we have:
2146 * x0: start of the data to test
2147 * w1: char to compare
2148 * w2: iteration count
2149 * x5: original start of string data
2150 */
2151
2152 subs w2, w2, #4
2153 b.lt .Lindexof_remainder
2154
2155.Lindexof_loop4:
2156 ldrh w6, [x0, #2]!
2157 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002158 ldrh wIP0, [x0, #2]!
2159 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002160 cmp w6, w1
2161 b.eq .Lmatch_0
2162 cmp w7, w1
2163 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002164 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002165 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002166 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002167 b.eq .Lmatch_3
2168 subs w2, w2, #4
2169 b.ge .Lindexof_loop4
2170
2171.Lindexof_remainder:
2172 adds w2, w2, #4
2173 b.eq .Lindexof_nomatch
2174
2175.Lindexof_loop1:
2176 ldrh w6, [x0, #2]!
2177 cmp w6, w1
2178 b.eq .Lmatch_3
2179 subs w2, w2, #1
2180 b.ne .Lindexof_loop1
2181
2182.Lindexof_nomatch:
2183 mov x0, #-1
2184 ret
2185
2186.Lmatch_0:
2187 sub x0, x0, #6
2188 sub x0, x0, x5
2189 asr x0, x0, #1
2190 ret
2191.Lmatch_1:
2192 sub x0, x0, #4
2193 sub x0, x0, x5
2194 asr x0, x0, #1
2195 ret
2196.Lmatch_2:
2197 sub x0, x0, #2
2198 sub x0, x0, x5
2199 asr x0, x0, #1
2200 ret
2201.Lmatch_3:
2202 sub x0, x0, x5
2203 asr x0, x0, #1
2204 ret
2205END art_quick_indexof