blob: ea4669df185f02ced51cd6bc9af9d8581bbb3a2c [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
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010022.macro INCREASE_FRAME frame_adjustment
23 sub sp, sp, #(\frame_adjustment)
24 .cfi_adjust_cfa_offset (\frame_adjustment)
25.endm
26
27.macro DECREASE_FRAME frame_adjustment
28 add sp, sp, #(\frame_adjustment)
29 .cfi_adjust_cfa_offset -(\frame_adjustment)
30.endm
31
Vladimir Marko215076b2016-09-07 18:05:55 +010032.macro SAVE_REG reg, offset
33 str \reg, [sp, #(\offset)]
34 .cfi_rel_offset \reg, (\offset)
35.endm
36
37.macro RESTORE_REG reg, offset
38 ldr \reg, [sp, #(\offset)]
39 .cfi_restore \reg
40.endm
41
42.macro SAVE_TWO_REGS reg1, reg2, offset
43 stp \reg1, \reg2, [sp, #(\offset)]
44 .cfi_rel_offset \reg1, (\offset)
45 .cfi_rel_offset \reg2, (\offset) + 8
46.endm
47
48.macro RESTORE_TWO_REGS reg1, reg2, offset
49 ldp \reg1, \reg2, [sp, #(\offset)]
50 .cfi_restore \reg1
51 .cfi_restore \reg2
52.endm
53
54.macro SAVE_TWO_REGS_INCREASE_FRAME reg1, reg2, frame_adjustment
55 stp \reg1, \reg2, [sp, #-(\frame_adjustment)]!
56 .cfi_adjust_cfa_offset (\frame_adjustment)
57 .cfi_rel_offset \reg1, 0
58 .cfi_rel_offset \reg2, 8
59.endm
60
61.macro RESTORE_TWO_REGS_DECREASE_FRAME reg1, reg2, frame_adjustment
62 ldp \reg1, \reg2, [sp], #(\frame_adjustment)
63 .cfi_restore \reg1
64 .cfi_restore \reg2
65 .cfi_adjust_cfa_offset -(\frame_adjustment)
66.endm
67
Stuart Monteithb95a5342014-03-12 13:32:32 +000068 /*
69 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010070 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Stuart Monteithb95a5342014-03-12 13:32:32 +000071 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010072.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
73 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +080074 adrp xIP0, :got:_ZN3art7Runtime9instance_E
75 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000076
77 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010078 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +000079
Vladimir Markofd36f1f2016-08-03 18:49:58 +010080 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves];
81 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070082
Vladimir Markoae6ba1f2016-09-09 11:56:05 +010083 INCREASE_FRAME 176
Andreas Gampe5c1e4352014-04-21 19:28:24 -070084
85 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010086#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176)
87#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070088#endif
89
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010090 // Stack alignment filler [sp, #8].
91 // FP callee-saves.
92 stp d8, d9, [sp, #16]
93 stp d10, d11, [sp, #32]
94 stp d12, d13, [sp, #48]
95 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070096
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010097 // GP callee-saves
Vladimir Marko215076b2016-09-07 18:05:55 +010098 SAVE_TWO_REGS x19, x20, 80
99 SAVE_TWO_REGS x21, x22, 96
100 SAVE_TWO_REGS x23, x24, 112
101 SAVE_TWO_REGS x25, x26, 128
102 SAVE_TWO_REGS x27, x28, 144
103 SAVE_TWO_REGS x29, xLR, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700104
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100105 // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100106 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700107 // Place sp in Thread::Current()->top_quick_frame.
108 mov xIP0, sp
109 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000110.endm
111
Zheng Xub551fdc2014-07-25 11:49:42 +0800112 /*
113 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100114 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly).
Zheng Xub551fdc2014-07-25 11:49:42 +0800115 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100116.macro SETUP_SAVE_REFS_ONLY_FRAME
117 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800118 adrp xIP0, :got:_ZN3art7Runtime9instance_E
119 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
120
121 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100122 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Zheng Xub551fdc2014-07-25 11:49:42 +0800123
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100124 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly];
125 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800126
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100127 INCREASE_FRAME 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800128
129 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100130#if (FRAME_SIZE_SAVE_REFS_ONLY != 96)
131#error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected."
Zheng Xub551fdc2014-07-25 11:49:42 +0800132#endif
133
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100134 // GP callee-saves.
135 // x20 paired with ArtMethod* - see below.
Vladimir Marko215076b2016-09-07 18:05:55 +0100136 SAVE_TWO_REGS x21, x22, 16
137 SAVE_TWO_REGS x23, x24, 32
138 SAVE_TWO_REGS x25, x26, 48
139 SAVE_TWO_REGS x27, x28, 64
140 SAVE_TWO_REGS x29, xLR, 80
Zheng Xub551fdc2014-07-25 11:49:42 +0800141
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100142 // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly].
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100143 stp xIP0, x20, [sp]
144 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800145
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700146 // Place sp in Thread::Current()->top_quick_frame.
147 mov xIP0, sp
148 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800149.endm
150
151// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100152.macro RESTORE_SAVE_REFS_ONLY_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100153 // Callee-saves.
Vladimir Marko215076b2016-09-07 18:05:55 +0100154 RESTORE_REG x20, 8
155 RESTORE_TWO_REGS x21, x22, 16
156 RESTORE_TWO_REGS x23, x24, 32
157 RESTORE_TWO_REGS x25, x26, 48
158 RESTORE_TWO_REGS x27, x28, 64
159 RESTORE_TWO_REGS x29, xLR, 80
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700160
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100161 DECREASE_FRAME 96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000162.endm
163
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100164.macro POP_SAVE_REFS_ONLY_FRAME
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100165 DECREASE_FRAME 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700166.endm
167
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100168.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
169 RESTORE_SAVE_REFS_ONLY_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800170 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000171.endm
172
173
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100174.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100175 INCREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000176
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700177 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100178#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224)
179#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700180#endif
181
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100182 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800183 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100184 stp d0, d1, [sp, #16]
185 stp d2, d3, [sp, #32]
186 stp d4, d5, [sp, #48]
187 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000188
Zheng Xu69a50302015-04-14 20:04:41 +0800189 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100190 SAVE_TWO_REGS x1, x2, 80
191 SAVE_TWO_REGS x3, x4, 96
192 SAVE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700193
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100194 // x7, Callee-saves.
Vladimir Marko215076b2016-09-07 18:05:55 +0100195 SAVE_TWO_REGS x7, x20, 128
196 SAVE_TWO_REGS x21, x22, 144
197 SAVE_TWO_REGS x23, x24, 160
198 SAVE_TWO_REGS x25, x26, 176
199 SAVE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700200
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100201 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100202 SAVE_TWO_REGS x29, xLR, 208
Andreas Gampe03906cf2014-04-07 12:08:28 -0700203
Stuart Monteithb95a5342014-03-12 13:32:32 +0000204.endm
205
206 /*
207 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100208 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000209 *
210 * TODO This is probably too conservative - saving FP & LR.
211 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100212.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
213 // art::Runtime** xIP0 = &art::Runtime::instance_
Zheng Xub551fdc2014-07-25 11:49:42 +0800214 adrp xIP0, :got:_ZN3art7Runtime9instance_E
215 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000216
217 // Our registers aren't intermixed - just spill in order.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100218 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000219
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100220 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs];
221 ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000222
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100223 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000224
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100225 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs].
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700226 // Place sp in Thread::Current()->top_quick_frame.
227 mov xIP0, sp
228 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
229.endm
230
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100231.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
232 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700233 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
234 // Place sp in Thread::Current()->top_quick_frame.
235 mov xIP0, sp
236 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000237.endm
238
Zheng Xub551fdc2014-07-25 11:49:42 +0800239// TODO: Probably no need to restore registers preserved by aapcs64.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100240.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800241 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100242 ldp d0, d1, [sp, #16]
243 ldp d2, d3, [sp, #32]
244 ldp d4, d5, [sp, #48]
245 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000246
Zheng Xu69a50302015-04-14 20:04:41 +0800247 // Core args.
Vladimir Marko215076b2016-09-07 18:05:55 +0100248 RESTORE_TWO_REGS x1, x2, 80
249 RESTORE_TWO_REGS x3, x4, 96
250 RESTORE_TWO_REGS x5, x6, 112
Andreas Gampe03906cf2014-04-07 12:08:28 -0700251
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100252 // x7, Callee-saves.
Vladimir Marko215076b2016-09-07 18:05:55 +0100253 RESTORE_TWO_REGS x7, x20, 128
254 RESTORE_TWO_REGS x21, x22, 144
255 RESTORE_TWO_REGS x23, x24, 160
256 RESTORE_TWO_REGS x25, x26, 176
257 RESTORE_TWO_REGS x27, x28, 192
Andreas Gampe03906cf2014-04-07 12:08:28 -0700258
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100259 // x29(callee-save) and LR.
Vladimir Marko215076b2016-09-07 18:05:55 +0100260 RESTORE_TWO_REGS x29, xLR, 208
Stuart Monteithb95a5342014-03-12 13:32:32 +0000261
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100262 DECREASE_FRAME 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000263.endm
264
Vladimir Marko952dbb12016-07-28 12:01:51 +0100265 /*
266 * Macro that sets up the callee save frame to conform with
267 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
Vladimir Marko7aa75602016-09-07 15:09:21 +0100268 * when the SP has already been decremented by FRAME_SIZE_SAVE_EVERYTHING
269 * and saving registers x29 and LR is handled elsewhere.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100270 */
Vladimir Marko7aa75602016-09-07 15:09:21 +0100271.macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
Vladimir Marko952dbb12016-07-28 12:01:51 +0100272 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100273#if (FRAME_SIZE_SAVE_EVERYTHING != 512)
274#error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100275#endif
276
277 // Save FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100278 // For better performance, store d0 and d31 separately, so that all STPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100279 str d0, [sp, #8]
280 stp d1, d2, [sp, #16]
281 stp d3, d4, [sp, #32]
282 stp d5, d6, [sp, #48]
283 stp d7, d8, [sp, #64]
284 stp d9, d10, [sp, #80]
285 stp d11, d12, [sp, #96]
286 stp d13, d14, [sp, #112]
287 stp d15, d16, [sp, #128]
288 stp d17, d18, [sp, #144]
289 stp d19, d20, [sp, #160]
290 stp d21, d22, [sp, #176]
291 stp d23, d24, [sp, #192]
292 stp d25, d26, [sp, #208]
293 stp d27, d28, [sp, #224]
294 stp d29, d30, [sp, #240]
295 str d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100296
297 // Save core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +0100298 SAVE_REG x0, 264
299 SAVE_TWO_REGS x1, x2, 272
300 SAVE_TWO_REGS x3, x4, 288
301 SAVE_TWO_REGS x5, x6, 304
302 SAVE_TWO_REGS x7, x8, 320
303 SAVE_TWO_REGS x9, x10, 336
304 SAVE_TWO_REGS x11, x12, 352
305 SAVE_TWO_REGS x13, x14, 368
306 SAVE_TWO_REGS x15, x16, 384
307 SAVE_TWO_REGS x17, x18, 400
308 SAVE_TWO_REGS x19, x20, 416
309 SAVE_TWO_REGS x21, x22, 432
310 SAVE_TWO_REGS x23, x24, 448
311 SAVE_TWO_REGS x25, x26, 464
312 SAVE_TWO_REGS x27, x28, 480
Vladimir Marko952dbb12016-07-28 12:01:51 +0100313
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100314 // art::Runtime** xIP0 = &art::Runtime::instance_
Vladimir Marko952dbb12016-07-28 12:01:51 +0100315 adrp xIP0, :got:_ZN3art7Runtime9instance_E
316 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
317
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100318 ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_;
Vladimir Marko952dbb12016-07-28 12:01:51 +0100319
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100320 // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything];
321 ldr xIP0, [xIP0, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100322
323 // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything].
324 str xIP0, [sp]
325 // Place sp in Thread::Current()->top_quick_frame.
326 mov xIP0, sp
327 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
328.endm
329
Vladimir Marko7aa75602016-09-07 15:09:21 +0100330 /*
331 * Macro that sets up the callee save frame to conform with
332 * Runtime::CreateCalleeSaveMethod(kSaveEverything)
333 */
334.macro SETUP_SAVE_EVERYTHING_FRAME
335 INCREASE_FRAME 512
336 SAVE_TWO_REGS x29, xLR, 496
337 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
338.endm
339
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100340.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100341 // Restore FP registers.
Vladimir Marko40df7c12016-08-22 16:02:12 +0100342 // For better performance, load d0 and d31 separately, so that all LDPs are 16-byte aligned.
Vladimir Markode5f1942016-08-10 12:30:05 +0100343 ldr d0, [sp, #8]
344 ldp d1, d2, [sp, #16]
345 ldp d3, d4, [sp, #32]
346 ldp d5, d6, [sp, #48]
347 ldp d7, d8, [sp, #64]
348 ldp d9, d10, [sp, #80]
349 ldp d11, d12, [sp, #96]
350 ldp d13, d14, [sp, #112]
351 ldp d15, d16, [sp, #128]
352 ldp d17, d18, [sp, #144]
353 ldp d19, d20, [sp, #160]
354 ldp d21, d22, [sp, #176]
355 ldp d23, d24, [sp, #192]
356 ldp d25, d26, [sp, #208]
357 ldp d27, d28, [sp, #224]
358 ldp d29, d30, [sp, #240]
359 ldr d31, [sp, #256]
Vladimir Marko952dbb12016-07-28 12:01:51 +0100360
361 // Restore core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +0100362 RESTORE_REG x0, 264
363 RESTORE_TWO_REGS x1, x2, 272
364 RESTORE_TWO_REGS x3, x4, 288
365 RESTORE_TWO_REGS x5, x6, 304
366 RESTORE_TWO_REGS x7, x8, 320
367 RESTORE_TWO_REGS x9, x10, 336
368 RESTORE_TWO_REGS x11, x12, 352
369 RESTORE_TWO_REGS x13, x14, 368
370 RESTORE_TWO_REGS x15, x16, 384
371 RESTORE_TWO_REGS x17, x18, 400
372 RESTORE_TWO_REGS x19, x20, 416
373 RESTORE_TWO_REGS x21, x22, 432
374 RESTORE_TWO_REGS x23, x24, 448
375 RESTORE_TWO_REGS x25, x26, 464
376 RESTORE_TWO_REGS x27, x28, 480
377 RESTORE_TWO_REGS x29, xLR, 496
Vladimir Marko952dbb12016-07-28 12:01:51 +0100378
Vladimir Markoae6ba1f2016-09-09 11:56:05 +0100379 DECREASE_FRAME 512
Vladimir Marko952dbb12016-07-28 12:01:51 +0100380.endm
381
Stuart Monteithb95a5342014-03-12 13:32:32 +0000382.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700383 cbnz x0, 1f // result non-zero branch over
384 ret // return
3851:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000386.endm
387
388.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700389 cbz x0, 1f // result zero branch over
390 ret // return
3911:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000392.endm
393
394 /*
395 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
396 * exception is Thread::Current()->exception_
397 */
398.macro DELIVER_PENDING_EXCEPTION
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100399 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000400 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000401
402 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700403 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000404 brk 0 // Unreached
405.endm
406
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700407.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
408 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
409 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000410 ret
4111:
412 DELIVER_PENDING_EXCEPTION
413.endm
414
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700415.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800416 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700417.endm
418
419// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
420.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
421 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
422.endm
423
424.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
425 cbnz w0, 1f // result non-zero branch over
426 ret // return
4271:
428 DELIVER_PENDING_EXCEPTION
429.endm
430
Stuart Monteithb95a5342014-03-12 13:32:32 +0000431.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
432 .extern \cxx_name
433ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100434 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800435 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700436 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000437END \c_name
438.endm
439
440.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
441 .extern \cxx_name
442ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100443 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800444 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700445 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000446 brk 0
447END \c_name
448.endm
449
450.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
451 .extern \cxx_name
452ENTRY \c_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100453 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800454 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700455 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000456 brk 0
457END \c_name
458.endm
459
460 /*
461 * Called by managed code, saves callee saves and then calls artThrowException
462 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
463 */
464ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
465
466 /*
467 * Called by managed code to create and deliver a NullPointerException.
468 */
469NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
470
471 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100472 * Call installed by a signal handler to create and deliver a NullPointerException.
473 */
Vladimir Marko7aa75602016-09-07 15:09:21 +0100474 .extern art_quick_throw_null_pointer_exception_from_signal
475ENTRY art_quick_throw_null_pointer_exception_from_signal
476 // The fault handler pushes the gc map address, i.e. "return address", to stack
477 // and passes the fault address in LR. So we need to set up the CFI info accordingly.
478 .cfi_def_cfa_offset __SIZEOF_POINTER__
479 .cfi_rel_offset lr, 0
480 // Save all registers as basis for long jump context.
481 INCREASE_FRAME (FRAME_SIZE_SAVE_EVERYTHING - __SIZEOF_POINTER__)
482 SAVE_REG x29, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__) // LR already saved.
483 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR
484 mov x0, lr // pass the fault address stored in LR by the fault handler.
485 mov x1, xSELF // pass Thread::Current.
486 b artThrowNullPointerExceptionFromSignal // (arg, Thread*).
487 brk 0
488END art_quick_throw_null_pointer_exception_from_signal
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100489
490 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000491 * Called by managed code to create and deliver an ArithmeticException.
492 */
493NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
494
495 /*
496 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
497 * index, arg2 holds limit.
498 */
499TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
500
501 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100502 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
503 * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit.
504 */
505TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode
506
507 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000508 * Called by managed code to create and deliver a StackOverflowError.
509 */
510NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
511
512 /*
513 * Called by managed code to create and deliver a NoSuchMethodError.
514 */
515ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
516
517 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000518 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700519 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100520 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700521 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000522 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700523 * 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 +0000524 * of the target Method* in x0 and method->code_ in x1.
525 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700526 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000527 * thread and we branch to another stub to deliver it.
528 *
529 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
530 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700531 *
532 * Adapted from ARM32 code.
533 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800534 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000535 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700536.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000537 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100538 SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700539 // Helper signature is always
540 // (method_idx, *this_object, *caller_method, *self, sp)
541
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100542 mov x2, xSELF // pass Thread::Current
543 mov x3, sp
544 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800545 mov xIP0, x1 // save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100546 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700547 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800548 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07005491:
550 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700551.endm
552.macro INVOKE_TRAMPOLINE c_name, cxx_name
553ENTRY \c_name
554 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000555END \c_name
556.endm
557
Stuart Monteithb95a5342014-03-12 13:32:32 +0000558INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
559
560INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
561INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
562INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
563INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
564
Andreas Gampe03906cf2014-04-07 12:08:28 -0700565
566.macro INVOKE_STUB_CREATE_FRAME
567
Zheng Xu69a50302015-04-14 20:04:41 +0800568SAVE_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 -0700569SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
Andreas Gampecf4035a2014-05-28 22:43:01 -0700570
Andreas Gampe03906cf2014-04-07 12:08:28 -0700571
Zheng Xu48241e72014-05-23 11:52:42 +0800572 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700573 .cfi_register sp,x9
574
Zheng Xu48241e72014-05-23 11:52:42 +0800575 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700576 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
Zheng Xu48241e72014-05-23 11:52:42 +0800577 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
578 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700579
Zheng Xu48241e72014-05-23 11:52:42 +0800580 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
581 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700582 .cfi_adjust_cfa_offset SAVE_SIZE
583
Nicolas Geoffray48088462014-12-12 10:29:38 +0000584 str x28, [x10, #112]
585 .cfi_rel_offset x28, 112
586
587 stp x26, x27, [x10, #96]
588 .cfi_rel_offset x26, 96
589 .cfi_rel_offset x27, 104
590
591 stp x24, x25, [x10, #80]
592 .cfi_rel_offset x24, 80
593 .cfi_rel_offset x25, 88
594
595 stp x22, x23, [x10, #64]
596 .cfi_rel_offset x22, 64
597 .cfi_rel_offset x23, 72
598
599 stp x20, x21, [x10, #48]
600 .cfi_rel_offset x20, 48
601 .cfi_rel_offset x21, 56
602
Zheng Xu69a50302015-04-14 20:04:41 +0800603 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700604 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700605 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700606
Zheng Xu48241e72014-05-23 11:52:42 +0800607 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700608 .cfi_rel_offset x4, 16
609 .cfi_rel_offset x5, 24
610
Zheng Xu48241e72014-05-23 11:52:42 +0800611 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700612 .cfi_rel_offset x29, 0
613 .cfi_rel_offset x30, 8
614
Zheng Xu48241e72014-05-23 11:52:42 +0800615 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700616 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800617 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700618
619 // Copy arguments into stack frame.
620 // Use simple copy routine for now.
621 // 4 bytes per slot.
622 // X1 - source address
623 // W2 - args length
624 // X9 - destination address.
625 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700626 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700627
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700628 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
629 // does not have unique-id variables.
6301:
Andreas Gampe03906cf2014-04-07 12:08:28 -0700631 cmp w2, #0
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700632 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700633 sub w2, w2, #4 // Need 65536 bytes of range.
634 ldr w10, [x1, x2]
635 str w10, [x9, x2]
636
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700637 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700638
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006392:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700640 // Store null into ArtMethod* at bottom of frame.
641 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700642.endm
643
644.macro INVOKE_STUB_CALL_AND_RETURN
645
646 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700647 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700648 // Branch to method.
649 blr x9
650
651 // Restore return value address and shorty address.
652 ldp x4,x5, [xFP, #16]
653 .cfi_restore x4
654 .cfi_restore x5
655
Nicolas Geoffray48088462014-12-12 10:29:38 +0000656 ldr x28, [xFP, #112]
657 .cfi_restore x28
658
659 ldp x26, x27, [xFP, #96]
660 .cfi_restore x26
661 .cfi_restore x27
662
663 ldp x24, x25, [xFP, #80]
664 .cfi_restore x24
665 .cfi_restore x25
666
667 ldp x22, x23, [xFP, #64]
668 .cfi_restore x22
669 .cfi_restore x23
670
671 ldp x20, x21, [xFP, #48]
672 .cfi_restore x20
673 .cfi_restore x21
674
Andreas Gampe03906cf2014-04-07 12:08:28 -0700675 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
676 ldrb w10, [x5]
677
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700678 // Check the return type and store the correct register into the jvalue in memory.
679 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
680
Andreas Gampe03906cf2014-04-07 12:08:28 -0700681 // Don't set anything for a void type.
682 cmp w10, #'V'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700683 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700684
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700685 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700686 cmp w10, #'D'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700687 bne 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700688 str d0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700689 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700690
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006911: // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700692 cmp w10, #'F'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700693 bne 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700694 str s0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700695 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700696
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006972: // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700698 str x0, [x4]
699
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07007003: // Finish up.
Zheng Xu69a50302015-04-14 20:04:41 +0800701 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700702 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700703 mov sp, x2
704 .cfi_restore sp
705
Andreas Gamped58342c2014-06-05 14:18:08 -0700706 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700707 .cfi_restore x29
708 .cfi_restore x30
709
710 ret
711
712.endm
713
714
Stuart Monteithb95a5342014-03-12 13:32:32 +0000715/*
716 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
717 * uint32_t *args, x1
718 * uint32_t argsize, w2
719 * Thread *self, x3
720 * JValue *result, x4
721 * char *shorty); x5
722 * +----------------------+
723 * | |
724 * | C/C++ frame |
725 * | LR'' |
726 * | FP'' | <- SP'
727 * +----------------------+
728 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800729 * | x28 | <- TODO: Remove callee-saves.
730 * | : |
731 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000732 * | SP' |
733 * | X5 |
734 * | X4 | Saved registers
735 * | LR' |
736 * | FP' | <- FP
737 * +----------------------+
738 * | uint32_t out[n-1] |
739 * | : : | Outs
740 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700741 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000742 * +----------------------+
743 *
744 * Outgoing registers:
745 * x0 - Method*
746 * x1-x7 - integer parameters.
747 * d0-d7 - Floating point parameters.
748 * xSELF = self
749 * SP = & of ArtMethod*
750 * x1 = "this" pointer.
751 *
752 */
753ENTRY art_quick_invoke_stub
754 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700755 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000756
757 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
758 // Parse the passed shorty to determine which register to load.
759 // Load addresses for routines that load WXSD registers.
760 adr x11, .LstoreW2
761 adr x12, .LstoreX2
762 adr x13, .LstoreS0
763 adr x14, .LstoreD0
764
765 // Initialize routine offsets to 0 for integers and floats.
766 // x8 for integers, x15 for floating point.
767 mov x8, #0
768 mov x15, #0
769
770 add x10, x5, #1 // Load shorty address, plus one to skip return value.
771 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
772
773 // Loop to fill registers.
774.LfillRegisters:
775 ldrb w17, [x10], #1 // Load next character in signature, and increment.
776 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
777
778 cmp w17, #'F' // is this a float?
779 bne .LisDouble
780
781 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700782 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000783
784 add x17, x13, x15 // Calculate subroutine to jump to.
785 br x17
786
787.LisDouble:
788 cmp w17, #'D' // is this a double?
789 bne .LisLong
790
791 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700792 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000793
794 add x17, x14, x15 // Calculate subroutine to jump to.
795 br x17
796
797.LisLong:
798 cmp w17, #'J' // is this a long?
799 bne .LisOther
800
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700801 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700802 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000803
804 add x17, x12, x8 // Calculate subroutine to jump to.
805 br x17
806
Stuart Monteithb95a5342014-03-12 13:32:32 +0000807.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700808 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700809 beq .Ladvance4
810
Stuart Monteithb95a5342014-03-12 13:32:32 +0000811 add x17, x11, x8 // Calculate subroutine to jump to.
812 br x17
813
Andreas Gampe03906cf2014-04-07 12:08:28 -0700814.Ladvance4:
815 add x9, x9, #4
816 b .LfillRegisters
817
818.Ladvance8:
819 add x9, x9, #8
820 b .LfillRegisters
821
Stuart Monteithb95a5342014-03-12 13:32:32 +0000822// Macro for loading a parameter into a register.
823// counter - the register with offset into these tables
824// size - the size of the register - 4 or 8 bytes.
825// register - the name of the register to be loaded.
826.macro LOADREG counter size register return
827 ldr \register , [x9], #\size
828 add \counter, \counter, 12
829 b \return
830.endm
831
832// Store ints.
833.LstoreW2:
834 LOADREG x8 4 w2 .LfillRegisters
835 LOADREG x8 4 w3 .LfillRegisters
836 LOADREG x8 4 w4 .LfillRegisters
837 LOADREG x8 4 w5 .LfillRegisters
838 LOADREG x8 4 w6 .LfillRegisters
839 LOADREG x8 4 w7 .LfillRegisters
840
841// Store longs.
842.LstoreX2:
843 LOADREG x8 8 x2 .LfillRegisters
844 LOADREG x8 8 x3 .LfillRegisters
845 LOADREG x8 8 x4 .LfillRegisters
846 LOADREG x8 8 x5 .LfillRegisters
847 LOADREG x8 8 x6 .LfillRegisters
848 LOADREG x8 8 x7 .LfillRegisters
849
850// Store singles.
851.LstoreS0:
852 LOADREG x15 4 s0 .LfillRegisters
853 LOADREG x15 4 s1 .LfillRegisters
854 LOADREG x15 4 s2 .LfillRegisters
855 LOADREG x15 4 s3 .LfillRegisters
856 LOADREG x15 4 s4 .LfillRegisters
857 LOADREG x15 4 s5 .LfillRegisters
858 LOADREG x15 4 s6 .LfillRegisters
859 LOADREG x15 4 s7 .LfillRegisters
860
861// Store doubles.
862.LstoreD0:
863 LOADREG x15 8 d0 .LfillRegisters
864 LOADREG x15 8 d1 .LfillRegisters
865 LOADREG x15 8 d2 .LfillRegisters
866 LOADREG x15 8 d3 .LfillRegisters
867 LOADREG x15 8 d4 .LfillRegisters
868 LOADREG x15 8 d5 .LfillRegisters
869 LOADREG x15 8 d6 .LfillRegisters
870 LOADREG x15 8 d7 .LfillRegisters
871
872
873.LcallFunction:
874
Andreas Gampe03906cf2014-04-07 12:08:28 -0700875 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000876
Stuart Monteithb95a5342014-03-12 13:32:32 +0000877END art_quick_invoke_stub
878
879/* extern"C"
880 * void art_quick_invoke_static_stub(ArtMethod *method, x0
881 * uint32_t *args, x1
882 * uint32_t argsize, w2
883 * Thread *self, x3
884 * JValue *result, x4
885 * char *shorty); x5
886 */
887ENTRY art_quick_invoke_static_stub
888 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700889 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000890
891 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
892 // Parse the passed shorty to determine which register to load.
893 // Load addresses for routines that load WXSD registers.
894 adr x11, .LstoreW1_2
895 adr x12, .LstoreX1_2
896 adr x13, .LstoreS0_2
897 adr x14, .LstoreD0_2
898
899 // Initialize routine offsets to 0 for integers and floats.
900 // x8 for integers, x15 for floating point.
901 mov x8, #0
902 mov x15, #0
903
904 add x10, x5, #1 // Load shorty address, plus one to skip return value.
905
906 // Loop to fill registers.
907.LfillRegisters2:
908 ldrb w17, [x10], #1 // Load next character in signature, and increment.
909 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
910
911 cmp w17, #'F' // is this a float?
912 bne .LisDouble2
913
914 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700915 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000916
917 add x17, x13, x15 // Calculate subroutine to jump to.
918 br x17
919
920.LisDouble2:
921 cmp w17, #'D' // is this a double?
922 bne .LisLong2
923
924 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700925 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000926
927 add x17, x14, x15 // Calculate subroutine to jump to.
928 br x17
929
930.LisLong2:
931 cmp w17, #'J' // is this a long?
932 bne .LisOther2
933
934 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700935 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000936
937 add x17, x12, x8 // Calculate subroutine to jump to.
938 br x17
939
Stuart Monteithb95a5342014-03-12 13:32:32 +0000940.LisOther2: // Everything else takes one vReg.
941 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700942 beq .Ladvance4_2
943
Stuart Monteithb95a5342014-03-12 13:32:32 +0000944 add x17, x11, x8 // Calculate subroutine to jump to.
945 br x17
946
Andreas Gampe03906cf2014-04-07 12:08:28 -0700947.Ladvance4_2:
948 add x9, x9, #4
949 b .LfillRegisters2
950
951.Ladvance8_2:
952 add x9, x9, #8
953 b .LfillRegisters2
954
Stuart Monteithb95a5342014-03-12 13:32:32 +0000955// Store ints.
956.LstoreW1_2:
957 LOADREG x8 4 w1 .LfillRegisters2
958 LOADREG x8 4 w2 .LfillRegisters2
959 LOADREG x8 4 w3 .LfillRegisters2
960 LOADREG x8 4 w4 .LfillRegisters2
961 LOADREG x8 4 w5 .LfillRegisters2
962 LOADREG x8 4 w6 .LfillRegisters2
963 LOADREG x8 4 w7 .LfillRegisters2
964
965// Store longs.
966.LstoreX1_2:
967 LOADREG x8 8 x1 .LfillRegisters2
968 LOADREG x8 8 x2 .LfillRegisters2
969 LOADREG x8 8 x3 .LfillRegisters2
970 LOADREG x8 8 x4 .LfillRegisters2
971 LOADREG x8 8 x5 .LfillRegisters2
972 LOADREG x8 8 x6 .LfillRegisters2
973 LOADREG x8 8 x7 .LfillRegisters2
974
975// Store singles.
976.LstoreS0_2:
977 LOADREG x15 4 s0 .LfillRegisters2
978 LOADREG x15 4 s1 .LfillRegisters2
979 LOADREG x15 4 s2 .LfillRegisters2
980 LOADREG x15 4 s3 .LfillRegisters2
981 LOADREG x15 4 s4 .LfillRegisters2
982 LOADREG x15 4 s5 .LfillRegisters2
983 LOADREG x15 4 s6 .LfillRegisters2
984 LOADREG x15 4 s7 .LfillRegisters2
985
986// Store doubles.
987.LstoreD0_2:
988 LOADREG x15 8 d0 .LfillRegisters2
989 LOADREG x15 8 d1 .LfillRegisters2
990 LOADREG x15 8 d2 .LfillRegisters2
991 LOADREG x15 8 d3 .LfillRegisters2
992 LOADREG x15 8 d4 .LfillRegisters2
993 LOADREG x15 8 d5 .LfillRegisters2
994 LOADREG x15 8 d6 .LfillRegisters2
995 LOADREG x15 8 d7 .LfillRegisters2
996
997
998.LcallFunction2:
999
Andreas Gampe03906cf2014-04-07 12:08:28 -07001000 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +00001001
Stuart Monteithb95a5342014-03-12 13:32:32 +00001002END art_quick_invoke_static_stub
1003
Andreas Gampe03906cf2014-04-07 12:08:28 -07001004
Stuart Monteithb95a5342014-03-12 13:32:32 +00001005
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001006/* extern"C" void art_quick_osr_stub(void** stack, x0
1007 * size_t stack_size_in_bytes, x1
1008 * const uin8_t* native_pc, x2
1009 * JValue *result, x3
1010 * char *shorty, x4
1011 * Thread *self) x5
1012 */
1013ENTRY art_quick_osr_stub
1014SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
1015 mov x9, sp // Save stack pointer.
1016 .cfi_register sp,x9
1017
1018 sub x10, sp, # SAVE_SIZE
1019 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
1020 mov sp, x10 // Set new SP.
1021
1022 str x28, [sp, #112]
1023 stp x26, x27, [sp, #96]
1024 stp x24, x25, [sp, #80]
1025 stp x22, x23, [sp, #64]
1026 stp x20, x21, [sp, #48]
1027 stp x9, x19, [sp, #32] // Save old stack pointer and x19.
1028 stp x3, x4, [sp, #16] // Save result and shorty addresses.
1029 stp xFP, xLR, [sp] // Store LR & FP.
1030 mov xSELF, x5 // Move thread pointer into SELF register.
1031
1032 sub sp, sp, #16
1033 str xzr, [sp] // Store null for ArtMethod* slot
1034 // Branch to stub.
1035 bl .Losr_entry
1036 add sp, sp, #16
1037
1038 // Restore return value address and shorty address.
1039 ldp x3,x4, [sp, #16]
1040 ldr x28, [sp, #112]
1041 ldp x26, x27, [sp, #96]
1042 ldp x24, x25, [sp, #80]
1043 ldp x22, x23, [sp, #64]
1044 ldp x20, x21, [sp, #48]
1045
1046 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1047 ldrb w10, [x4]
1048
1049 // Check the return type and store the correct register into the jvalue in memory.
1050
1051 // Don't set anything for a void type.
1052 cmp w10, #'V'
1053 beq .Losr_exit
1054
1055 // Is it a double?
1056 cmp w10, #'D'
1057 bne .Lno_double
1058 str d0, [x3]
1059 b .Losr_exit
1060
1061.Lno_double: // Is it a float?
1062 cmp w10, #'F'
1063 bne .Lno_float
1064 str s0, [x3]
1065 b .Losr_exit
1066
1067.Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits.
1068 str x0, [x3]
1069
1070.Losr_exit: // Finish up.
1071 ldp x2, x19, [sp, #32] // Restore stack pointer and x19.
1072 ldp xFP, xLR, [sp] // Restore old frame pointer and link register.
1073 mov sp, x2
1074 ret
1075
1076.Losr_entry:
1077 // Update stack pointer for the callee
1078 sub sp, sp, x1
1079
1080 // Update link register slot expected by the callee.
1081 sub w1, w1, #8
1082 str lr, [sp, x1]
1083
1084 // Copy arguments into stack frame.
1085 // Use simple copy routine for now.
1086 // 4 bytes per slot.
1087 // X0 - source address
1088 // W1 - args length
1089 // SP - destination address.
1090 // W10 - temporary
1091.Losr_loop_entry:
1092 cmp w1, #0
1093 beq .Losr_loop_exit
1094 sub w1, w1, #4
1095 ldr w10, [x0, x1]
1096 str w10, [sp, x1]
1097 b .Losr_loop_entry
1098
1099.Losr_loop_exit:
1100 // Branch to the OSR entry point.
1101 br x2
1102
1103END art_quick_osr_stub
1104
Stuart Monteithb95a5342014-03-12 13:32:32 +00001105 /*
1106 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1107 */
1108
1109ENTRY art_quick_do_long_jump
1110 // Load FPRs
1111 ldp d0, d1, [x1], #16
1112 ldp d2, d3, [x1], #16
1113 ldp d4, d5, [x1], #16
1114 ldp d6, d7, [x1], #16
1115 ldp d8, d9, [x1], #16
1116 ldp d10, d11, [x1], #16
1117 ldp d12, d13, [x1], #16
1118 ldp d14, d15, [x1], #16
1119 ldp d16, d17, [x1], #16
1120 ldp d18, d19, [x1], #16
1121 ldp d20, d21, [x1], #16
1122 ldp d22, d23, [x1], #16
1123 ldp d24, d25, [x1], #16
1124 ldp d26, d27, [x1], #16
1125 ldp d28, d29, [x1], #16
1126 ldp d30, d31, [x1]
1127
1128 // Load GPRs
1129 // TODO: lots of those are smashed, could optimize.
1130 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001131 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001132 ldp x28, x29, [x0], #-16
1133 ldp x26, x27, [x0], #-16
1134 ldp x24, x25, [x0], #-16
1135 ldp x22, x23, [x0], #-16
1136 ldp x20, x21, [x0], #-16
1137 ldp x18, x19, [x0], #-16
1138 ldp x16, x17, [x0], #-16
1139 ldp x14, x15, [x0], #-16
1140 ldp x12, x13, [x0], #-16
1141 ldp x10, x11, [x0], #-16
1142 ldp x8, x9, [x0], #-16
1143 ldp x6, x7, [x0], #-16
1144 ldp x4, x5, [x0], #-16
1145 ldp x2, x3, [x0], #-16
1146 mov sp, x1
1147
Andreas Gampe639bdd12015-06-03 11:22:45 -07001148 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1149 ldr x1, [x0, #33*8]
1150 // And the value of x0.
1151 ldr x0, [x0]
1152
1153 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001154END art_quick_do_long_jump
1155
Andreas Gampef4e910b2014-04-29 16:55:52 -07001156 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001157 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1158 * possibly null object to lock.
1159 *
1160 * Derived from arm32 code.
1161 */
1162 .extern artLockObjectFromCode
1163ENTRY art_quick_lock_object
1164 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001165 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001166.Lretry_lock:
1167 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1168 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001169 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001170 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001171 cbnz w3, .Lnot_unlocked // already thin locked
1172 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1173 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001174 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001175 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001176 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001177 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001178.Lnot_unlocked: // x1: original lock word
1179 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001180 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1181 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1182 uxth w2, w2 // zero top 16 bits
1183 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1184 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001185 mov x3, x1 // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001186 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001187 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001188 lsr w3, w2, #LOCK_WORD_GC_STATE_SHIFT // if the first gc state bit is set, we overflowed.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001189 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1190 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1191 stxr w3, w2, [x4]
1192 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001193 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001194.Llock_stxr_fail:
1195 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001196.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001197 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001198 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001199 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001200 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001201 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1202END art_quick_lock_object
1203
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001204ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001205 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001206 mov x1, xSELF // pass Thread::Current
1207 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001208 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001209 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1210END art_quick_lock_object_no_inline
1211
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001212 /*
1213 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1214 * x0 holds the possibly null object to lock.
1215 *
1216 * Derived from arm32 code.
1217 */
1218 .extern artUnlockObjectFromCode
1219ENTRY art_quick_unlock_object
1220 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001221 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1222.Lretry_unlock:
1223#ifndef USE_READ_BARRIER
1224 ldr w1, [x4]
1225#else
1226 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1227#endif
1228 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001229 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1230 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001231 mov x3, x1 // copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001232 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001233 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001234 uxth w3, w3 // zero top 16 bits
1235 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001236 mov x3, x1 // copy lock word to detect transition to unlocked
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001237 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001238 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001239 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001240 // transition to unlocked
1241 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001242 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED // w3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -07001243 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001244#ifndef USE_READ_BARRIER
1245 str w3, [x4]
1246#else
1247 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1248 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1249#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001250 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001251.Lrecursive_thin_unlock: // w1: original lock word
1252 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1253#ifndef USE_READ_BARRIER
1254 str w1, [x4]
1255#else
1256 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1257 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1258#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001259 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001260.Lunlock_stxr_fail:
1261 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001262.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001263 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001264 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001265 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001266 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001267 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1268END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001269
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001270ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001271 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001272 mov x1, xSELF // pass Thread::Current
1273 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001274 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001275 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1276END art_quick_unlock_object_no_inline
1277
Andreas Gampe525cde22014-04-22 15:44:50 -07001278 /*
1279 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1280 * artThrowClassCastException.
1281 */
1282 .extern artThrowClassCastException
1283ENTRY art_quick_check_cast
1284 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001285 // Stack needs to be 16B aligned on calls.
Vladimir Marko215076b2016-09-07 18:05:55 +01001286 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1287 SAVE_REG xLR, 24
Andreas Gampe525cde22014-04-22 15:44:50 -07001288
1289 // Call runtime code
1290 bl artIsAssignableFromCode
1291
1292 // Check for exception
1293 cbz x0, .Lthrow_class_cast_exception
1294
1295 // Restore and return
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001296 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001297 RESTORE_REG xLR, 24
1298 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001299 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001300 .cfi_restore_state // Reset unwind info so following code unwinds.
Andreas Gampe6b90d422015-06-26 19:49:24 -07001301
Andreas Gampe525cde22014-04-22 15:44:50 -07001302.Lthrow_class_cast_exception:
1303 // Restore
Vladimir Marko215076b2016-09-07 18:05:55 +01001304 RESTORE_REG xLR, 24
1305 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001306
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001307 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001308 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001309 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001310 brk 0 // We should not return here...
1311END art_quick_check_cast
1312
Man Cao1aee9002015-07-14 22:31:42 -07001313// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1314.macro POP_REG_NE xReg, offset, xExclude
1315 .ifnc \xReg, \xExclude
1316 ldr \xReg, [sp, #\offset] // restore xReg
1317 .cfi_restore \xReg
1318 .endif
1319.endm
1320
Roland Levillain4359e612016-07-20 11:32:19 +01001321// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1322// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1323.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1324 .ifc \xReg1, \xExclude
1325 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1326 .else
1327 .ifc \xReg2, \xExclude
1328 ldr \xReg1, [sp, #\offset] // restore xReg1
1329 .else
1330 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1331 .endif
1332 .endif
1333 .cfi_restore \xReg1
1334 .cfi_restore \xReg2
1335.endm
1336
Man Cao1aee9002015-07-14 22:31:42 -07001337 /*
1338 * Macro to insert read barrier, only used in art_quick_aput_obj.
1339 * xDest, wDest and xObj are registers, offset is a defined literal such as
1340 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1341 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1342 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1343 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001344.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001345#ifdef USE_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001346#ifdef USE_BAKER_READ_BARRIER
1347 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1348 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1349 // False dependency to avoid needing load/load fence.
1350 add \xObj, \xObj, \xTemp, lsr #32
1351 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1352 UNPOISON_HEAP_REF \wDest
1353 b .Lrb_exit\number
1354#endif
1355.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001356 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
Vladimir Marko215076b2016-09-07 18:05:55 +01001357 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1358 SAVE_TWO_REGS x2, x3, 16
1359 SAVE_TWO_REGS x4, xLR, 32
Man Cao1aee9002015-07-14 22:31:42 -07001360
Man Cao63069212015-08-21 15:51:39 -07001361 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001362 .ifnc \xObj, x1
1363 mov x1, \xObj // pass xObj
1364 .endif
1365 mov w2, #\offset // pass offset
1366 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1367 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1368 .ifnc \wDest, w0
1369 mov \wDest, w0 // save return value in wDest
1370 .endif
1371
1372 // Conditionally restore saved registers
1373 POP_REG_NE x0, 0, \xDest
1374 POP_REG_NE x1, 8, \xDest
1375 POP_REG_NE x2, 16, \xDest
1376 POP_REG_NE x3, 24, \xDest
1377 POP_REG_NE x4, 32, \xDest
Vladimir Marko215076b2016-09-07 18:05:55 +01001378 RESTORE_REG xLR, 40
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001379 DECREASE_FRAME 48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001380.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001381#else
1382 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1383 UNPOISON_HEAP_REF \wDest
1384#endif // USE_READ_BARRIER
1385.endm
1386
Andreas Gampef4e910b2014-04-29 16:55:52 -07001387 /*
1388 * Entry from managed code for array put operations of objects where the value being stored
1389 * needs to be checked for compatibility.
1390 * x0 = array, x1 = index, x2 = value
1391 *
1392 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1393 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1394 * using index-zero-extension in load/stores.
1395 *
1396 * Temporaries: x3, x4
1397 * TODO: x4 OK? ip seems wrong here.
1398 */
1399ENTRY art_quick_aput_obj_with_null_and_bound_check
1400 tst x0, x0
1401 bne art_quick_aput_obj_with_bound_check
1402 b art_quick_throw_null_pointer_exception
1403END art_quick_aput_obj_with_null_and_bound_check
1404
1405ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001406 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001407 cmp w3, w1
1408 bhi art_quick_aput_obj
1409 mov x0, x1
1410 mov x1, x3
1411 b art_quick_throw_array_bounds
1412END art_quick_aput_obj_with_bound_check
1413
Man Cao1aee9002015-07-14 22:31:42 -07001414#ifdef USE_READ_BARRIER
1415 .extern artReadBarrierSlow
1416#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001417ENTRY art_quick_aput_obj
1418 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001419 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1420 // This also zero-extends to x3
1421 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1422 // This also zero-extends to x3
1423 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1424 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001425 cmp w3, w4 // value's type == array's component type - trivial assignability
1426 bne .Lcheck_assignability
1427.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001428 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001429 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001430 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001431 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1432 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1433 lsr x0, x0, #7
1434 strb w3, [x3, x0]
1435 ret
1436.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001437 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001438 // "Compress" = do nothing
1439 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1440 ret
1441.Lcheck_assignability:
1442 // Store arguments and link register
Vladimir Marko215076b2016-09-07 18:05:55 +01001443 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1444 SAVE_TWO_REGS x2, xLR, 16
Andreas Gampef4e910b2014-04-29 16:55:52 -07001445
1446 // Call runtime code
1447 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1448 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1449 bl artIsAssignableFromCode
1450
1451 // Check for exception
1452 cbz x0, .Lthrow_array_store_exception
1453
1454 // Restore
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001455 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001456 RESTORE_TWO_REGS x2, xLR, 16
1457 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001458
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001459 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001460 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001461 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001462 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1463 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1464 lsr x0, x0, #7
1465 strb w3, [x3, x0]
1466 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001467 .cfi_restore_state // Reset unwind info so following code unwinds.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001468.Lthrow_array_store_exception:
Vladimir Marko215076b2016-09-07 18:05:55 +01001469 RESTORE_TWO_REGS x2, xLR, 16
1470 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001471
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001472 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gampef4e910b2014-04-29 16:55:52 -07001473 mov x1, x2 // Pass value.
1474 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001475 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001476 brk 0 // Unreached.
1477END art_quick_aput_obj
1478
Stuart Monteithb95a5342014-03-12 13:32:32 +00001479// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001480.macro ONE_ARG_DOWNCALL name, entrypoint, return
1481 .extern \entrypoint
1482ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001483 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001484 mov x1, xSELF // pass Thread::Current
1485 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001486 RESTORE_SAVE_REFS_ONLY_FRAME
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001487 \return
1488END \name
1489.endm
1490
1491// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001492.macro TWO_ARG_DOWNCALL name, entrypoint, return
1493 .extern \entrypoint
1494ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001495 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001496 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001497 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001498 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001499 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001500END \name
1501.endm
1502
Jeff Hao848f70a2014-01-15 13:49:50 -08001503// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001504.macro THREE_ARG_DOWNCALL name, entrypoint, return
1505 .extern \entrypoint
1506ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001507 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001508 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001509 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001510 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001511 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001512END \name
1513.endm
1514
Jeff Hao848f70a2014-01-15 13:49:50 -08001515// Macro to facilitate adding new allocation entrypoints.
1516.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1517 .extern \entrypoint
1518ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001519 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001520 mov x4, xSELF // pass Thread::Current
1521 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001522 RESTORE_SAVE_REFS_ONLY_FRAME
Jeff Hao848f70a2014-01-15 13:49:50 -08001523 \return
1524 DELIVER_PENDING_EXCEPTION
1525END \name
1526.endm
1527
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001528// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001529.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1530 .extern \entrypoint
1531ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001532 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1533 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001534 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001535 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001536 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001537 \return
1538END \name
1539.endm
1540
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001541.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1542 .extern \entrypoint
1543ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001544 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1545 ldr x2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001546 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001547 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001548 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001549 \return
1550END \name
1551.endm
1552
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001553.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1554 .extern \entrypoint
1555ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001556 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1557 ldr x3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001558 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001559 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001560 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001561 \return
1562END \name
1563.endm
1564
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001565.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1566 cbz w0, 1f // result zero branch over
1567 ret // return
15681:
1569 DELIVER_PENDING_EXCEPTION
1570.endm
1571
Matteo Franchindfd891a2014-04-30 12:17:17 +01001572 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001573 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1574 * failure.
1575 */
1576TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1577
1578 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001579 * Entry from managed code when uninitialized static storage, this stub will run the class
1580 * initializer and deliver the exception on error. On success the static storage base is
1581 * returned.
1582 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001583ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001584
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001585ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1586ONE_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 +01001587
Fred Shih37f05ef2014-07-16 18:38:08 -07001588ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1589ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1590ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1591ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001592ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1593ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1594ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1595
Fred Shih37f05ef2014-07-16 18:38:08 -07001596TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1597TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1598TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1599TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001600TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1601TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1602TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1603
Fred Shih37f05ef2014-07-16 18:38:08 -07001604TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1605TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001606TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1607TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1608
Fred Shih37f05ef2014-07-16 18:38:08 -07001609THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1610THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001611THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001612THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001613THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1614
1615// This is separated out as the argument order is different.
1616 .extern artSet64StaticFromCode
1617ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001618 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1619 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Calin Juravlee460d1d2015-09-29 04:52:17 +01001620 // x2 contains the parameter
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001621 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001622 bl artSet64StaticFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001623 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001624 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1625END art_quick_set64_static
1626
Matteo Franchindfd891a2014-04-30 12:17:17 +01001627 /*
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001628 * Entry from managed code to resolve a string, this stub will
1629 * check the dex cache for a matching string (the fast path), and if not found,
1630 * it will allocate a String and deliver an exception on error.
1631 * On success the String is returned. R0 holds the string index.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001632 */
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001633
1634ENTRY art_quick_resolve_string
1635 ldr x1, [sp] // load referrer
1636 ldr w2, [x1, #ART_METHOD_DECLARING_CLASS_OFFSET] // load declaring class
1637 ldr x1, [x2, #DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET] // load string dex cache
Mathieu Chartiere3fbe382016-08-30 09:42:28 -07001638 ubfx x2, x0, #0, #STRING_DEX_CACHE_HASH_BITS // get masked string index into x2
Mathieu Chartier5f404332016-08-22 15:38:08 -07001639 ldr x2, [x1, x2, lsl #STRING_DEX_CACHE_ELEMENT_SIZE_SHIFT] // load dex cache pair into x2
1640 cmp x0, x2, lsr #32 // compare against upper 32 bits
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001641 bne .Lart_quick_resolve_string_slow_path
Mathieu Chartier5f404332016-08-22 15:38:08 -07001642 ubfx x0, x2, #0, #32 // extract lower 32 bits into x0
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001643#ifdef USE_READ_BARRIER
Mathieu Chartier5f404332016-08-22 15:38:08 -07001644 // Most common case: GC is not marking.
1645 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1646 cbnz x3, .Lart_quick_resolve_string_marking
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001647#endif
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001648 ret
1649
Mathieu Chartier5f404332016-08-22 15:38:08 -07001650// Slow path case, the index did not match.
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001651.Lart_quick_resolve_string_slow_path:
1652 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1653 mov x1, xSELF // pass Thread::Current
Mathieu Chartier5f404332016-08-22 15:38:08 -07001654 bl artResolveStringFromCode // (int32_t string_idx, Thread* self)
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001655 RESTORE_SAVE_REFS_ONLY_FRAME
1656 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1657
Mathieu Chartier5f404332016-08-22 15:38:08 -07001658// GC is marking case, need to check the mark bit.
1659.Lart_quick_resolve_string_marking:
1660 ldr x3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1661 tbnz x3, #LOCK_WORD_MARK_BIT_SHIFT, .Lart_quick_resolve_string_no_rb
1662 // Save LR so that we can return, also x1 for alignment purposes.
Vladimir Marko215076b2016-09-07 18:05:55 +01001663 SAVE_TWO_REGS_INCREASE_FRAME x1, xLR, 16 // Save x1, LR.
Mathieu Chartier5f404332016-08-22 15:38:08 -07001664 bl artReadBarrierMark // Get the marked string back.
Vladimir Marko215076b2016-09-07 18:05:55 +01001665 RESTORE_TWO_REGS_DECREASE_FRAME x1, xLR, 16 // Restore registers.
Mathieu Chartier5f404332016-08-22 15:38:08 -07001666.Lart_quick_resolve_string_no_rb:
1667 ret
1668
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001669END art_quick_resolve_string
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001670
Stuart Monteithb95a5342014-03-12 13:32:32 +00001671// Generate the allocation entrypoints for each allocator.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001672GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_REGION_TLAB_ALLOCATORS
1673// Comment out allocators that have arm64 specific asm.
1674// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) implemented in asm
1675// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1676// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1677GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1678// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) implemented in asm
1679// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
1680GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1681GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB)
1682GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1683GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1684GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1685GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001686
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001687// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1688ENTRY art_quick_alloc_object_rosalloc
1689 // Fast path rosalloc allocation.
1690 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1691 // x2-x7: free.
1692 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1693 // Load the class (x2)
1694 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1695 cbz x2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001696 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1697 // allocation stack has room.
1698 // ldp won't work due to large offset.
1699 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1700 cmp x3, x4
1701 bhs .Lart_quick_alloc_object_rosalloc_slow_path
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001702 ldr w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3)
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001703 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001704 // local allocation. Also does the
1705 // finalizable and initialization
1706 // checks.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001707 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1708 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001709 // from the size. Since the size is
1710 // already aligned we can combine the
1711 // two shifts together.
1712 add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1713 // Subtract pointer size since ther
1714 // are no runs for 0 byte allocations
1715 // and the size is already aligned.
1716 ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001717 // Load the free list head (x3). This
1718 // will be the return val.
1719 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1720 cbz x3, .Lart_quick_alloc_object_rosalloc_slow_path
1721 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1722 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1723 // and update the list head with the
1724 // next pointer.
1725 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1726 // Store the class pointer in the
1727 // header. This also overwrites the
1728 // next pointer. The offsets are
1729 // asserted to match.
1730#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1731#error "Class pointer needs to overwrite next pointer."
1732#endif
1733 POISON_HEAP_REF w2
1734 str w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001735 // Fence. This is "ish" not "ishst" so
1736 // that it also ensures ordering of
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001737 // the object size load with respect
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001738 // to later accesses to the class
1739 // object. Alternatively we could use
1740 // "ishst" if we use load-acquire for
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001741 // the class status load.
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001742 // Needs to be done before pushing on
1743 // allocation since Heap::VisitObjects
1744 // relies on seeing the class pointer.
1745 // b/28790624
1746 dmb ish
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001747 // Push the new object onto the thread
1748 // local allocation stack and
1749 // increment the thread local
1750 // allocation stack top.
1751 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1752 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1753 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1754 // Decrement the size of the free list
1755 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1756 sub x1, x1, #1
1757 // TODO: consider combining this store
1758 // and the list head store above using
1759 // strd.
1760 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001761
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001762 mov x0, x3 // Set the return value and return.
1763 ret
1764.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001765 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001766 mov x2, xSELF // pass Thread::Current
1767 bl artAllocObjectFromCodeRosAlloc // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001768 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001769 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1770END art_quick_alloc_object_rosalloc
Stuart Monteithb95a5342014-03-12 13:32:32 +00001771
Mathieu Chartier8261d022016-08-08 09:41:04 -07001772
1773// The common fast path code for art_quick_alloc_array_region_tlab.
1774.macro ALLOC_ARRAY_TLAB_FAST_PATH slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1775 // Check null class
1776 cbz \wClass, \slowPathLabel
1777 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED \slowPathLabel, \xClass, \wClass, \xCount, \wCount, \xTemp0, \wTemp0, \xTemp1, \wTemp1, \xTemp2, \wTemp2
1778.endm
1779
1780// The common fast path code for art_quick_alloc_array_region_tlab.
1781.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1782 // Array classes are never finalizable or uninitialized, no need to check.
1783 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1784 UNPOISON_HEAP_REF \wTemp0
1785 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1786 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1787 // bits.
1788 // xCount is holding a 32 bit value,
1789 // it can not overflow.
1790 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1791 // Add array data offset and alignment.
1792 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1793#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1794#error Long array data offset must be 4 greater than int array data offset.
1795#endif
1796
1797 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1798 // component size shift is 3
1799 // (for 64 bit alignment).
1800 and \xTemp0, \xTemp0, #4
1801 add \xTemp1, \xTemp1, \xTemp0
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001802 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask
1803 // (addr + 7) & ~7. The mask must
1804 // be 64 bits to keep high bits in
1805 // case of overflow.
1806 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1807 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1808 // 32 bit int. Since the max shift for arrays is 3, it can not become a negative 64 bit int.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001809 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1810 bhs \slowPathLabel // path.
1811
1812 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1813 // we use (end - begin) to handle
1814 // negative size arrays. It is
1815 // assumed that a negative size will
1816 // always be greater unsigned than
1817 // region size.
1818 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1819 sub \xTemp2, \xTemp2, \xTemp0
1820 cmp \xTemp1, \xTemp2
1821 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001822 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1823 // Move old thread_local_pos to x0
1824 // for the return value.
1825 mov x0, \xTemp0
1826 add \xTemp0, \xTemp0, \xTemp1
1827 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1828 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1829 add \xTemp0, \xTemp0, #1
1830 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1831 POISON_HEAP_REF \wClass
1832 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1833 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1834 // Fence.
1835 dmb ishst
1836 ret
1837.endm
1838
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001839// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1840//
1841// x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current
1842// x3-x7: free.
1843// Need to preserve x0 and x1 to the slow path.
1844.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1845 cbz x2, \slowPathLabel // Check null class
Mathieu Chartier8261d022016-08-08 09:41:04 -07001846 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED \slowPathLabel
1847.endm
1848
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001849// TODO: delete ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since it is the same as
1850// ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001851.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001852 ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED \slowPathLabel
1853.endm
1854
1855.macro ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001856 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1857 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001858 ldr w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7).
1859 add x6, x4, x7 // Add object size to tlab pos.
1860 cmp x6, x5 // Check if it fits, overflow works
1861 // since the tlab pos and end are 32
1862 // bit values.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001863 bhi \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001864 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001865 mov x0, x4
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001866 str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001867 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1868 add x5, x5, #1
1869 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1870 POISON_HEAP_REF w2
1871 str w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1872 // Fence. This is "ish" not "ishst" so
1873 // that the code after this allocation
1874 // site will see the right values in
1875 // the fields of the class.
1876 // Alternatively we could use "ishst"
1877 // if we use load-acquire for the
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001878 // object size load.)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001879 dmb ish
1880 ret
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001881.endm
1882
1883// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1884ENTRY art_quick_alloc_object_tlab
1885 // Fast path tlab allocation.
1886 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1887 // x2-x7: free.
1888#if defined(USE_READ_BARRIER)
1889 mvn x0, xzr // Read barrier not supported here.
1890 ret // Return -1.
1891#endif
1892 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1893 // Load the class (x2)
1894 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1895 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001896.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001897 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001898 mov x2, xSELF // Pass Thread::Current.
1899 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001900 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001901 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1902END art_quick_alloc_object_tlab
1903
Mathieu Chartier8261d022016-08-08 09:41:04 -07001904// The common code for art_quick_alloc_object_*region_tlab
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001905.macro GENERATE_ALLOC_OBJECT_REGION_TLAB name, entrypoint, fast_path, is_resolved, read_barrier
Mathieu Chartier8261d022016-08-08 09:41:04 -07001906ENTRY \name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001907 // Fast path region tlab allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001908 // x0: type_idx/resolved class/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1909 // If is_resolved is 1 then x0 is the resolved type, otherwise it is the index.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001910 // x2-x7: free.
1911#if !defined(USE_READ_BARRIER)
1912 mvn x0, xzr // Read barrier must be enabled here.
1913 ret // Return -1.
1914#endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001915.if \is_resolved
1916 mov x2, x0 // class is actually stored in x0 already
1917.else
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001918 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1919 // Load the class (x2)
1920 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001921 // If the class is null, go slow path. The check is required to read the lock word.
1922 cbz w2, .Lslow_path\name
Mathieu Chartier8261d022016-08-08 09:41:04 -07001923.endif
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001924.if \read_barrier
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001925 // Most common case: GC is not marking.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001926 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
Mathieu Chartier8261d022016-08-08 09:41:04 -07001927 cbnz x3, .Lmarking\name
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001928.endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001929.Ldo_allocation\name:
1930 \fast_path .Lslow_path\name
1931.Lmarking\name:
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001932.if \read_barrier
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001933 // GC is marking, check the lock word of the class for the mark bit.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001934 // Class is not null, check mark bit in lock word.
1935 ldr w3, [x2, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1936 // If the bit is not zero, do the allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001937 tbnz w3, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001938 // The read barrier slow path. Mark
1939 // the class.
Vladimir Marko215076b2016-09-07 18:05:55 +01001940 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32 // Save registers (x0, x1, lr).
1941 SAVE_REG xLR, 24 // Align sp by 16 bytes.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001942 mov x0, x2 // Pass the class as the first param.
1943 bl artReadBarrierMark
1944 mov x2, x0 // Get the (marked) class back.
Vladimir Marko215076b2016-09-07 18:05:55 +01001945 RESTORE_REG xLR, 24
1946 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 // Restore registers.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001947 b .Ldo_allocation\name
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001948.endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001949.Lslow_path\name:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001950 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001951 mov x2, xSELF // Pass Thread::Current.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001952 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1953 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001954 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Mathieu Chartier8261d022016-08-08 09:41:04 -07001955END \name
1956.endm
1957
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001958// Use ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since the null check is already done in GENERATE_ALLOC_OBJECT_TLAB.
1959GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_region_tlab, artAllocObjectFromCodeRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 0, 1
1960// No read barrier for the resolved or initialized cases since the caller is responsible for the
1961// read barrier due to the to-space invariant.
1962GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 1, 0
1963GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED, 1, 0
1964
1965// TODO: We could use this macro for the normal tlab allocator too.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001966
1967// The common code for art_quick_alloc_array_*region_tlab
1968.macro GENERATE_ALLOC_ARRAY_REGION_TLAB name, entrypoint, fast_path, is_resolved
1969ENTRY \name
1970 // Fast path array allocation for region tlab allocation.
1971 // x0: uint32_t type_idx
1972 // x1: int32_t component_count
1973 // x2: ArtMethod* method
1974 // x3-x7: free.
1975#if !defined(USE_READ_BARRIER)
1976 mvn x0, xzr // Read barrier must be enabled here.
1977 ret // Return -1.
1978#endif
1979.if \is_resolved
1980 mov x3, x0
1981 // If already resolved, class is stored in x0
1982.else
1983 ldr x3, [x2, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1984 // Load the class (x2)
1985 ldr w3, [x3, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1986.endif
1987 // Most common case: GC is not marking.
1988 ldr w4, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1989 cbnz x4, .Lmarking\name
1990.Ldo_allocation\name:
1991 \fast_path .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1992.Lmarking\name:
1993 // GC is marking, check the lock word of the class for the mark bit.
1994 // If the class is null, go slow path. The check is required to read the lock word.
1995 cbz w3, .Lslow_path\name
1996 // Class is not null, check mark bit in lock word.
1997 ldr w4, [x3, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1998 // If the bit is not zero, do the allocation.
1999 tbnz w4, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
2000 // The read barrier slow path. Mark
2001 // the class.
2002 stp x0, x1, [sp, #-32]! // Save registers (x0, x1, x2, lr).
2003 stp x2, xLR, [sp, #16]
2004 mov x0, x3 // Pass the class as the first param.
2005 bl artReadBarrierMark
2006 mov x3, x0 // Get the (marked) class back.
2007 ldp x2, xLR, [sp, #16]
2008 ldp x0, x1, [sp], #32 // Restore registers.
2009 b .Ldo_allocation\name
2010.Lslow_path\name:
2011 // x0: uint32_t type_idx / mirror::Class* klass (if resolved)
2012 // x1: int32_t component_count
2013 // x2: ArtMethod* method
2014 // x3: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002015 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Mathieu Chartier8261d022016-08-08 09:41:04 -07002016 mov x3, xSELF // pass Thread::Current
2017 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002018 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier8261d022016-08-08 09:41:04 -07002019 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
2020END \name
2021.endm
2022
2023GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_region_tlab, artAllocArrayFromCodeRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH, 0
2024// TODO: art_quick_alloc_array_resolved_region_tlab seems to not get called. Investigate compiler.
2025GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED, 1
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08002026
Zheng Xu48241e72014-05-23 11:52:42 +08002027 /*
Zheng Xu69a50302015-04-14 20:04:41 +08002028 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08002029 */
2030 .extern artTestSuspendFromCode
2031ENTRY art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002032 SETUP_SAVE_EVERYTHING_FRAME // save callee saves for stack crawl
Zheng Xu48241e72014-05-23 11:52:42 +08002033 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002034 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002035 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01002036 ret
Zheng Xu48241e72014-05-23 11:52:42 +08002037END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00002038
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002039ENTRY art_quick_implicit_suspend
2040 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002041 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002042 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002043 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002044END art_quick_implicit_suspend
2045
Andreas Gampee62a07e2014-03-26 14:53:21 -07002046 /*
2047 * Called by managed code that is attempting to call a method on a proxy class. On entry
2048 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2049 * method agrees with a ref and args callee save frame.
2050 */
2051 .extern artQuickProxyInvokeHandler
2052ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002053 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07002054 mov x2, xSELF // pass Thread::Current
2055 mov x3, sp // pass SP
2056 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002057 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07002058 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002059 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07002060 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07002061 ret // return on success
2062.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002063 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07002064 DELIVER_PENDING_EXCEPTION
2065END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00002066
Andreas Gampe51f76352014-05-21 08:28:48 -07002067 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002068 * Called to resolve an imt conflict.
2069 * x0 is the conflict ArtMethod.
2070 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2071 *
2072 * Note that this stub writes to xIP0, xIP1, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002073 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002074 .extern artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002075ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002076 ldr xIP0, [sp, #0] // Load referrer
2077 ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64] // Load dex cache methods array
2078 ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT] // Load interface method
2079 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2080 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2081.Limt_table_iterate:
2082 cmp x0, xIP0
2083 // Branch if found. Benchmarks have shown doing a branch here is better.
2084 beq .Limt_table_found
2085 // If the entry is null, the interface method is not in the ImtConflictTable.
2086 cbz x0, .Lconflict_trampoline
2087 // Iterate over the entries of the ImtConflictTable.
2088 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2089 b .Limt_table_iterate
2090.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002091 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002092 // and jump to it.
2093 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2094 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2095 br xIP0
2096.Lconflict_trampoline:
2097 // Call the runtime stub to populate the ImtConflictTable and jump to the
2098 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002099 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002100END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002101
2102ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002103 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002104 mov x2, xSELF
2105 mov x3, sp
2106 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002107 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002108 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002109 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002110 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08002111 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000021121:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002113 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002114 DELIVER_PENDING_EXCEPTION
2115END art_quick_resolution_trampoline
2116
2117/*
2118 * Generic JNI frame layout:
2119 *
2120 * #-------------------#
2121 * | |
2122 * | caller method... |
2123 * #-------------------# <--- SP on entry
2124 * | Return X30/LR |
2125 * | X29/FP | callee save
2126 * | X28 | callee save
2127 * | X27 | callee save
2128 * | X26 | callee save
2129 * | X25 | callee save
2130 * | X24 | callee save
2131 * | X23 | callee save
2132 * | X22 | callee save
2133 * | X21 | callee save
2134 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002135 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002136 * | X7 | arg7
2137 * | X6 | arg6
2138 * | X5 | arg5
2139 * | X4 | arg4
2140 * | X3 | arg3
2141 * | X2 | arg2
2142 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002143 * | D7 | float arg 8
2144 * | D6 | float arg 7
2145 * | D5 | float arg 6
2146 * | D4 | float arg 5
2147 * | D3 | float arg 4
2148 * | D2 | float arg 3
2149 * | D1 | float arg 2
2150 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002151 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002152 * #-------------------#
2153 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002154 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002155 * #-------------------#
2156 * | JNI Call Stack |
2157 * #-------------------# <--- SP on native call
2158 * | |
2159 * | Stack for Regs | The trampoline assembly will pop these values
2160 * | | into registers for native call
2161 * #-------------------#
2162 * | Native code ptr |
2163 * #-------------------#
2164 * | Free scratch |
2165 * #-------------------#
2166 * | Ptr to (1) | <--- SP
2167 * #-------------------#
2168 */
2169 /*
2170 * Called to do a generic JNI down-call
2171 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002172ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002173 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002174
2175 // Save SP , so we can have static CFI info.
2176 mov x28, sp
2177 .cfi_def_cfa_register x28
2178
2179 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002180 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002181 mov xFP, sp
2182
Zheng Xub551fdc2014-07-25 11:49:42 +08002183 mov xIP0, #5120
2184 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002185
2186 // prepare for artQuickGenericJniTrampoline call
2187 // (Thread*, SP)
2188 // x0 x1 <= C calling convention
2189 // xSELF xFP <= where they are
2190
2191 mov x0, xSELF // Thread*
2192 mov x1, xFP
2193 bl artQuickGenericJniTrampoline // (Thread*, sp)
2194
Andreas Gampec200a4a2014-06-16 18:39:09 -07002195 // The C call will have registered the complete save-frame on success.
2196 // The result of the call is:
2197 // x0: pointer to native code, 0 on error.
2198 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002199
Andreas Gampec200a4a2014-06-16 18:39:09 -07002200 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002201 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002202
Andreas Gampec200a4a2014-06-16 18:39:09 -07002203 // Release part of the alloca.
2204 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002205
Andreas Gampec200a4a2014-06-16 18:39:09 -07002206 // Save the code pointer
2207 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002208
2209 // Load parameters from frame into registers.
2210 // TODO Check with artQuickGenericJniTrampoline.
2211 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002212 ldp x0, x1, [sp]
2213 ldp x2, x3, [sp, #16]
2214 ldp x4, x5, [sp, #32]
2215 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002216
Andreas Gampec200a4a2014-06-16 18:39:09 -07002217 ldp d0, d1, [sp, #64]
2218 ldp d2, d3, [sp, #80]
2219 ldp d4, d5, [sp, #96]
2220 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002221
Andreas Gampec200a4a2014-06-16 18:39:09 -07002222 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002223
Zheng Xub551fdc2014-07-25 11:49:42 +08002224 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002225
2226 // result sign extension is handled in C code
2227 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002228 // (Thread*, result, result_f)
2229 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002230 mov x1, x0 // Result (from saved).
2231 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002232 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002233
2234 bl artQuickGenericJniEndTrampoline
2235
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002236 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002237 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002238 cbnz x2, .Lexception_in_native
2239
Stuart Monteithb95a5342014-03-12 13:32:32 +00002240 // Tear down the alloca.
2241 mov sp, x28
2242 .cfi_def_cfa_register sp
2243
Stuart Monteithb95a5342014-03-12 13:32:32 +00002244 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002245 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002246
2247 // store into fpr, for when it's a fpr return...
2248 fmov d0, x0
2249 ret
2250
Stuart Monteithb95a5342014-03-12 13:32:32 +00002251.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002252 // Move to x1 then sp to please assembler.
2253 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
2254 mov sp, x1
2255 .cfi_def_cfa_register sp
2256 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002257 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002258END art_quick_generic_jni_trampoline
2259
2260/*
2261 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2262 * of a quick call:
2263 * x0 = method being called/to bridge to.
2264 * x1..x7, d0..d7 = arguments to that method.
2265 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002266ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002267 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002268
2269 // x0 will contain mirror::ArtMethod* method.
2270 mov x1, xSELF // How to get Thread::Current() ???
2271 mov x2, sp
2272
2273 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2274 // mirror::ArtMethod** sp)
2275 bl artQuickToInterpreterBridge
2276
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002277 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002278
2279 fmov d0, x0
2280
2281 RETURN_OR_DELIVER_PENDING_EXCEPTION
2282END art_quick_to_interpreter_bridge
2283
Andreas Gamped58342c2014-06-05 14:18:08 -07002284
2285//
2286// Instrumentation-related stubs
2287//
2288 .extern artInstrumentationMethodEntryFromCode
2289ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002290 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002291
Zheng Xub551fdc2014-07-25 11:49:42 +08002292 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002293
2294 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002295 mov x3, xLR
2296 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07002297
Zheng Xub551fdc2014-07-25 11:49:42 +08002298 mov xIP0, x0 // x0 = result of call.
2299 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002300
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002301 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07002302 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002303 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07002304END art_quick_instrumentation_entry
2305
2306 .extern artInstrumentationMethodExitFromCode
2307ENTRY art_quick_instrumentation_exit
2308 mov xLR, #0 // Clobber LR for later checks.
2309
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002310 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002311
2312 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
2313 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
2314 // easier to have an extra small stack area.
2315
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002316 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07002317 .cfi_adjust_cfa_offset 16
2318 str d0, [sp, #8] // Save floating-point result.
2319
Andreas Gamped58342c2014-06-05 14:18:08 -07002320 add x1, sp, #16 // Pass SP.
2321 mov x2, x0 // Pass integer result.
2322 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002323 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07002324 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
2325
Zheng Xub551fdc2014-07-25 11:49:42 +08002326 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07002327 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
2328
2329 ldr d0, [sp, #8] // Restore floating-point result.
Vladimir Marko215076b2016-09-07 18:05:55 +01002330 ldr x0, [sp], #16 // Restore integer result, and drop stack area.
Andreas Gamped58342c2014-06-05 14:18:08 -07002331 .cfi_adjust_cfa_offset 16
2332
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002333 POP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002334
Zheng Xub551fdc2014-07-25 11:49:42 +08002335 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07002336END art_quick_instrumentation_exit
2337
2338 /*
2339 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2340 * will long jump to the upcall with a special exception of -1.
2341 */
2342 .extern artDeoptimize
2343ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002344 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002345 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002346 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002347 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002348END art_quick_deoptimize
2349
Sebastien Hertz07474662015-08-25 15:12:33 +00002350 /*
2351 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2352 * will long jump to the upcall with a special exception of -1.
2353 */
2354 .extern artDeoptimizeFromCompiledCode
2355ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002356 SETUP_SAVE_EVERYTHING_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002357 mov x0, xSELF // Pass thread.
2358 bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*)
2359 brk 0
2360END art_quick_deoptimize_from_compiled_code
2361
Andreas Gamped58342c2014-06-05 14:18:08 -07002362
Serban Constantinescu169489b2014-06-11 16:43:35 +01002363 /*
2364 * String's indexOf.
2365 *
2366 * TODO: Not very optimized.
2367 * On entry:
2368 * x0: string object (known non-null)
2369 * w1: char to match (known <= 0xFFFF)
2370 * w2: Starting offset in string data
2371 */
2372ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002373 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08002374 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01002375
2376 /* Clamp start to [0..count] */
2377 cmp w2, #0
2378 csel w2, wzr, w2, lt
2379 cmp w2, w3
2380 csel w2, w3, w2, gt
2381
Serban Constantinescu169489b2014-06-11 16:43:35 +01002382 /* Save a copy to compute result */
2383 mov x5, x0
2384
2385 /* Build pointer to start of data to compare and pre-bias */
2386 add x0, x0, x2, lsl #1
2387 sub x0, x0, #2
2388
2389 /* Compute iteration count */
2390 sub w2, w3, w2
2391
2392 /*
2393 * At this point we have:
2394 * x0: start of the data to test
2395 * w1: char to compare
2396 * w2: iteration count
2397 * x5: original start of string data
2398 */
2399
2400 subs w2, w2, #4
2401 b.lt .Lindexof_remainder
2402
2403.Lindexof_loop4:
2404 ldrh w6, [x0, #2]!
2405 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002406 ldrh wIP0, [x0, #2]!
2407 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002408 cmp w6, w1
2409 b.eq .Lmatch_0
2410 cmp w7, w1
2411 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002412 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002413 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002414 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002415 b.eq .Lmatch_3
2416 subs w2, w2, #4
2417 b.ge .Lindexof_loop4
2418
2419.Lindexof_remainder:
2420 adds w2, w2, #4
2421 b.eq .Lindexof_nomatch
2422
2423.Lindexof_loop1:
2424 ldrh w6, [x0, #2]!
2425 cmp w6, w1
2426 b.eq .Lmatch_3
2427 subs w2, w2, #1
2428 b.ne .Lindexof_loop1
2429
2430.Lindexof_nomatch:
2431 mov x0, #-1
2432 ret
2433
2434.Lmatch_0:
2435 sub x0, x0, #6
2436 sub x0, x0, x5
2437 asr x0, x0, #1
2438 ret
2439.Lmatch_1:
2440 sub x0, x0, #4
2441 sub x0, x0, x5
2442 asr x0, x0, #1
2443 ret
2444.Lmatch_2:
2445 sub x0, x0, #2
2446 sub x0, x0, x5
2447 asr x0, x0, #1
2448 ret
2449.Lmatch_3:
2450 sub x0, x0, x5
2451 asr x0, x0, #1
2452 ret
2453END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002454
2455 /*
2456 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002457 * getting its argument and returning its result through W register
2458 * `wreg` (corresponding to X register `xreg`), saving and restoring
2459 * all caller-save registers.
2460 *
2461 * If `wreg` is different from `w0`, the generated function follows a
2462 * non-standard runtime calling convention:
2463 * - register `wreg` is used to pass the (sole) argument of this
2464 * function (instead of W0);
2465 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002466 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002467 * - W0 is treated like a normal (non-argument) caller-save register;
2468 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002469 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002470 */
Roland Levillain4359e612016-07-20 11:32:19 +01002471.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002472ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002473 // Reference is null, no work to do at all.
2474 cbz \wreg, .Lret_rb_\name
Roland Levillain4359e612016-07-20 11:32:19 +01002475 /*
2476 * Allocate 46 stack slots * 8 = 368 bytes:
2477 * - 20 slots for core registers X0-X19
2478 * - 24 slots for floating-point registers D0-D7 and D16-D31
2479 * - 1 slot for return address register XLR
2480 * - 1 padding slot for 16-byte stack alignment
2481 */
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002482 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2483 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2484 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lslow_path_rb_\name
2485 ret
2486.Lslow_path_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002487 // Save all potentially live caller-save core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +01002488 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 368
2489 SAVE_TWO_REGS x2, x3, 16
2490 SAVE_TWO_REGS x4, x5, 32
2491 SAVE_TWO_REGS x6, x7, 48
2492 SAVE_TWO_REGS x8, x9, 64
2493 SAVE_TWO_REGS x10, x11, 80
2494 SAVE_TWO_REGS x12, x13, 96
2495 SAVE_TWO_REGS x14, x15, 112
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01002496 SAVE_TWO_REGS x16, x17, 128
2497 SAVE_TWO_REGS x18, x19, 144
Roland Levillain4359e612016-07-20 11:32:19 +01002498 // Save all potentially live caller-save floating-point registers.
2499 stp d0, d1, [sp, #160]
2500 stp d2, d3, [sp, #176]
2501 stp d4, d5, [sp, #192]
2502 stp d6, d7, [sp, #208]
2503 stp d16, d17, [sp, #224]
2504 stp d18, d19, [sp, #240]
2505 stp d20, d21, [sp, #256]
2506 stp d22, d23, [sp, #272]
2507 stp d24, d25, [sp, #288]
2508 stp d26, d27, [sp, #304]
2509 stp d28, d29, [sp, #320]
2510 stp d30, d31, [sp, #336]
2511 // Save return address.
Vladimir Marko215076b2016-09-07 18:05:55 +01002512 // (sp + #352 is a padding slot)
2513 SAVE_REG xLR, 360
Roland Levillain4359e612016-07-20 11:32:19 +01002514
2515 .ifnc \wreg, w0
2516 mov w0, \wreg // Pass arg1 - obj from `wreg`
2517 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002518 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002519 .ifnc \wreg, w0
2520 mov \wreg, w0 // Return result into `wreg`
2521 .endif
2522
2523 // Restore core regs, except `xreg`, as `wreg` is used to return the
2524 // result of this function (simply remove it from the stack instead).
2525 POP_REGS_NE x0, x1, 0, \xreg
2526 POP_REGS_NE x2, x3, 16, \xreg
2527 POP_REGS_NE x4, x5, 32, \xreg
2528 POP_REGS_NE x6, x7, 48, \xreg
2529 POP_REGS_NE x8, x9, 64, \xreg
2530 POP_REGS_NE x10, x11, 80, \xreg
2531 POP_REGS_NE x12, x13, 96, \xreg
2532 POP_REGS_NE x14, x15, 112, \xreg
2533 POP_REGS_NE x16, x17, 128, \xreg
2534 POP_REGS_NE x18, x19, 144, \xreg
2535 // Restore floating-point registers.
2536 ldp d0, d1, [sp, #160]
2537 ldp d2, d3, [sp, #176]
2538 ldp d4, d5, [sp, #192]
2539 ldp d6, d7, [sp, #208]
2540 ldp d16, d17, [sp, #224]
2541 ldp d18, d19, [sp, #240]
2542 ldp d20, d21, [sp, #256]
2543 ldp d22, d23, [sp, #272]
2544 ldp d24, d25, [sp, #288]
2545 ldp d26, d27, [sp, #304]
2546 ldp d28, d29, [sp, #320]
2547 ldp d30, d31, [sp, #336]
2548 // Restore return address and remove padding.
Vladimir Marko215076b2016-09-07 18:05:55 +01002549 RESTORE_REG xLR, 360
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01002550 DECREASE_FRAME 368
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002551.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002552 ret
2553END \name
2554.endm
2555
Roland Levillain4359e612016-07-20 11:32:19 +01002556READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2557READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2558READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2559READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2560READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2561READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2562READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2563READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2564READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2565READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2566READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2567READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2568READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2569READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2570READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2571READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
Mathieu Chartier36c22712016-08-12 13:19:44 -07002572// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
Roland Levillain4359e612016-07-20 11:32:19 +01002573READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2574READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2575READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2576READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2577READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2578READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2579READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2580READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2581READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2582READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2583READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2584READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2585READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29