blob: e9d03d7ceb2c37aa58b173641283b2c386492e3e [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 Marko3b7537b2016-09-13 11:56:01 +0000268 * 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 Marko3b7537b2016-09-13 11:56:01 +0000271.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 Marko3b7537b2016-09-13 11:56:01 +0000330 /*
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.
Vladimir Marko908eb222016-09-14 10:29:18 +0100403 bl 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
Vladimir Marko908eb222016-09-14 10:29:18 +0100436 bl \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.
Vladimir Marko908eb222016-09-14 10:29:18 +0100445 bl \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
Vladimir Marko908eb222016-09-14 10:29:18 +0100455 bl \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 Marko3b7537b2016-09-13 11:56:01 +0000474 .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.
Vladimir Marko908eb222016-09-14 10:29:18 +0100486 bl artThrowNullPointerExceptionFromSignal // (arg, Thread*).
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000487 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 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000513 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700514 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100515 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700516 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000517 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700518 * 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 +0000519 * of the target Method* in x0 and method->code_ in x1.
520 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700521 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000522 * thread and we branch to another stub to deliver it.
523 *
524 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
525 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700526 *
527 * Adapted from ARM32 code.
528 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800529 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000530 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700531.macro INVOKE_TRAMPOLINE_BODY cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000532 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100533 SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700534 // Helper signature is always
535 // (method_idx, *this_object, *caller_method, *self, sp)
536
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100537 mov x2, xSELF // pass Thread::Current
538 mov x3, sp
539 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800540 mov xIP0, x1 // save Method*->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100541 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700542 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800543 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07005441:
545 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700546.endm
547.macro INVOKE_TRAMPOLINE c_name, cxx_name
548ENTRY \c_name
549 INVOKE_TRAMPOLINE_BODY \cxx_name
Stuart Monteithb95a5342014-03-12 13:32:32 +0000550END \c_name
551.endm
552
Stuart Monteithb95a5342014-03-12 13:32:32 +0000553INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
554
555INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
556INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
557INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
558INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
559
Andreas Gampe03906cf2014-04-07 12:08:28 -0700560
561.macro INVOKE_STUB_CREATE_FRAME
562
Zheng Xu69a50302015-04-14 20:04:41 +0800563SAVE_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 -0700564SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
Andreas Gampecf4035a2014-05-28 22:43:01 -0700565
Andreas Gampe03906cf2014-04-07 12:08:28 -0700566
Zheng Xu48241e72014-05-23 11:52:42 +0800567 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700568 .cfi_register sp,x9
569
Zheng Xu48241e72014-05-23 11:52:42 +0800570 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700571 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
Zheng Xu48241e72014-05-23 11:52:42 +0800572 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
573 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700574
Zheng Xu48241e72014-05-23 11:52:42 +0800575 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
576 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700577 .cfi_adjust_cfa_offset SAVE_SIZE
578
Nicolas Geoffray48088462014-12-12 10:29:38 +0000579 str x28, [x10, #112]
580 .cfi_rel_offset x28, 112
581
582 stp x26, x27, [x10, #96]
583 .cfi_rel_offset x26, 96
584 .cfi_rel_offset x27, 104
585
586 stp x24, x25, [x10, #80]
587 .cfi_rel_offset x24, 80
588 .cfi_rel_offset x25, 88
589
590 stp x22, x23, [x10, #64]
591 .cfi_rel_offset x22, 64
592 .cfi_rel_offset x23, 72
593
594 stp x20, x21, [x10, #48]
595 .cfi_rel_offset x20, 48
596 .cfi_rel_offset x21, 56
597
Zheng Xu69a50302015-04-14 20:04:41 +0800598 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700599 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700600 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700601
Zheng Xu48241e72014-05-23 11:52:42 +0800602 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700603 .cfi_rel_offset x4, 16
604 .cfi_rel_offset x5, 24
605
Zheng Xu48241e72014-05-23 11:52:42 +0800606 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700607 .cfi_rel_offset x29, 0
608 .cfi_rel_offset x30, 8
609
Zheng Xu48241e72014-05-23 11:52:42 +0800610 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700611 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800612 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700613
614 // Copy arguments into stack frame.
615 // Use simple copy routine for now.
616 // 4 bytes per slot.
617 // X1 - source address
618 // W2 - args length
619 // X9 - destination address.
620 // W10 - temporary
Mathieu Chartiere401d142015-04-22 13:56:20 -0700621 add x9, sp, #8 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700622
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700623 // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler
624 // does not have unique-id variables.
6251:
Andreas Gampe03906cf2014-04-07 12:08:28 -0700626 cmp w2, #0
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700627 beq 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700628 sub w2, w2, #4 // Need 65536 bytes of range.
629 ldr w10, [x1, x2]
630 str w10, [x9, x2]
631
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700632 b 1b
Andreas Gampe03906cf2014-04-07 12:08:28 -0700633
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006342:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700635 // Store null into ArtMethod* at bottom of frame.
636 str xzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700637.endm
638
639.macro INVOKE_STUB_CALL_AND_RETURN
640
641 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartiere401d142015-04-22 13:56:20 -0700642 ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700643 // Branch to method.
644 blr x9
645
646 // Restore return value address and shorty address.
647 ldp x4,x5, [xFP, #16]
648 .cfi_restore x4
649 .cfi_restore x5
650
Nicolas Geoffray48088462014-12-12 10:29:38 +0000651 ldr x28, [xFP, #112]
652 .cfi_restore x28
653
654 ldp x26, x27, [xFP, #96]
655 .cfi_restore x26
656 .cfi_restore x27
657
658 ldp x24, x25, [xFP, #80]
659 .cfi_restore x24
660 .cfi_restore x25
661
662 ldp x22, x23, [xFP, #64]
663 .cfi_restore x22
664 .cfi_restore x23
665
666 ldp x20, x21, [xFP, #48]
667 .cfi_restore x20
668 .cfi_restore x21
669
Andreas Gampe03906cf2014-04-07 12:08:28 -0700670 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
671 ldrb w10, [x5]
672
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700673 // Check the return type and store the correct register into the jvalue in memory.
674 // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables.
675
Andreas Gampe03906cf2014-04-07 12:08:28 -0700676 // Don't set anything for a void type.
677 cmp w10, #'V'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700678 beq 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700679
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700680 // Is it a double?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700681 cmp w10, #'D'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700682 bne 1f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700683 str d0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700684 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700685
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006861: // Is it a float?
Andreas Gampe03906cf2014-04-07 12:08:28 -0700687 cmp w10, #'F'
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700688 bne 2f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700689 str s0, [x4]
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -0700690 b 3f
Andreas Gampe03906cf2014-04-07 12:08:28 -0700691
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006922: // Just store x0. Doesn't matter if it is 64 or 32 bits.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700693 str x0, [x4]
694
Chih-Hung Hsiehc0da7ac2015-07-27 10:10:44 -07006953: // Finish up.
Zheng Xu69a50302015-04-14 20:04:41 +0800696 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700697 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700698 mov sp, x2
699 .cfi_restore sp
700
Andreas Gamped58342c2014-06-05 14:18:08 -0700701 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700702 .cfi_restore x29
703 .cfi_restore x30
704
705 ret
706
707.endm
708
709
Stuart Monteithb95a5342014-03-12 13:32:32 +0000710/*
711 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
712 * uint32_t *args, x1
713 * uint32_t argsize, w2
714 * Thread *self, x3
715 * JValue *result, x4
716 * char *shorty); x5
717 * +----------------------+
718 * | |
719 * | C/C++ frame |
720 * | LR'' |
721 * | FP'' | <- SP'
722 * +----------------------+
723 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800724 * | x28 | <- TODO: Remove callee-saves.
725 * | : |
726 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000727 * | SP' |
728 * | X5 |
729 * | X4 | Saved registers
730 * | LR' |
731 * | FP' | <- FP
732 * +----------------------+
733 * | uint32_t out[n-1] |
734 * | : : | Outs
735 * | uint32_t out[0] |
Mathieu Chartiere401d142015-04-22 13:56:20 -0700736 * | ArtMethod* | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000737 * +----------------------+
738 *
739 * Outgoing registers:
740 * x0 - Method*
741 * x1-x7 - integer parameters.
742 * d0-d7 - Floating point parameters.
743 * xSELF = self
744 * SP = & of ArtMethod*
745 * x1 = "this" pointer.
746 *
747 */
748ENTRY art_quick_invoke_stub
749 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700750 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000751
752 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
753 // Parse the passed shorty to determine which register to load.
754 // Load addresses for routines that load WXSD registers.
755 adr x11, .LstoreW2
756 adr x12, .LstoreX2
757 adr x13, .LstoreS0
758 adr x14, .LstoreD0
759
760 // Initialize routine offsets to 0 for integers and floats.
761 // x8 for integers, x15 for floating point.
762 mov x8, #0
763 mov x15, #0
764
765 add x10, x5, #1 // Load shorty address, plus one to skip return value.
766 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
767
768 // Loop to fill registers.
769.LfillRegisters:
770 ldrb w17, [x10], #1 // Load next character in signature, and increment.
771 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
772
773 cmp w17, #'F' // is this a float?
774 bne .LisDouble
775
776 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700777 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000778
779 add x17, x13, x15 // Calculate subroutine to jump to.
780 br x17
781
782.LisDouble:
783 cmp w17, #'D' // is this a double?
784 bne .LisLong
785
786 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700787 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000788
789 add x17, x14, x15 // Calculate subroutine to jump to.
790 br x17
791
792.LisLong:
793 cmp w17, #'J' // is this a long?
794 bne .LisOther
795
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700796 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700797 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000798
799 add x17, x12, x8 // Calculate subroutine to jump to.
800 br x17
801
Stuart Monteithb95a5342014-03-12 13:32:32 +0000802.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700803 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700804 beq .Ladvance4
805
Stuart Monteithb95a5342014-03-12 13:32:32 +0000806 add x17, x11, x8 // Calculate subroutine to jump to.
807 br x17
808
Andreas Gampe03906cf2014-04-07 12:08:28 -0700809.Ladvance4:
810 add x9, x9, #4
811 b .LfillRegisters
812
813.Ladvance8:
814 add x9, x9, #8
815 b .LfillRegisters
816
Stuart Monteithb95a5342014-03-12 13:32:32 +0000817// Macro for loading a parameter into a register.
818// counter - the register with offset into these tables
819// size - the size of the register - 4 or 8 bytes.
820// register - the name of the register to be loaded.
821.macro LOADREG counter size register return
822 ldr \register , [x9], #\size
823 add \counter, \counter, 12
824 b \return
825.endm
826
827// Store ints.
828.LstoreW2:
829 LOADREG x8 4 w2 .LfillRegisters
830 LOADREG x8 4 w3 .LfillRegisters
831 LOADREG x8 4 w4 .LfillRegisters
832 LOADREG x8 4 w5 .LfillRegisters
833 LOADREG x8 4 w6 .LfillRegisters
834 LOADREG x8 4 w7 .LfillRegisters
835
836// Store longs.
837.LstoreX2:
838 LOADREG x8 8 x2 .LfillRegisters
839 LOADREG x8 8 x3 .LfillRegisters
840 LOADREG x8 8 x4 .LfillRegisters
841 LOADREG x8 8 x5 .LfillRegisters
842 LOADREG x8 8 x6 .LfillRegisters
843 LOADREG x8 8 x7 .LfillRegisters
844
845// Store singles.
846.LstoreS0:
847 LOADREG x15 4 s0 .LfillRegisters
848 LOADREG x15 4 s1 .LfillRegisters
849 LOADREG x15 4 s2 .LfillRegisters
850 LOADREG x15 4 s3 .LfillRegisters
851 LOADREG x15 4 s4 .LfillRegisters
852 LOADREG x15 4 s5 .LfillRegisters
853 LOADREG x15 4 s6 .LfillRegisters
854 LOADREG x15 4 s7 .LfillRegisters
855
856// Store doubles.
857.LstoreD0:
858 LOADREG x15 8 d0 .LfillRegisters
859 LOADREG x15 8 d1 .LfillRegisters
860 LOADREG x15 8 d2 .LfillRegisters
861 LOADREG x15 8 d3 .LfillRegisters
862 LOADREG x15 8 d4 .LfillRegisters
863 LOADREG x15 8 d5 .LfillRegisters
864 LOADREG x15 8 d6 .LfillRegisters
865 LOADREG x15 8 d7 .LfillRegisters
866
867
868.LcallFunction:
869
Andreas Gampe03906cf2014-04-07 12:08:28 -0700870 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000871
Stuart Monteithb95a5342014-03-12 13:32:32 +0000872END art_quick_invoke_stub
873
874/* extern"C"
875 * void art_quick_invoke_static_stub(ArtMethod *method, x0
876 * uint32_t *args, x1
877 * uint32_t argsize, w2
878 * Thread *self, x3
879 * JValue *result, x4
880 * char *shorty); x5
881 */
882ENTRY art_quick_invoke_static_stub
883 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700884 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000885
886 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
887 // Parse the passed shorty to determine which register to load.
888 // Load addresses for routines that load WXSD registers.
889 adr x11, .LstoreW1_2
890 adr x12, .LstoreX1_2
891 adr x13, .LstoreS0_2
892 adr x14, .LstoreD0_2
893
894 // Initialize routine offsets to 0 for integers and floats.
895 // x8 for integers, x15 for floating point.
896 mov x8, #0
897 mov x15, #0
898
899 add x10, x5, #1 // Load shorty address, plus one to skip return value.
900
901 // Loop to fill registers.
902.LfillRegisters2:
903 ldrb w17, [x10], #1 // Load next character in signature, and increment.
904 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
905
906 cmp w17, #'F' // is this a float?
907 bne .LisDouble2
908
909 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700910 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000911
912 add x17, x13, x15 // Calculate subroutine to jump to.
913 br x17
914
915.LisDouble2:
916 cmp w17, #'D' // is this a double?
917 bne .LisLong2
918
919 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700920 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000921
922 add x17, x14, x15 // Calculate subroutine to jump to.
923 br x17
924
925.LisLong2:
926 cmp w17, #'J' // is this a long?
927 bne .LisOther2
928
929 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700930 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000931
932 add x17, x12, x8 // Calculate subroutine to jump to.
933 br x17
934
Stuart Monteithb95a5342014-03-12 13:32:32 +0000935.LisOther2: // Everything else takes one vReg.
936 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700937 beq .Ladvance4_2
938
Stuart Monteithb95a5342014-03-12 13:32:32 +0000939 add x17, x11, x8 // Calculate subroutine to jump to.
940 br x17
941
Andreas Gampe03906cf2014-04-07 12:08:28 -0700942.Ladvance4_2:
943 add x9, x9, #4
944 b .LfillRegisters2
945
946.Ladvance8_2:
947 add x9, x9, #8
948 b .LfillRegisters2
949
Stuart Monteithb95a5342014-03-12 13:32:32 +0000950// Store ints.
951.LstoreW1_2:
952 LOADREG x8 4 w1 .LfillRegisters2
953 LOADREG x8 4 w2 .LfillRegisters2
954 LOADREG x8 4 w3 .LfillRegisters2
955 LOADREG x8 4 w4 .LfillRegisters2
956 LOADREG x8 4 w5 .LfillRegisters2
957 LOADREG x8 4 w6 .LfillRegisters2
958 LOADREG x8 4 w7 .LfillRegisters2
959
960// Store longs.
961.LstoreX1_2:
962 LOADREG x8 8 x1 .LfillRegisters2
963 LOADREG x8 8 x2 .LfillRegisters2
964 LOADREG x8 8 x3 .LfillRegisters2
965 LOADREG x8 8 x4 .LfillRegisters2
966 LOADREG x8 8 x5 .LfillRegisters2
967 LOADREG x8 8 x6 .LfillRegisters2
968 LOADREG x8 8 x7 .LfillRegisters2
969
970// Store singles.
971.LstoreS0_2:
972 LOADREG x15 4 s0 .LfillRegisters2
973 LOADREG x15 4 s1 .LfillRegisters2
974 LOADREG x15 4 s2 .LfillRegisters2
975 LOADREG x15 4 s3 .LfillRegisters2
976 LOADREG x15 4 s4 .LfillRegisters2
977 LOADREG x15 4 s5 .LfillRegisters2
978 LOADREG x15 4 s6 .LfillRegisters2
979 LOADREG x15 4 s7 .LfillRegisters2
980
981// Store doubles.
982.LstoreD0_2:
983 LOADREG x15 8 d0 .LfillRegisters2
984 LOADREG x15 8 d1 .LfillRegisters2
985 LOADREG x15 8 d2 .LfillRegisters2
986 LOADREG x15 8 d3 .LfillRegisters2
987 LOADREG x15 8 d4 .LfillRegisters2
988 LOADREG x15 8 d5 .LfillRegisters2
989 LOADREG x15 8 d6 .LfillRegisters2
990 LOADREG x15 8 d7 .LfillRegisters2
991
992
993.LcallFunction2:
994
Andreas Gampe03906cf2014-04-07 12:08:28 -0700995 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000996
Stuart Monteithb95a5342014-03-12 13:32:32 +0000997END art_quick_invoke_static_stub
998
Andreas Gampe03906cf2014-04-07 12:08:28 -0700999
Stuart Monteithb95a5342014-03-12 13:32:32 +00001000
Nicolas Geoffrayb331feb2016-02-05 16:51:53 +00001001/* extern"C" void art_quick_osr_stub(void** stack, x0
1002 * size_t stack_size_in_bytes, x1
1003 * const uin8_t* native_pc, x2
1004 * JValue *result, x3
1005 * char *shorty, x4
1006 * Thread *self) x5
1007 */
1008ENTRY art_quick_osr_stub
1009SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
1010 mov x9, sp // Save stack pointer.
1011 .cfi_register sp,x9
1012
1013 sub x10, sp, # SAVE_SIZE
1014 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
1015 mov sp, x10 // Set new SP.
1016
1017 str x28, [sp, #112]
1018 stp x26, x27, [sp, #96]
1019 stp x24, x25, [sp, #80]
1020 stp x22, x23, [sp, #64]
1021 stp x20, x21, [sp, #48]
1022 stp x9, x19, [sp, #32] // Save old stack pointer and x19.
1023 stp x3, x4, [sp, #16] // Save result and shorty addresses.
1024 stp xFP, xLR, [sp] // Store LR & FP.
1025 mov xSELF, x5 // Move thread pointer into SELF register.
1026
1027 sub sp, sp, #16
1028 str xzr, [sp] // Store null for ArtMethod* slot
1029 // Branch to stub.
1030 bl .Losr_entry
1031 add sp, sp, #16
1032
1033 // Restore return value address and shorty address.
1034 ldp x3,x4, [sp, #16]
1035 ldr x28, [sp, #112]
1036 ldp x26, x27, [sp, #96]
1037 ldp x24, x25, [sp, #80]
1038 ldp x22, x23, [sp, #64]
1039 ldp x20, x21, [sp, #48]
1040
1041 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
1042 ldrb w10, [x4]
1043
1044 // Check the return type and store the correct register into the jvalue in memory.
1045
1046 // Don't set anything for a void type.
1047 cmp w10, #'V'
1048 beq .Losr_exit
1049
1050 // Is it a double?
1051 cmp w10, #'D'
1052 bne .Lno_double
1053 str d0, [x3]
1054 b .Losr_exit
1055
1056.Lno_double: // Is it a float?
1057 cmp w10, #'F'
1058 bne .Lno_float
1059 str s0, [x3]
1060 b .Losr_exit
1061
1062.Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits.
1063 str x0, [x3]
1064
1065.Losr_exit: // Finish up.
1066 ldp x2, x19, [sp, #32] // Restore stack pointer and x19.
1067 ldp xFP, xLR, [sp] // Restore old frame pointer and link register.
1068 mov sp, x2
1069 ret
1070
1071.Losr_entry:
1072 // Update stack pointer for the callee
1073 sub sp, sp, x1
1074
1075 // Update link register slot expected by the callee.
1076 sub w1, w1, #8
1077 str lr, [sp, x1]
1078
1079 // Copy arguments into stack frame.
1080 // Use simple copy routine for now.
1081 // 4 bytes per slot.
1082 // X0 - source address
1083 // W1 - args length
1084 // SP - destination address.
1085 // W10 - temporary
1086.Losr_loop_entry:
1087 cmp w1, #0
1088 beq .Losr_loop_exit
1089 sub w1, w1, #4
1090 ldr w10, [x0, x1]
1091 str w10, [sp, x1]
1092 b .Losr_loop_entry
1093
1094.Losr_loop_exit:
1095 // Branch to the OSR entry point.
1096 br x2
1097
1098END art_quick_osr_stub
1099
Stuart Monteithb95a5342014-03-12 13:32:32 +00001100 /*
1101 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
1102 */
1103
1104ENTRY art_quick_do_long_jump
1105 // Load FPRs
1106 ldp d0, d1, [x1], #16
1107 ldp d2, d3, [x1], #16
1108 ldp d4, d5, [x1], #16
1109 ldp d6, d7, [x1], #16
1110 ldp d8, d9, [x1], #16
1111 ldp d10, d11, [x1], #16
1112 ldp d12, d13, [x1], #16
1113 ldp d14, d15, [x1], #16
1114 ldp d16, d17, [x1], #16
1115 ldp d18, d19, [x1], #16
1116 ldp d20, d21, [x1], #16
1117 ldp d22, d23, [x1], #16
1118 ldp d24, d25, [x1], #16
1119 ldp d26, d27, [x1], #16
1120 ldp d28, d29, [x1], #16
1121 ldp d30, d31, [x1]
1122
1123 // Load GPRs
1124 // TODO: lots of those are smashed, could optimize.
1125 add x0, x0, #30*8
Andreas Gampe639bdd12015-06-03 11:22:45 -07001126 ldp x30, x1, [x0], #-16 // LR & SP
Stuart Monteithb95a5342014-03-12 13:32:32 +00001127 ldp x28, x29, [x0], #-16
1128 ldp x26, x27, [x0], #-16
1129 ldp x24, x25, [x0], #-16
1130 ldp x22, x23, [x0], #-16
1131 ldp x20, x21, [x0], #-16
1132 ldp x18, x19, [x0], #-16
1133 ldp x16, x17, [x0], #-16
1134 ldp x14, x15, [x0], #-16
1135 ldp x12, x13, [x0], #-16
1136 ldp x10, x11, [x0], #-16
1137 ldp x8, x9, [x0], #-16
1138 ldp x6, x7, [x0], #-16
1139 ldp x4, x5, [x0], #-16
1140 ldp x2, x3, [x0], #-16
1141 mov sp, x1
1142
Andreas Gampe639bdd12015-06-03 11:22:45 -07001143 // Need to load PC, it's at the end (after the space for the unused XZR). Use x1.
1144 ldr x1, [x0, #33*8]
1145 // And the value of x0.
1146 ldr x0, [x0]
1147
1148 br x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001149END art_quick_do_long_jump
1150
Andreas Gampef4e910b2014-04-29 16:55:52 -07001151 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001152 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
1153 * possibly null object to lock.
1154 *
1155 * Derived from arm32 code.
1156 */
1157 .extern artLockObjectFromCode
1158ENTRY art_quick_lock_object
1159 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001160 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001161.Lretry_lock:
1162 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1163 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001164 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001165 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001166 cbnz w3, .Lnot_unlocked // already thin locked
1167 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1168 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001169 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001170 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001171 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001172 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001173.Lnot_unlocked: // x1: original lock word
1174 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001175 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1176 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1177 uxth w2, w2 // zero top 16 bits
1178 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1179 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001180 mov x3, x1 // copy the lock word to check count overflow.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001181 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits.
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001182 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 -07001183 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 -08001184 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1185 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1186 stxr w3, w2, [x4]
1187 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001188 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001189.Llock_stxr_fail:
1190 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001191.Lslow_lock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001192 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001193 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001194 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001195 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001196 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1197END art_quick_lock_object
1198
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001199ENTRY art_quick_lock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001200 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001201 mov x1, xSELF // pass Thread::Current
1202 bl artLockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001203 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001204 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1205END art_quick_lock_object_no_inline
1206
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001207 /*
1208 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1209 * x0 holds the possibly null object to lock.
1210 *
1211 * Derived from arm32 code.
1212 */
1213 .extern artUnlockObjectFromCode
1214ENTRY art_quick_unlock_object
1215 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001216 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1217.Lretry_unlock:
1218#ifndef USE_READ_BARRIER
1219 ldr w1, [x4]
1220#else
1221 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1222#endif
1223 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001224 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1225 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001226 mov x3, x1 // copy lock word to check thread id equality
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001227 and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001228 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001229 uxth w3, w3 // zero top 16 bits
1230 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001231 mov x3, x1 // copy lock word to detect transition to unlocked
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 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001234 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001235 // transition to unlocked
1236 mov x3, x1
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001237 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 -07001238 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001239#ifndef USE_READ_BARRIER
1240 str w3, [x4]
1241#else
1242 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1243 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1244#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001245 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001246.Lrecursive_thin_unlock: // w1: original lock word
1247 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1248#ifndef USE_READ_BARRIER
1249 str w1, [x4]
1250#else
1251 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1252 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1253#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001254 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001255.Lunlock_stxr_fail:
1256 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001257.Lslow_unlock:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001258 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001259 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001260 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001261 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001262 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1263END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001264
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001265ENTRY art_quick_unlock_object_no_inline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001266 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001267 mov x1, xSELF // pass Thread::Current
1268 bl artUnlockObjectFromCode // (Object* obj, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001269 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001270 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1271END art_quick_unlock_object_no_inline
1272
Andreas Gampe525cde22014-04-22 15:44:50 -07001273 /*
1274 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1275 * artThrowClassCastException.
1276 */
1277 .extern artThrowClassCastException
1278ENTRY art_quick_check_cast
1279 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001280 // Stack needs to be 16B aligned on calls.
Vladimir Marko215076b2016-09-07 18:05:55 +01001281 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1282 SAVE_REG xLR, 24
Andreas Gampe525cde22014-04-22 15:44:50 -07001283
1284 // Call runtime code
1285 bl artIsAssignableFromCode
1286
1287 // Check for exception
1288 cbz x0, .Lthrow_class_cast_exception
1289
1290 // Restore and return
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001291 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001292 RESTORE_REG xLR, 24
1293 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001294 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001295 .cfi_restore_state // Reset unwind info so following code unwinds.
Andreas Gampe6b90d422015-06-26 19:49:24 -07001296
Andreas Gampe525cde22014-04-22 15:44:50 -07001297.Lthrow_class_cast_exception:
1298 // Restore
Vladimir Marko215076b2016-09-07 18:05:55 +01001299 RESTORE_REG xLR, 24
1300 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001301
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001302 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context
Andreas Gampe525cde22014-04-22 15:44:50 -07001303 mov x2, xSELF // pass Thread::Current
Vladimir Marko908eb222016-09-14 10:29:18 +01001304 bl artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001305 brk 0 // We should not return here...
1306END art_quick_check_cast
1307
Man Cao1aee9002015-07-14 22:31:42 -07001308// Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude.
1309.macro POP_REG_NE xReg, offset, xExclude
1310 .ifnc \xReg, \xExclude
1311 ldr \xReg, [sp, #\offset] // restore xReg
1312 .cfi_restore \xReg
1313 .endif
1314.endm
1315
Roland Levillain4359e612016-07-20 11:32:19 +01001316// Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude.
1317// Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude.
1318.macro POP_REGS_NE xReg1, xReg2, offset, xExclude
1319 .ifc \xReg1, \xExclude
1320 ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2
1321 .else
1322 .ifc \xReg2, \xExclude
1323 ldr \xReg1, [sp, #\offset] // restore xReg1
1324 .else
1325 ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2
1326 .endif
1327 .endif
1328 .cfi_restore \xReg1
1329 .cfi_restore \xReg2
1330.endm
1331
Man Cao1aee9002015-07-14 22:31:42 -07001332 /*
1333 * Macro to insert read barrier, only used in art_quick_aput_obj.
1334 * xDest, wDest and xObj are registers, offset is a defined literal such as
1335 * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle
1336 * name mismatch between instructions. This macro uses the lower 32b of register when possible.
1337 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1338 */
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001339.macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number
Man Cao1aee9002015-07-14 22:31:42 -07001340#ifdef USE_READ_BARRIER
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001341#ifdef USE_BAKER_READ_BARRIER
1342 ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1343 tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number
1344 // False dependency to avoid needing load/load fence.
1345 add \xObj, \xObj, \xTemp, lsr #32
1346 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1347 UNPOISON_HEAP_REF \wDest
1348 b .Lrb_exit\number
1349#endif
1350.Lrb_slowpath\number:
Man Cao1aee9002015-07-14 22:31:42 -07001351 // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned.
Vladimir Marko215076b2016-09-07 18:05:55 +01001352 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48
1353 SAVE_TWO_REGS x2, x3, 16
1354 SAVE_TWO_REGS x4, xLR, 32
Man Cao1aee9002015-07-14 22:31:42 -07001355
Man Cao63069212015-08-21 15:51:39 -07001356 // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001357 .ifnc \xObj, x1
1358 mov x1, \xObj // pass xObj
1359 .endif
1360 mov w2, #\offset // pass offset
1361 bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset)
1362 // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning.
1363 .ifnc \wDest, w0
1364 mov \wDest, w0 // save return value in wDest
1365 .endif
1366
1367 // Conditionally restore saved registers
1368 POP_REG_NE x0, 0, \xDest
1369 POP_REG_NE x1, 8, \xDest
1370 POP_REG_NE x2, 16, \xDest
1371 POP_REG_NE x3, 24, \xDest
1372 POP_REG_NE x4, 32, \xDest
Vladimir Marko215076b2016-09-07 18:05:55 +01001373 RESTORE_REG xLR, 40
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001374 DECREASE_FRAME 48
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001375.Lrb_exit\number:
Man Cao1aee9002015-07-14 22:31:42 -07001376#else
1377 ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest.
1378 UNPOISON_HEAP_REF \wDest
1379#endif // USE_READ_BARRIER
1380.endm
1381
Andreas Gampef4e910b2014-04-29 16:55:52 -07001382 /*
1383 * Entry from managed code for array put operations of objects where the value being stored
1384 * needs to be checked for compatibility.
1385 * x0 = array, x1 = index, x2 = value
1386 *
1387 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1388 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1389 * using index-zero-extension in load/stores.
1390 *
1391 * Temporaries: x3, x4
1392 * TODO: x4 OK? ip seems wrong here.
1393 */
1394ENTRY art_quick_aput_obj_with_null_and_bound_check
1395 tst x0, x0
1396 bne art_quick_aput_obj_with_bound_check
1397 b art_quick_throw_null_pointer_exception
1398END art_quick_aput_obj_with_null_and_bound_check
1399
1400ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001401 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001402 cmp w3, w1
1403 bhi art_quick_aput_obj
1404 mov x0, x1
1405 mov x1, x3
1406 b art_quick_throw_array_bounds
1407END art_quick_aput_obj_with_bound_check
1408
Man Cao1aee9002015-07-14 22:31:42 -07001409#ifdef USE_READ_BARRIER
1410 .extern artReadBarrierSlow
1411#endif
Andreas Gampef4e910b2014-04-29 16:55:52 -07001412ENTRY art_quick_aput_obj
1413 cbz x2, .Ldo_aput_null
Mathieu Chartier4b5f7912016-07-21 14:59:04 -07001414 READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b
1415 // This also zero-extends to x3
1416 READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b
1417 // This also zero-extends to x3
1418 READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b
1419 // This also zero-extends to x4
Andreas Gampef4e910b2014-04-29 16:55:52 -07001420 cmp w3, w4 // value's type == array's component type - trivial assignability
1421 bne .Lcheck_assignability
1422.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001423 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001424 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001425 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001426 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1427 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1428 lsr x0, x0, #7
1429 strb w3, [x3, x0]
1430 ret
1431.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001432 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001433 // "Compress" = do nothing
1434 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1435 ret
1436.Lcheck_assignability:
1437 // Store arguments and link register
Vladimir Marko215076b2016-09-07 18:05:55 +01001438 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32
1439 SAVE_TWO_REGS x2, xLR, 16
Andreas Gampef4e910b2014-04-29 16:55:52 -07001440
1441 // Call runtime code
1442 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1443 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1444 bl artIsAssignableFromCode
1445
1446 // Check for exception
1447 cbz x0, .Lthrow_array_store_exception
1448
1449 // Restore
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001450 .cfi_remember_state
Vladimir Marko215076b2016-09-07 18:05:55 +01001451 RESTORE_TWO_REGS x2, xLR, 16
1452 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001453
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001454 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001455 // "Compress" = do nothing
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001456 POISON_HEAP_REF w2
Andreas Gampef4e910b2014-04-29 16:55:52 -07001457 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1458 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1459 lsr x0, x0, #7
1460 strb w3, [x3, x0]
1461 ret
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01001462 .cfi_restore_state // Reset unwind info so following code unwinds.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001463.Lthrow_array_store_exception:
Vladimir Marko215076b2016-09-07 18:05:55 +01001464 RESTORE_TWO_REGS x2, xLR, 16
1465 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001466
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001467 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko908eb222016-09-14 10:29:18 +01001468 mov x1, x2 // Pass value.
1469 mov x2, xSELF // Pass Thread::Current.
1470 bl artThrowArrayStoreException // (Object*, Object*, Thread*).
1471 brk 0 // Unreached.
Andreas Gampef4e910b2014-04-29 16:55:52 -07001472END art_quick_aput_obj
1473
Stuart Monteithb95a5342014-03-12 13:32:32 +00001474// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001475.macro ONE_ARG_DOWNCALL name, entrypoint, return
1476 .extern \entrypoint
1477ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001478 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001479 mov x1, xSELF // pass Thread::Current
1480 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001481 RESTORE_SAVE_REFS_ONLY_FRAME
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001482 \return
1483END \name
1484.endm
1485
1486// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001487.macro TWO_ARG_DOWNCALL name, entrypoint, return
1488 .extern \entrypoint
1489ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001490 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001491 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001492 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001493 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001494 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001495END \name
1496.endm
1497
Jeff Hao848f70a2014-01-15 13:49:50 -08001498// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001499.macro THREE_ARG_DOWNCALL name, entrypoint, return
1500 .extern \entrypoint
1501ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001502 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001503 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001504 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001505 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001506 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001507END \name
1508.endm
1509
Jeff Hao848f70a2014-01-15 13:49:50 -08001510// Macro to facilitate adding new allocation entrypoints.
1511.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1512 .extern \entrypoint
1513ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001514 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001515 mov x4, xSELF // pass Thread::Current
1516 bl \entrypoint //
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001517 RESTORE_SAVE_REFS_ONLY_FRAME
Jeff Hao848f70a2014-01-15 13:49:50 -08001518 \return
1519 DELIVER_PENDING_EXCEPTION
1520END \name
1521.endm
1522
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001523// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001524.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1525 .extern \entrypoint
1526ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001527 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1528 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001529 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001530 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001531 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001532 \return
1533END \name
1534.endm
1535
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001536.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1537 .extern \entrypoint
1538ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001539 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1540 ldr x2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001541 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001542 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001543 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001544 \return
1545END \name
1546.endm
1547
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001548.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1549 .extern \entrypoint
1550ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001551 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1552 ldr x3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001553 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001554 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001555 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001556 \return
1557END \name
1558.endm
1559
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001560.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1561 cbz w0, 1f // result zero branch over
1562 ret // return
15631:
1564 DELIVER_PENDING_EXCEPTION
1565.endm
1566
Matteo Franchindfd891a2014-04-30 12:17:17 +01001567 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001568 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1569 * failure.
1570 */
1571TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1572
1573 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001574 * Entry from managed code when uninitialized static storage, this stub will run the class
1575 * initializer and deliver the exception on error. On success the static storage base is
1576 * returned.
1577 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001578ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001579
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001580ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1581ONE_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 +01001582
Fred Shih37f05ef2014-07-16 18:38:08 -07001583ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1584ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1585ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1586ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001587ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1588ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1589ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1590
Fred Shih37f05ef2014-07-16 18:38:08 -07001591TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1592TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1593TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1594TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001595TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1596TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1597TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1598
Fred Shih37f05ef2014-07-16 18:38:08 -07001599TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1600TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001601TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1602TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1603
Fred Shih37f05ef2014-07-16 18:38:08 -07001604THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1605THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001606THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001607THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001608THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1609
1610// This is separated out as the argument order is different.
1611 .extern artSet64StaticFromCode
1612ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001613 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1614 ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer
Calin Juravlee460d1d2015-09-29 04:52:17 +01001615 // x2 contains the parameter
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001616 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001617 bl artSet64StaticFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001618 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001619 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1620END art_quick_set64_static
1621
Matteo Franchindfd891a2014-04-30 12:17:17 +01001622 /*
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001623 * Entry from managed code to resolve a string, this stub will
1624 * check the dex cache for a matching string (the fast path), and if not found,
1625 * it will allocate a String and deliver an exception on error.
1626 * On success the String is returned. R0 holds the string index.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001627 */
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001628
1629ENTRY art_quick_resolve_string
1630 ldr x1, [sp] // load referrer
1631 ldr w2, [x1, #ART_METHOD_DECLARING_CLASS_OFFSET] // load declaring class
1632 ldr x1, [x2, #DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET] // load string dex cache
Mathieu Chartiere3fbe382016-08-30 09:42:28 -07001633 ubfx x2, x0, #0, #STRING_DEX_CACHE_HASH_BITS // get masked string index into x2
Mathieu Chartier5f404332016-08-22 15:38:08 -07001634 ldr x2, [x1, x2, lsl #STRING_DEX_CACHE_ELEMENT_SIZE_SHIFT] // load dex cache pair into x2
1635 cmp x0, x2, lsr #32 // compare against upper 32 bits
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001636 bne .Lart_quick_resolve_string_slow_path
Mathieu Chartier5f404332016-08-22 15:38:08 -07001637 ubfx x0, x2, #0, #32 // extract lower 32 bits into x0
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001638#ifdef USE_READ_BARRIER
Mathieu Chartier5f404332016-08-22 15:38:08 -07001639 // Most common case: GC is not marking.
1640 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1641 cbnz x3, .Lart_quick_resolve_string_marking
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001642#endif
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001643 ret
1644
Mathieu Chartier5f404332016-08-22 15:38:08 -07001645// Slow path case, the index did not match.
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001646.Lart_quick_resolve_string_slow_path:
1647 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
1648 mov x1, xSELF // pass Thread::Current
Mathieu Chartier5f404332016-08-22 15:38:08 -07001649 bl artResolveStringFromCode // (int32_t string_idx, Thread* self)
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001650 RESTORE_SAVE_REFS_ONLY_FRAME
1651 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1652
Mathieu Chartier5f404332016-08-22 15:38:08 -07001653// GC is marking case, need to check the mark bit.
1654.Lart_quick_resolve_string_marking:
1655 ldr x3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1656 tbnz x3, #LOCK_WORD_MARK_BIT_SHIFT, .Lart_quick_resolve_string_no_rb
1657 // Save LR so that we can return, also x1 for alignment purposes.
Vladimir Marko215076b2016-09-07 18:05:55 +01001658 SAVE_TWO_REGS_INCREASE_FRAME x1, xLR, 16 // Save x1, LR.
Mathieu Chartier5f404332016-08-22 15:38:08 -07001659 bl artReadBarrierMark // Get the marked string back.
Vladimir Marko215076b2016-09-07 18:05:55 +01001660 RESTORE_TWO_REGS_DECREASE_FRAME x1, xLR, 16 // Restore registers.
Mathieu Chartier5f404332016-08-22 15:38:08 -07001661.Lart_quick_resolve_string_no_rb:
1662 ret
1663
Christina Wadsworthead8ba32016-08-08 13:08:05 -07001664END art_quick_resolve_string
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001665
Stuart Monteithb95a5342014-03-12 13:32:32 +00001666// Generate the allocation entrypoints for each allocator.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001667GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_REGION_TLAB_ALLOCATORS
1668// Comment out allocators that have arm64 specific asm.
1669// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) implemented in asm
1670// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB)
1671// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB)
1672GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1673// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) implemented in asm
1674// GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB)
1675GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1676GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB)
1677GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB)
1678GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB)
1679GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB)
1680GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB)
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001681
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001682// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1683ENTRY art_quick_alloc_object_rosalloc
1684 // Fast path rosalloc allocation.
1685 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1686 // x2-x7: free.
1687 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1688 // Load the class (x2)
1689 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1690 cbz x2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001691 ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local
1692 // allocation stack has room.
1693 // ldp won't work due to large offset.
1694 ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET]
1695 cmp x3, x4
1696 bhs .Lart_quick_alloc_object_rosalloc_slow_path
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001697 ldr w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3)
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001698 cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001699 // local allocation. Also does the
1700 // finalizable and initialization
1701 // checks.
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001702 bhs .Lart_quick_alloc_object_rosalloc_slow_path
1703 // Compute the rosalloc bracket index
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001704 // from the size. Since the size is
1705 // already aligned we can combine the
1706 // two shifts together.
1707 add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT)
1708 // Subtract pointer size since ther
1709 // are no runs for 0 byte allocations
1710 // and the size is already aligned.
1711 ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)]
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001712 // Load the free list head (x3). This
1713 // will be the return val.
1714 ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1715 cbz x3, .Lart_quick_alloc_object_rosalloc_slow_path
1716 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1717 ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head
1718 // and update the list head with the
1719 // next pointer.
1720 str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)]
1721 // Store the class pointer in the
1722 // header. This also overwrites the
1723 // next pointer. The offsets are
1724 // asserted to match.
1725#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1726#error "Class pointer needs to overwrite next pointer."
1727#endif
1728 POISON_HEAP_REF w2
1729 str w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001730 // Fence. This is "ish" not "ishst" so
1731 // that it also ensures ordering of
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001732 // the object size load with respect
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001733 // to later accesses to the class
1734 // object. Alternatively we could use
1735 // "ishst" if we use load-acquire for
Mathieu Chartier161db1d2016-09-01 14:06:54 -07001736 // the class status load.
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001737 // Needs to be done before pushing on
1738 // allocation since Heap::VisitObjects
1739 // relies on seeing the class pointer.
1740 // b/28790624
1741 dmb ish
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001742 // Push the new object onto the thread
1743 // local allocation stack and
1744 // increment the thread local
1745 // allocation stack top.
1746 ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1747 str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.)
1748 str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET]
1749 // Decrement the size of the free list
1750 ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
1751 sub x1, x1, #1
1752 // TODO: consider combining this store
1753 // and the list head store above using
1754 // strd.
1755 str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)]
Mathieu Chartier011dc2c2016-07-18 11:11:45 -07001756
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001757 mov x0, x3 // Set the return value and return.
1758 ret
1759.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001760 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001761 mov x2, xSELF // pass Thread::Current
1762 bl artAllocObjectFromCodeRosAlloc // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001763 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchi6f6244a2015-10-22 12:08:12 -07001764 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1765END art_quick_alloc_object_rosalloc
Stuart Monteithb95a5342014-03-12 13:32:32 +00001766
Mathieu Chartier8261d022016-08-08 09:41:04 -07001767
1768// The common fast path code for art_quick_alloc_array_region_tlab.
1769.macro ALLOC_ARRAY_TLAB_FAST_PATH slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1770 // Check null class
1771 cbz \wClass, \slowPathLabel
1772 ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED \slowPathLabel, \xClass, \wClass, \xCount, \wCount, \xTemp0, \wTemp0, \xTemp1, \wTemp1, \xTemp2, \wTemp2
1773.endm
1774
1775// The common fast path code for art_quick_alloc_array_region_tlab.
1776.macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2
1777 // Array classes are never finalizable or uninitialized, no need to check.
1778 ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type
1779 UNPOISON_HEAP_REF \wTemp0
1780 ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET]
1781 lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16
1782 // bits.
1783 // xCount is holding a 32 bit value,
1784 // it can not overflow.
1785 lsl \xTemp1, \xCount, \xTemp0 // Calculate data size
1786 // Add array data offset and alignment.
1787 add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK)
1788#if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4
1789#error Long array data offset must be 4 greater than int array data offset.
1790#endif
1791
1792 add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the
1793 // component size shift is 3
1794 // (for 64 bit alignment).
1795 and \xTemp0, \xTemp0, #4
1796 add \xTemp1, \xTemp1, \xTemp0
Mathieu Chartier2ee98f22016-08-10 10:08:58 -07001797 and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask
1798 // (addr + 7) & ~7. The mask must
1799 // be 64 bits to keep high bits in
1800 // case of overflow.
1801 // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value.
1802 // Negative ints become large 64 bit unsigned ints which will always be larger than max signed
1803 // 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 -07001804 cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow
1805 bhs \slowPathLabel // path.
1806
1807 ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that
1808 // we use (end - begin) to handle
1809 // negative size arrays. It is
1810 // assumed that a negative size will
1811 // always be greater unsigned than
1812 // region size.
1813 ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET]
1814 sub \xTemp2, \xTemp2, \xTemp0
1815 cmp \xTemp1, \xTemp2
1816 bhi \slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001817 // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1.
1818 // Move old thread_local_pos to x0
1819 // for the return value.
1820 mov x0, \xTemp0
1821 add \xTemp0, \xTemp0, \xTemp1
1822 str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
1823 ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1824 add \xTemp0, \xTemp0, #1
1825 str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1826 POISON_HEAP_REF \wClass
1827 str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1828 str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length.
1829 // Fence.
1830 dmb ishst
1831 ret
1832.endm
1833
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001834// The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab.
1835//
1836// x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current
1837// x3-x7: free.
1838// Need to preserve x0 and x1 to the slow path.
1839.macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel
1840 cbz x2, \slowPathLabel // Check null class
Mathieu Chartier8261d022016-08-08 09:41:04 -07001841 ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED \slowPathLabel
1842.endm
1843
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001844// TODO: delete ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since it is the same as
1845// ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001846.macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel
Mathieu Chartier8261d022016-08-08 09:41:04 -07001847 ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED \slowPathLabel
1848.endm
1849
1850.macro ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001851 ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET]
1852 ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET]
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001853 ldr w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7).
1854 add x6, x4, x7 // Add object size to tlab pos.
1855 cmp x6, x5 // Check if it fits, overflow works
1856 // since the tlab pos and end are 32
1857 // bit values.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001858 bhi \slowPathLabel
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001859 // "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 -07001860 mov x0, x4
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001861 str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001862 ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects.
1863 add x5, x5, #1
1864 str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET]
1865 POISON_HEAP_REF w2
1866 str w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer.
1867 // Fence. This is "ish" not "ishst" so
1868 // that the code after this allocation
1869 // site will see the right values in
1870 // the fields of the class.
1871 // Alternatively we could use "ishst"
1872 // if we use load-acquire for the
Mathieu Chartier93bbee02016-08-31 09:38:40 -07001873 // object size load.)
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001874 dmb ish
1875 ret
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001876.endm
1877
1878// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB).
1879ENTRY art_quick_alloc_object_tlab
1880 // Fast path tlab allocation.
1881 // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1882 // x2-x7: free.
1883#if defined(USE_READ_BARRIER)
1884 mvn x0, xzr // Read barrier not supported here.
1885 ret // Return -1.
1886#endif
1887 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1888 // Load the class (x2)
1889 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1890 ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001891.Lart_quick_alloc_object_tlab_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001892 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001893 mov x2, xSELF // Pass Thread::Current.
1894 bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001895 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchid72945c2016-03-16 11:23:10 -07001896 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1897END art_quick_alloc_object_tlab
1898
Mathieu Chartier8261d022016-08-08 09:41:04 -07001899// The common code for art_quick_alloc_object_*region_tlab
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001900.macro GENERATE_ALLOC_OBJECT_REGION_TLAB name, entrypoint, fast_path, is_resolved, read_barrier
Mathieu Chartier8261d022016-08-08 09:41:04 -07001901ENTRY \name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001902 // Fast path region tlab allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001903 // x0: type_idx/resolved class/return value, x1: ArtMethod*, xSELF(x19): Thread::Current
1904 // If is_resolved is 1 then x0 is the resolved type, otherwise it is the index.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001905 // x2-x7: free.
1906#if !defined(USE_READ_BARRIER)
1907 mvn x0, xzr // Read barrier must be enabled here.
1908 ret // Return -1.
1909#endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001910.if \is_resolved
1911 mov x2, x0 // class is actually stored in x0 already
1912.else
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001913 ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1914 // Load the class (x2)
1915 ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001916 // If the class is null, go slow path. The check is required to read the lock word.
1917 cbz w2, .Lslow_path\name
Mathieu Chartier8261d022016-08-08 09:41:04 -07001918.endif
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001919.if \read_barrier
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001920 // Most common case: GC is not marking.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001921 ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
Mathieu Chartier8261d022016-08-08 09:41:04 -07001922 cbnz x3, .Lmarking\name
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001923.endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001924.Ldo_allocation\name:
1925 \fast_path .Lslow_path\name
1926.Lmarking\name:
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001927.if \read_barrier
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001928 // GC is marking, check the lock word of the class for the mark bit.
Mathieu Chartier36a270a2016-07-28 18:08:51 -07001929 // Class is not null, check mark bit in lock word.
1930 ldr w3, [x2, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1931 // If the bit is not zero, do the allocation.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001932 tbnz w3, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001933 // The read barrier slow path. Mark
1934 // the class.
Vladimir Marko215076b2016-09-07 18:05:55 +01001935 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32 // Save registers (x0, x1, lr).
1936 SAVE_REG xLR, 24 // Align sp by 16 bytes.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001937 mov x0, x2 // Pass the class as the first param.
1938 bl artReadBarrierMark
1939 mov x2, x0 // Get the (marked) class back.
Vladimir Marko215076b2016-09-07 18:05:55 +01001940 RESTORE_REG xLR, 24
1941 RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 // Restore registers.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001942 b .Ldo_allocation\name
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001943.endif
Mathieu Chartier8261d022016-08-08 09:41:04 -07001944.Lslow_path\name:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001945 SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC.
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001946 mov x2, xSELF // Pass Thread::Current.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001947 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1948 RESTORE_SAVE_REFS_ONLY_FRAME
Hiroshi Yamauchicd773782016-04-07 17:18:24 -07001949 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Mathieu Chartier8261d022016-08-08 09:41:04 -07001950END \name
1951.endm
1952
Mathieu Chartierb6ec5d72016-08-30 15:06:54 -07001953// Use ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since the null check is already done in GENERATE_ALLOC_OBJECT_TLAB.
1954GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_region_tlab, artAllocObjectFromCodeRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 0, 1
1955// No read barrier for the resolved or initialized cases since the caller is responsible for the
1956// read barrier due to the to-space invariant.
1957GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 1, 0
1958GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED, 1, 0
1959
1960// TODO: We could use this macro for the normal tlab allocator too.
Mathieu Chartier8261d022016-08-08 09:41:04 -07001961
1962// The common code for art_quick_alloc_array_*region_tlab
1963.macro GENERATE_ALLOC_ARRAY_REGION_TLAB name, entrypoint, fast_path, is_resolved
1964ENTRY \name
1965 // Fast path array allocation for region tlab allocation.
1966 // x0: uint32_t type_idx
1967 // x1: int32_t component_count
1968 // x2: ArtMethod* method
1969 // x3-x7: free.
1970#if !defined(USE_READ_BARRIER)
1971 mvn x0, xzr // Read barrier must be enabled here.
1972 ret // Return -1.
1973#endif
1974.if \is_resolved
1975 mov x3, x0
1976 // If already resolved, class is stored in x0
1977.else
1978 ldr x3, [x2, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array
1979 // Load the class (x2)
1980 ldr w3, [x3, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT]
1981.endif
1982 // Most common case: GC is not marking.
1983 ldr w4, [xSELF, #THREAD_IS_GC_MARKING_OFFSET]
1984 cbnz x4, .Lmarking\name
1985.Ldo_allocation\name:
1986 \fast_path .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6
1987.Lmarking\name:
1988 // GC is marking, check the lock word of the class for the mark bit.
1989 // If the class is null, go slow path. The check is required to read the lock word.
1990 cbz w3, .Lslow_path\name
1991 // Class is not null, check mark bit in lock word.
1992 ldr w4, [x3, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
1993 // If the bit is not zero, do the allocation.
1994 tbnz w4, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name
1995 // The read barrier slow path. Mark
1996 // the class.
1997 stp x0, x1, [sp, #-32]! // Save registers (x0, x1, x2, lr).
1998 stp x2, xLR, [sp, #16]
1999 mov x0, x3 // Pass the class as the first param.
2000 bl artReadBarrierMark
2001 mov x3, x0 // Get the (marked) class back.
2002 ldp x2, xLR, [sp, #16]
2003 ldp x0, x1, [sp], #32 // Restore registers.
2004 b .Ldo_allocation\name
2005.Lslow_path\name:
2006 // x0: uint32_t type_idx / mirror::Class* klass (if resolved)
2007 // x1: int32_t component_count
2008 // x2: ArtMethod* method
2009 // x3: Thread* self
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002010 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC
Mathieu Chartier8261d022016-08-08 09:41:04 -07002011 mov x3, xSELF // pass Thread::Current
2012 bl \entrypoint
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002013 RESTORE_SAVE_REFS_ONLY_FRAME
Mathieu Chartier8261d022016-08-08 09:41:04 -07002014 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
2015END \name
2016.endm
2017
2018GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_region_tlab, artAllocArrayFromCodeRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH, 0
2019// TODO: art_quick_alloc_array_resolved_region_tlab seems to not get called. Investigate compiler.
2020GENERATE_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 -08002021
Zheng Xu48241e72014-05-23 11:52:42 +08002022 /*
Zheng Xu69a50302015-04-14 20:04:41 +08002023 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08002024 */
2025 .extern artTestSuspendFromCode
2026ENTRY art_quick_test_suspend
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002027 SETUP_SAVE_EVERYTHING_FRAME // save callee saves for stack crawl
Zheng Xu48241e72014-05-23 11:52:42 +08002028 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002029 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002030 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01002031 ret
Zheng Xu48241e72014-05-23 11:52:42 +08002032END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00002033
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002034ENTRY art_quick_implicit_suspend
2035 mov x0, xSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002036 SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002037 bl artTestSuspendFromCode // (Thread*)
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002038 RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01002039END art_quick_implicit_suspend
2040
Andreas Gampee62a07e2014-03-26 14:53:21 -07002041 /*
2042 * Called by managed code that is attempting to call a method on a proxy class. On entry
2043 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
2044 * method agrees with a ref and args callee save frame.
2045 */
2046 .extern artQuickProxyInvokeHandler
2047ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002048 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07002049 mov x2, xSELF // pass Thread::Current
2050 mov x3, sp // pass SP
2051 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002052 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07002053 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002054 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07002055 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07002056 ret // return on success
2057.Lexception_in_proxy:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002058 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07002059 DELIVER_PENDING_EXCEPTION
2060END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00002061
Andreas Gampe51f76352014-05-21 08:28:48 -07002062 /*
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002063 * Called to resolve an imt conflict.
2064 * x0 is the conflict ArtMethod.
2065 * xIP1 is a hidden argument that holds the target interface method's dex method index.
2066 *
2067 * Note that this stub writes to xIP0, xIP1, and x0.
Andreas Gampe51f76352014-05-21 08:28:48 -07002068 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002069 .extern artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002070ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002071 ldr xIP0, [sp, #0] // Load referrer
2072 ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64] // Load dex cache methods array
2073 ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT] // Load interface method
2074 ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable
2075 ldr x0, [xIP1] // Load first entry in ImtConflictTable.
2076.Limt_table_iterate:
2077 cmp x0, xIP0
2078 // Branch if found. Benchmarks have shown doing a branch here is better.
2079 beq .Limt_table_found
2080 // If the entry is null, the interface method is not in the ImtConflictTable.
2081 cbz x0, .Lconflict_trampoline
2082 // Iterate over the entries of the ImtConflictTable.
2083 ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]!
2084 b .Limt_table_iterate
2085.Limt_table_found:
Goran Jakovljevic59028d92016-03-29 18:05:03 +02002086 // We successfully hit an entry in the table. Load the target method
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002087 // and jump to it.
2088 ldr x0, [xIP1, #__SIZEOF_POINTER__]
2089 ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64]
2090 br xIP0
2091.Lconflict_trampoline:
2092 // Call the runtime stub to populate the ImtConflictTable and jump to the
2093 // resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07002094 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Andreas Gampe51f76352014-05-21 08:28:48 -07002095END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00002096
2097ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002098 SETUP_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002099 mov x2, xSELF
2100 mov x3, sp
2101 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01002102 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08002103 mov xIP0, x0 // Remember returned code pointer in xIP0.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002104 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002105 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08002106 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000021071:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002108 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002109 DELIVER_PENDING_EXCEPTION
2110END art_quick_resolution_trampoline
2111
2112/*
2113 * Generic JNI frame layout:
2114 *
2115 * #-------------------#
2116 * | |
2117 * | caller method... |
2118 * #-------------------# <--- SP on entry
2119 * | Return X30/LR |
2120 * | X29/FP | callee save
2121 * | X28 | callee save
2122 * | X27 | callee save
2123 * | X26 | callee save
2124 * | X25 | callee save
2125 * | X24 | callee save
2126 * | X23 | callee save
2127 * | X22 | callee save
2128 * | X21 | callee save
2129 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08002130 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00002131 * | X7 | arg7
2132 * | X6 | arg6
2133 * | X5 | arg5
2134 * | X4 | arg4
2135 * | X3 | arg3
2136 * | X2 | arg2
2137 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002138 * | D7 | float arg 8
2139 * | D6 | float arg 7
2140 * | D5 | float arg 6
2141 * | D4 | float arg 5
2142 * | D3 | float arg 4
2143 * | D2 | float arg 3
2144 * | D1 | float arg 2
2145 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07002146 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002147 * #-------------------#
2148 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07002149 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00002150 * #-------------------#
2151 * | JNI Call Stack |
2152 * #-------------------# <--- SP on native call
2153 * | |
2154 * | Stack for Regs | The trampoline assembly will pop these values
2155 * | | into registers for native call
2156 * #-------------------#
2157 * | Native code ptr |
2158 * #-------------------#
2159 * | Free scratch |
2160 * #-------------------#
2161 * | Ptr to (1) | <--- SP
2162 * #-------------------#
2163 */
2164 /*
2165 * Called to do a generic JNI down-call
2166 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002167ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002168 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002169
2170 // Save SP , so we can have static CFI info.
2171 mov x28, sp
2172 .cfi_def_cfa_register x28
2173
2174 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002175 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002176 mov xFP, sp
2177
Zheng Xub551fdc2014-07-25 11:49:42 +08002178 mov xIP0, #5120
2179 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002180
2181 // prepare for artQuickGenericJniTrampoline call
2182 // (Thread*, SP)
2183 // x0 x1 <= C calling convention
2184 // xSELF xFP <= where they are
2185
2186 mov x0, xSELF // Thread*
2187 mov x1, xFP
2188 bl artQuickGenericJniTrampoline // (Thread*, sp)
2189
Andreas Gampec200a4a2014-06-16 18:39:09 -07002190 // The C call will have registered the complete save-frame on success.
2191 // The result of the call is:
2192 // x0: pointer to native code, 0 on error.
2193 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002194
Andreas Gampec200a4a2014-06-16 18:39:09 -07002195 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002196 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00002197
Andreas Gampec200a4a2014-06-16 18:39:09 -07002198 // Release part of the alloca.
2199 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00002200
Andreas Gampec200a4a2014-06-16 18:39:09 -07002201 // Save the code pointer
2202 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00002203
2204 // Load parameters from frame into registers.
2205 // TODO Check with artQuickGenericJniTrampoline.
2206 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002207 ldp x0, x1, [sp]
2208 ldp x2, x3, [sp, #16]
2209 ldp x4, x5, [sp, #32]
2210 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002211
Andreas Gampec200a4a2014-06-16 18:39:09 -07002212 ldp d0, d1, [sp, #64]
2213 ldp d2, d3, [sp, #80]
2214 ldp d4, d5, [sp, #96]
2215 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00002216
Andreas Gampec200a4a2014-06-16 18:39:09 -07002217 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00002218
Zheng Xub551fdc2014-07-25 11:49:42 +08002219 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002220
2221 // result sign extension is handled in C code
2222 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07002223 // (Thread*, result, result_f)
2224 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002225 mov x1, x0 // Result (from saved).
2226 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07002227 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00002228
2229 bl artQuickGenericJniEndTrampoline
2230
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002231 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01002232 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002233 cbnz x2, .Lexception_in_native
2234
Stuart Monteithb95a5342014-03-12 13:32:32 +00002235 // Tear down the alloca.
2236 mov sp, x28
2237 .cfi_def_cfa_register sp
2238
Stuart Monteithb95a5342014-03-12 13:32:32 +00002239 // Tear down the callee-save frame.
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002240 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00002241
2242 // store into fpr, for when it's a fpr return...
2243 fmov d0, x0
2244 ret
2245
Stuart Monteithb95a5342014-03-12 13:32:32 +00002246.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002247 // Move to x1 then sp to please assembler.
2248 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
2249 mov sp, x1
2250 .cfi_def_cfa_register sp
2251 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002252 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00002253END art_quick_generic_jni_trampoline
2254
2255/*
2256 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
2257 * of a quick call:
2258 * x0 = method being called/to bridge to.
2259 * x1..x7, d0..d7 = arguments to that method.
2260 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07002261ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002262 SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002263
2264 // x0 will contain mirror::ArtMethod* method.
2265 mov x1, xSELF // How to get Thread::Current() ???
2266 mov x2, sp
2267
2268 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
2269 // mirror::ArtMethod** sp)
2270 bl artQuickToInterpreterBridge
2271
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002272 RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00002273
2274 fmov d0, x0
2275
2276 RETURN_OR_DELIVER_PENDING_EXCEPTION
2277END art_quick_to_interpreter_bridge
2278
Andreas Gamped58342c2014-06-05 14:18:08 -07002279
2280//
2281// Instrumentation-related stubs
2282//
2283 .extern artInstrumentationMethodEntryFromCode
2284ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002285 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002286
Zheng Xub551fdc2014-07-25 11:49:42 +08002287 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07002288
2289 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002290 mov x3, xLR
2291 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07002292
Zheng Xub551fdc2014-07-25 11:49:42 +08002293 mov xIP0, x0 // x0 = result of call.
2294 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07002295
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002296 RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07002297 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08002298 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07002299END art_quick_instrumentation_entry
2300
2301 .extern artInstrumentationMethodExitFromCode
2302ENTRY art_quick_instrumentation_exit
2303 mov xLR, #0 // Clobber LR for later checks.
2304
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002305 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002306
2307 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
2308 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
2309 // easier to have an extra small stack area.
2310
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002311 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07002312 .cfi_adjust_cfa_offset 16
2313 str d0, [sp, #8] // Save floating-point result.
2314
Andreas Gamped58342c2014-06-05 14:18:08 -07002315 add x1, sp, #16 // Pass SP.
2316 mov x2, x0 // Pass integer result.
2317 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02002318 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07002319 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
2320
Zheng Xub551fdc2014-07-25 11:49:42 +08002321 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07002322 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
2323
2324 ldr d0, [sp, #8] // Restore floating-point result.
Vladimir Marko215076b2016-09-07 18:05:55 +01002325 ldr x0, [sp], #16 // Restore integer result, and drop stack area.
Andreas Gamped58342c2014-06-05 14:18:08 -07002326 .cfi_adjust_cfa_offset 16
2327
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002328 POP_SAVE_REFS_ONLY_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002329
Zheng Xub551fdc2014-07-25 11:49:42 +08002330 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07002331END art_quick_instrumentation_exit
2332
2333 /*
2334 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2335 * will long jump to the upcall with a special exception of -1.
2336 */
2337 .extern artDeoptimize
2338ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002339 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07002340 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002341 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01002342 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07002343END art_quick_deoptimize
2344
Sebastien Hertz07474662015-08-25 15:12:33 +00002345 /*
2346 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2347 * will long jump to the upcall with a special exception of -1.
2348 */
2349 .extern artDeoptimizeFromCompiledCode
2350ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002351 SETUP_SAVE_EVERYTHING_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002352 mov x0, xSELF // Pass thread.
2353 bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*)
2354 brk 0
2355END art_quick_deoptimize_from_compiled_code
2356
Andreas Gamped58342c2014-06-05 14:18:08 -07002357
Serban Constantinescu169489b2014-06-11 16:43:35 +01002358 /*
2359 * String's indexOf.
2360 *
2361 * TODO: Not very optimized.
2362 * On entry:
2363 * x0: string object (known non-null)
2364 * w1: char to match (known <= 0xFFFF)
2365 * w2: Starting offset in string data
2366 */
2367ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002368 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08002369 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01002370
2371 /* Clamp start to [0..count] */
2372 cmp w2, #0
2373 csel w2, wzr, w2, lt
2374 cmp w2, w3
2375 csel w2, w3, w2, gt
2376
Serban Constantinescu169489b2014-06-11 16:43:35 +01002377 /* Save a copy to compute result */
2378 mov x5, x0
2379
2380 /* Build pointer to start of data to compare and pre-bias */
2381 add x0, x0, x2, lsl #1
2382 sub x0, x0, #2
2383
2384 /* Compute iteration count */
2385 sub w2, w3, w2
2386
2387 /*
2388 * At this point we have:
2389 * x0: start of the data to test
2390 * w1: char to compare
2391 * w2: iteration count
2392 * x5: original start of string data
2393 */
2394
2395 subs w2, w2, #4
2396 b.lt .Lindexof_remainder
2397
2398.Lindexof_loop4:
2399 ldrh w6, [x0, #2]!
2400 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08002401 ldrh wIP0, [x0, #2]!
2402 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01002403 cmp w6, w1
2404 b.eq .Lmatch_0
2405 cmp w7, w1
2406 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08002407 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002408 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08002409 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01002410 b.eq .Lmatch_3
2411 subs w2, w2, #4
2412 b.ge .Lindexof_loop4
2413
2414.Lindexof_remainder:
2415 adds w2, w2, #4
2416 b.eq .Lindexof_nomatch
2417
2418.Lindexof_loop1:
2419 ldrh w6, [x0, #2]!
2420 cmp w6, w1
2421 b.eq .Lmatch_3
2422 subs w2, w2, #1
2423 b.ne .Lindexof_loop1
2424
2425.Lindexof_nomatch:
2426 mov x0, #-1
2427 ret
2428
2429.Lmatch_0:
2430 sub x0, x0, #6
2431 sub x0, x0, x5
2432 asr x0, x0, #1
2433 ret
2434.Lmatch_1:
2435 sub x0, x0, #4
2436 sub x0, x0, x5
2437 asr x0, x0, #1
2438 ret
2439.Lmatch_2:
2440 sub x0, x0, #2
2441 sub x0, x0, x5
2442 asr x0, x0, #1
2443 ret
2444.Lmatch_3:
2445 sub x0, x0, x5
2446 asr x0, x0, #1
2447 ret
2448END art_quick_indexof
Roland Levillain02b75802016-07-13 11:54:35 +01002449
2450 /*
2451 * Create a function `name` calling the ReadBarrier::Mark routine,
Roland Levillain4359e612016-07-20 11:32:19 +01002452 * getting its argument and returning its result through W register
2453 * `wreg` (corresponding to X register `xreg`), saving and restoring
2454 * all caller-save registers.
2455 *
2456 * If `wreg` is different from `w0`, the generated function follows a
2457 * non-standard runtime calling convention:
2458 * - register `wreg` is used to pass the (sole) argument of this
2459 * function (instead of W0);
2460 * - register `wreg` is used to return the result of this function
Roland Levillain02b75802016-07-13 11:54:35 +01002461 * (instead of W0);
Roland Levillain02b75802016-07-13 11:54:35 +01002462 * - W0 is treated like a normal (non-argument) caller-save register;
2463 * - everything else is the same as in the standard runtime calling
Roland Levillain4359e612016-07-20 11:32:19 +01002464 * convention (e.g. standard callee-save registers are preserved).
Roland Levillain02b75802016-07-13 11:54:35 +01002465 */
Roland Levillain4359e612016-07-20 11:32:19 +01002466.macro READ_BARRIER_MARK_REG name, wreg, xreg
Roland Levillain02b75802016-07-13 11:54:35 +01002467ENTRY \name
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002468 // Reference is null, no work to do at all.
2469 cbz \wreg, .Lret_rb_\name
Roland Levillain4359e612016-07-20 11:32:19 +01002470 /*
2471 * Allocate 46 stack slots * 8 = 368 bytes:
2472 * - 20 slots for core registers X0-X19
2473 * - 24 slots for floating-point registers D0-D7 and D16-D31
2474 * - 1 slot for return address register XLR
2475 * - 1 padding slot for 16-byte stack alignment
2476 */
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002477 // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler.
2478 ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET]
2479 tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lslow_path_rb_\name
2480 ret
2481.Lslow_path_rb_\name:
Roland Levillain4359e612016-07-20 11:32:19 +01002482 // Save all potentially live caller-save core registers.
Vladimir Marko215076b2016-09-07 18:05:55 +01002483 SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 368
2484 SAVE_TWO_REGS x2, x3, 16
2485 SAVE_TWO_REGS x4, x5, 32
2486 SAVE_TWO_REGS x6, x7, 48
2487 SAVE_TWO_REGS x8, x9, 64
2488 SAVE_TWO_REGS x10, x11, 80
2489 SAVE_TWO_REGS x12, x13, 96
2490 SAVE_TWO_REGS x14, x15, 112
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01002491 SAVE_TWO_REGS x16, x17, 128
2492 SAVE_TWO_REGS x18, x19, 144
Roland Levillain4359e612016-07-20 11:32:19 +01002493 // Save all potentially live caller-save floating-point registers.
2494 stp d0, d1, [sp, #160]
2495 stp d2, d3, [sp, #176]
2496 stp d4, d5, [sp, #192]
2497 stp d6, d7, [sp, #208]
2498 stp d16, d17, [sp, #224]
2499 stp d18, d19, [sp, #240]
2500 stp d20, d21, [sp, #256]
2501 stp d22, d23, [sp, #272]
2502 stp d24, d25, [sp, #288]
2503 stp d26, d27, [sp, #304]
2504 stp d28, d29, [sp, #320]
2505 stp d30, d31, [sp, #336]
2506 // Save return address.
Vladimir Marko215076b2016-09-07 18:05:55 +01002507 // (sp + #352 is a padding slot)
2508 SAVE_REG xLR, 360
Roland Levillain4359e612016-07-20 11:32:19 +01002509
2510 .ifnc \wreg, w0
2511 mov w0, \wreg // Pass arg1 - obj from `wreg`
2512 .endif
Roland Levillain02b75802016-07-13 11:54:35 +01002513 bl artReadBarrierMark // artReadBarrierMark(obj)
Roland Levillain4359e612016-07-20 11:32:19 +01002514 .ifnc \wreg, w0
2515 mov \wreg, w0 // Return result into `wreg`
2516 .endif
2517
2518 // Restore core regs, except `xreg`, as `wreg` is used to return the
2519 // result of this function (simply remove it from the stack instead).
2520 POP_REGS_NE x0, x1, 0, \xreg
2521 POP_REGS_NE x2, x3, 16, \xreg
2522 POP_REGS_NE x4, x5, 32, \xreg
2523 POP_REGS_NE x6, x7, 48, \xreg
2524 POP_REGS_NE x8, x9, 64, \xreg
2525 POP_REGS_NE x10, x11, 80, \xreg
2526 POP_REGS_NE x12, x13, 96, \xreg
2527 POP_REGS_NE x14, x15, 112, \xreg
2528 POP_REGS_NE x16, x17, 128, \xreg
2529 POP_REGS_NE x18, x19, 144, \xreg
2530 // Restore floating-point registers.
2531 ldp d0, d1, [sp, #160]
2532 ldp d2, d3, [sp, #176]
2533 ldp d4, d5, [sp, #192]
2534 ldp d6, d7, [sp, #208]
2535 ldp d16, d17, [sp, #224]
2536 ldp d18, d19, [sp, #240]
2537 ldp d20, d21, [sp, #256]
2538 ldp d22, d23, [sp, #272]
2539 ldp d24, d25, [sp, #288]
2540 ldp d26, d27, [sp, #304]
2541 ldp d28, d29, [sp, #320]
2542 ldp d30, d31, [sp, #336]
2543 // Restore return address and remove padding.
Vladimir Marko215076b2016-09-07 18:05:55 +01002544 RESTORE_REG xLR, 360
Vladimir Markoae6ba1f2016-09-09 11:56:05 +01002545 DECREASE_FRAME 368
Mathieu Chartier36a270a2016-07-28 18:08:51 -07002546.Lret_rb_\name:
Roland Levillain02b75802016-07-13 11:54:35 +01002547 ret
2548END \name
2549.endm
2550
Roland Levillain4359e612016-07-20 11:32:19 +01002551READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0
2552READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1
2553READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2
2554READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3
2555READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4
2556READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5
2557READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6
2558READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7
2559READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8
2560READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9
2561READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10
2562READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11
2563READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12
2564READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13
2565READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14
2566READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15
Mathieu Chartier36c22712016-08-12 13:19:44 -07002567// READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked
Roland Levillain4359e612016-07-20 11:32:19 +01002568READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17
2569READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18
2570READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19
2571READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20
2572READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21
2573READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22
2574READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23
2575READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24
2576READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25
2577READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26
2578READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27
2579READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28
2580READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29