blob: 7eb6c16117ccbc533770683916948035501e70da [file] [log] [blame]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_arm64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21
22 /*
23 * Macro that sets up the callee save frame to conform with
24 * Runtime::CreateCalleeSaveMethod(kSaveAll)
25 */
26.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080027 adrp xIP0, :got:_ZN3art7Runtime9instance_E
28 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +000029
30 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +080031 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +000032
Zheng Xub551fdc2014-07-25 11:49:42 +080033 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -070034 THIS_LOAD_REQUIRES_READ_BARRIER
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010035
36 // Loads appropriate callee-save-method.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070037 ldr wIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070038
39 sub sp, sp, #176
40 .cfi_adjust_cfa_offset 176
41
42 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +080043#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176)
44#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070045#endif
46
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010047 // Stack alignment filler [sp, #8].
48 // FP callee-saves.
49 stp d8, d9, [sp, #16]
50 stp d10, d11, [sp, #32]
51 stp d12, d13, [sp, #48]
52 stp d14, d15, [sp, #64]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070053
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010054 // GP callee-saves
55 stp x19, x20, [sp, #80]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070056 .cfi_rel_offset x19, 80
Andreas Gampe5c1e4352014-04-21 19:28:24 -070057 .cfi_rel_offset x20, 88
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010058
59 stp x21, x22, [sp, #96]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070060 .cfi_rel_offset x21, 96
Andreas Gampe5c1e4352014-04-21 19:28:24 -070061 .cfi_rel_offset x22, 104
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010062
63 stp x23, x24, [sp, #112]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070064 .cfi_rel_offset x23, 112
Andreas Gampe5c1e4352014-04-21 19:28:24 -070065 .cfi_rel_offset x24, 120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010066
67 stp x25, x26, [sp, #128]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070068 .cfi_rel_offset x25, 128
Andreas Gampe5c1e4352014-04-21 19:28:24 -070069 .cfi_rel_offset x26, 136
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010070
71 stp x27, x28, [sp, #144]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070072 .cfi_rel_offset x27, 144
Andreas Gampe5c1e4352014-04-21 19:28:24 -070073 .cfi_rel_offset x28, 152
Andreas Gampe5c1e4352014-04-21 19:28:24 -070074
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010075 stp x29, xLR, [sp, #160]
76 .cfi_rel_offset x29, 160
Andreas Gampe5c1e4352014-04-21 19:28:24 -070077 .cfi_rel_offset x30, 168
78
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010079 // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs].
80 str xIP0, [sp]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070081 // Place sp in Thread::Current()->top_quick_frame.
82 mov xIP0, sp
83 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +000084.endm
85
Zheng Xub551fdc2014-07-25 11:49:42 +080086 /*
87 * Macro that sets up the callee save frame to conform with
88 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
89 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070090.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080091 adrp xIP0, :got:_ZN3art7Runtime9instance_E
92 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
93
94 // Our registers aren't intermixed - just spill in order.
95 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
96
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010097 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefOnly] .
Zheng Xub551fdc2014-07-25 11:49:42 +080098 THIS_LOAD_REQUIRES_READ_BARRIER
Serban Constantinescu9bd88b02015-04-22 16:24:46 +010099
100 // Loads appropriate callee-save-method.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700101 ldr wIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
Zheng Xub551fdc2014-07-25 11:49:42 +0800102
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100103 sub sp, sp, #96
104 .cfi_adjust_cfa_offset 96
Zheng Xub551fdc2014-07-25 11:49:42 +0800105
106 // Ugly compile-time check, but we only have the preprocessor.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100107#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96)
Zheng Xub551fdc2014-07-25 11:49:42 +0800108#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
109#endif
110
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100111 // GP callee-saves.
112 // x20 paired with ArtMethod* - see below.
113 stp x21, x22, [sp, #16]
114 .cfi_rel_offset x21, 16
115 .cfi_rel_offset x22, 24
Zheng Xub551fdc2014-07-25 11:49:42 +0800116
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100117 stp x23, x24, [sp, #32]
118 .cfi_rel_offset x23, 32
119 .cfi_rel_offset x24, 40
Zheng Xub551fdc2014-07-25 11:49:42 +0800120
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100121 stp x25, x26, [sp, #48]
122 .cfi_rel_offset x25, 48
123 .cfi_rel_offset x26, 56
Zheng Xub551fdc2014-07-25 11:49:42 +0800124
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100125 stp x27, x28, [sp, #64]
126 .cfi_rel_offset x27, 64
127 .cfi_rel_offset x28, 72
Zheng Xub551fdc2014-07-25 11:49:42 +0800128
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100129 stp x29, xLR, [sp, #80]
130 .cfi_rel_offset x29, 80
131 .cfi_rel_offset x30, 88
Zheng Xub551fdc2014-07-25 11:49:42 +0800132
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100133 // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly].
134 stp xIP0, x20, [sp]
135 .cfi_rel_offset x20, 8
Zheng Xub551fdc2014-07-25 11:49:42 +0800136
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700137 // Place sp in Thread::Current()->top_quick_frame.
138 mov xIP0, sp
139 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800140.endm
141
142// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700143.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100144 // Callee-saves.
145 ldr x20, [sp, #8]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700146 .cfi_restore x20
Zheng Xu69a50302015-04-14 20:04:41 +0800147
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100148 ldp x21, x22, [sp, #16]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700149 .cfi_restore x21
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700150 .cfi_restore x22
Zheng Xu69a50302015-04-14 20:04:41 +0800151
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100152 ldp x23, x24, [sp, #32]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700153 .cfi_restore x23
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700154 .cfi_restore x24
Zheng Xu69a50302015-04-14 20:04:41 +0800155
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100156 ldp x25, x26, [sp, #48]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700157 .cfi_restore x25
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700158 .cfi_restore x26
Zheng Xu69a50302015-04-14 20:04:41 +0800159
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100160 ldp x27, x28, [sp, #64]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700161 .cfi_restore x27
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700162 .cfi_restore x28
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700163
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100164 ldp x29, xLR, [sp, #80]
Zheng Xu69a50302015-04-14 20:04:41 +0800165 .cfi_restore x29
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700166 .cfi_restore x30
167
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100168 add sp, sp, #96
169 .cfi_adjust_cfa_offset -96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000170.endm
171
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700172.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100173 add sp, sp, #96
174 .cfi_adjust_cfa_offset - 96
Andreas Gamped58342c2014-06-05 14:18:08 -0700175.endm
176
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700177.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
178 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800179 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000180.endm
181
182
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700183.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800184 sub sp, sp, #224
185 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000186
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700187 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +0800188#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700189#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
190#endif
191
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100192 // Stack alignment filler [sp, #8].
Zheng Xu69a50302015-04-14 20:04:41 +0800193 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100194 stp d0, d1, [sp, #16]
195 stp d2, d3, [sp, #32]
196 stp d4, d5, [sp, #48]
197 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000198
Zheng Xu69a50302015-04-14 20:04:41 +0800199 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100200 stp x1, x2, [sp, #80]
201 .cfi_rel_offset x1, 80
202 .cfi_rel_offset x2, 88
Stuart Monteithb95a5342014-03-12 13:32:32 +0000203
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100204 stp x3, x4, [sp, #96]
205 .cfi_rel_offset x3, 96
206 .cfi_rel_offset x4, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700207
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100208 stp x5, x6, [sp, #112]
209 .cfi_rel_offset x5, 112
210 .cfi_rel_offset x6, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700211
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100212 // x7, Callee-saves.
213 stp x7, x20, [sp, #128]
214 .cfi_rel_offset x7, 128
Zheng Xu69a50302015-04-14 20:04:41 +0800215 .cfi_rel_offset x20, 136
216
Zheng Xub551fdc2014-07-25 11:49:42 +0800217 stp x21, x22, [sp, #144]
218 .cfi_rel_offset x21, 144
219 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700220
Zheng Xub551fdc2014-07-25 11:49:42 +0800221 stp x23, x24, [sp, #160]
222 .cfi_rel_offset x23, 160
223 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700224
Zheng Xub551fdc2014-07-25 11:49:42 +0800225 stp x25, x26, [sp, #176]
226 .cfi_rel_offset x25, 176
227 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700228
Zheng Xub551fdc2014-07-25 11:49:42 +0800229 stp x27, x28, [sp, #192]
230 .cfi_rel_offset x27, 192
231 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700232
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100233 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800234 stp x29, xLR, [sp, #208]
235 .cfi_rel_offset x29, 208
236 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700237
Stuart Monteithb95a5342014-03-12 13:32:32 +0000238.endm
239
240 /*
241 * Macro that sets up the callee save frame to conform with
242 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
243 *
244 * TODO This is probably too conservative - saving FP & LR.
245 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700246.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800247 adrp xIP0, :got:_ZN3art7Runtime9instance_E
248 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000249
250 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +0800251 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +0000252
Zheng Xub551fdc2014-07-25 11:49:42 +0800253 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -0700254 THIS_LOAD_REQUIRES_READ_BARRIER
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700255 ldr wIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000256
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700257 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000258
Zheng Xub551fdc2014-07-25 11:49:42 +0800259 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700260 // Place sp in Thread::Current()->top_quick_frame.
261 mov xIP0, sp
262 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
263.endm
264
265.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
266 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
267 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
268 // Place sp in Thread::Current()->top_quick_frame.
269 mov xIP0, sp
270 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000271.endm
272
Zheng Xub551fdc2014-07-25 11:49:42 +0800273// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700274.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xu69a50302015-04-14 20:04:41 +0800275 // FP args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100276 ldp d0, d1, [sp, #16]
277 ldp d2, d3, [sp, #32]
278 ldp d4, d5, [sp, #48]
279 ldp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000280
Zheng Xu69a50302015-04-14 20:04:41 +0800281 // Core args.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100282 ldp x1, x2, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700283 .cfi_restore x1
284 .cfi_restore x2
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100285
286 ldp x3, x4, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700287 .cfi_restore x3
288 .cfi_restore x4
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100289
290 ldp x5, x6, [sp, #112]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700291 .cfi_restore x5
Zheng Xu69a50302015-04-14 20:04:41 +0800292 .cfi_restore x6
Andreas Gampe03906cf2014-04-07 12:08:28 -0700293
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100294 // x7, Callee-saves.
295 ldp x7, x20, [sp, #128]
296 .cfi_restore x7
Zheng Xu69a50302015-04-14 20:04:41 +0800297 .cfi_restore x20
298
Zheng Xub551fdc2014-07-25 11:49:42 +0800299 ldp x21, x22, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700300 .cfi_restore x21
301 .cfi_restore x22
302
Zheng Xub551fdc2014-07-25 11:49:42 +0800303 ldp x23, x24, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700304 .cfi_restore x23
305 .cfi_restore x24
306
Zheng Xub551fdc2014-07-25 11:49:42 +0800307 ldp x25, x26, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700308 .cfi_restore x25
309 .cfi_restore x26
310
Zheng Xub551fdc2014-07-25 11:49:42 +0800311 ldp x27, x28, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700312 .cfi_restore x27
313 .cfi_restore x28
314
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100315 // x29(callee-save) and LR.
Zheng Xub551fdc2014-07-25 11:49:42 +0800316 ldp x29, xLR, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700317 .cfi_restore x29
318 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000319
Zheng Xub551fdc2014-07-25 11:49:42 +0800320 add sp, sp, #224
321 .cfi_adjust_cfa_offset -224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000322.endm
323
324.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700325 cbnz x0, 1f // result non-zero branch over
326 ret // return
3271:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000328.endm
329
330.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700331 cbz x0, 1f // result zero branch over
332 ret // return
3331:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000334.endm
335
336 /*
337 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
338 * exception is Thread::Current()->exception_
339 */
340.macro DELIVER_PENDING_EXCEPTION
341 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
342 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000343
344 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700345 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000346 brk 0 // Unreached
347.endm
348
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700349.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
350 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
351 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000352 ret
3531:
354 DELIVER_PENDING_EXCEPTION
355.endm
356
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700357.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800358 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700359.endm
360
361// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
362.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
363 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
364.endm
365
366.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
367 cbnz w0, 1f // result non-zero branch over
368 ret // return
3691:
370 DELIVER_PENDING_EXCEPTION
371.endm
372
Stuart Monteithb95a5342014-03-12 13:32:32 +0000373.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
374 .extern \cxx_name
375ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700376 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800377 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700378 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000379END \c_name
380.endm
381
382.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
383 .extern \cxx_name
384ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100385 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800386 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700387 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000388 brk 0
389END \c_name
390.endm
391
392.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
393 .extern \cxx_name
394ENTRY \c_name
395 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800396 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700397 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000398 brk 0
399END \c_name
400.endm
401
402 /*
403 * Called by managed code, saves callee saves and then calls artThrowException
404 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
405 */
406ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
407
408 /*
409 * Called by managed code to create and deliver a NullPointerException.
410 */
411NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
412
413 /*
414 * Called by managed code to create and deliver an ArithmeticException.
415 */
416NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
417
418 /*
419 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
420 * index, arg2 holds limit.
421 */
422TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
423
424 /*
425 * Called by managed code to create and deliver a StackOverflowError.
426 */
427NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
428
429 /*
430 * Called by managed code to create and deliver a NoSuchMethodError.
431 */
432ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
433
434 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000435 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700436 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100437 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700438 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000439 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700440 * 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 +0000441 * of the target Method* in x0 and method->code_ in x1.
442 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700443 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000444 * thread and we branch to another stub to deliver it.
445 *
446 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
447 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700448 *
449 * Adapted from ARM32 code.
450 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800451 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000452 */
453.macro INVOKE_TRAMPOLINE c_name, cxx_name
454 .extern \cxx_name
455ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700456 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700457 // Helper signature is always
458 // (method_idx, *this_object, *caller_method, *self, sp)
459
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100460 mov x2, xSELF // pass Thread::Current
461 mov x3, sp
462 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800463 mov xIP0, x1 // save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700464 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700465 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800466 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07004671:
468 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +0000469END \c_name
470.endm
471
472INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
473INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
474
475INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
476INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
477INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
478INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
479
Andreas Gampe03906cf2014-04-07 12:08:28 -0700480
481.macro INVOKE_STUB_CREATE_FRAME
482
Zheng Xu69a50302015-04-14 20:04:41 +0800483SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700484SAVE_SIZE_AND_METHOD=SAVE_SIZE+STACK_REFERENCE_SIZE
485
Andreas Gampe03906cf2014-04-07 12:08:28 -0700486
Zheng Xu48241e72014-05-23 11:52:42 +0800487 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700488 .cfi_register sp,x9
489
Zheng Xu48241e72014-05-23 11:52:42 +0800490 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
491 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
492 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
493 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700494
Zheng Xu48241e72014-05-23 11:52:42 +0800495 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
496 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700497 .cfi_adjust_cfa_offset SAVE_SIZE
498
Nicolas Geoffray48088462014-12-12 10:29:38 +0000499 str x28, [x10, #112]
500 .cfi_rel_offset x28, 112
501
502 stp x26, x27, [x10, #96]
503 .cfi_rel_offset x26, 96
504 .cfi_rel_offset x27, 104
505
506 stp x24, x25, [x10, #80]
507 .cfi_rel_offset x24, 80
508 .cfi_rel_offset x25, 88
509
510 stp x22, x23, [x10, #64]
511 .cfi_rel_offset x22, 64
512 .cfi_rel_offset x23, 72
513
514 stp x20, x21, [x10, #48]
515 .cfi_rel_offset x20, 48
516 .cfi_rel_offset x21, 56
517
Zheng Xu69a50302015-04-14 20:04:41 +0800518 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700519 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700520 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700521
Zheng Xu48241e72014-05-23 11:52:42 +0800522 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700523 .cfi_rel_offset x4, 16
524 .cfi_rel_offset x5, 24
525
Zheng Xu48241e72014-05-23 11:52:42 +0800526 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700527 .cfi_rel_offset x29, 0
528 .cfi_rel_offset x30, 8
529
Zheng Xu48241e72014-05-23 11:52:42 +0800530 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700531 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800532 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700533
534 // Copy arguments into stack frame.
535 // Use simple copy routine for now.
536 // 4 bytes per slot.
537 // X1 - source address
538 // W2 - args length
539 // X9 - destination address.
540 // W10 - temporary
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700541 add x9, sp, #4 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700542
543 // Use \@ to differentiate between macro invocations.
544.LcopyParams\@:
545 cmp w2, #0
546 beq .LendCopyParams\@
547 sub w2, w2, #4 // Need 65536 bytes of range.
548 ldr w10, [x1, x2]
549 str w10, [x9, x2]
550
551 b .LcopyParams\@
552
553.LendCopyParams\@:
554
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700555 // Store null into StackReference<Method>* at bottom of frame.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700556 str wzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700557
Andreas Gampecf4035a2014-05-28 22:43:01 -0700558#if (STACK_REFERENCE_SIZE != 4)
559#error "STACK_REFERENCE_SIZE(ARM64) size not as expected."
560#endif
Andreas Gampe03906cf2014-04-07 12:08:28 -0700561.endm
562
563.macro INVOKE_STUB_CALL_AND_RETURN
564
565 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartier2d721012014-11-10 11:08:06 -0800566 ldr x9, [x0 , #MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700567 // Branch to method.
568 blr x9
569
570 // Restore return value address and shorty address.
571 ldp x4,x5, [xFP, #16]
572 .cfi_restore x4
573 .cfi_restore x5
574
Nicolas Geoffray48088462014-12-12 10:29:38 +0000575 ldr x28, [xFP, #112]
576 .cfi_restore x28
577
578 ldp x26, x27, [xFP, #96]
579 .cfi_restore x26
580 .cfi_restore x27
581
582 ldp x24, x25, [xFP, #80]
583 .cfi_restore x24
584 .cfi_restore x25
585
586 ldp x22, x23, [xFP, #64]
587 .cfi_restore x22
588 .cfi_restore x23
589
590 ldp x20, x21, [xFP, #48]
591 .cfi_restore x20
592 .cfi_restore x21
593
Andreas Gampe03906cf2014-04-07 12:08:28 -0700594 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
595 ldrb w10, [x5]
596
597 // Don't set anything for a void type.
598 cmp w10, #'V'
599 beq .Lexit_art_quick_invoke_stub\@
600
601 cmp w10, #'D'
602 bne .Lreturn_is_float\@
603 str d0, [x4]
604 b .Lexit_art_quick_invoke_stub\@
605
606.Lreturn_is_float\@:
607 cmp w10, #'F'
608 bne .Lreturn_is_int\@
609 str s0, [x4]
610 b .Lexit_art_quick_invoke_stub\@
611
612 // Just store x0. Doesn't matter if it is 64 or 32 bits.
613.Lreturn_is_int\@:
614 str x0, [x4]
615
616.Lexit_art_quick_invoke_stub\@:
Zheng Xu69a50302015-04-14 20:04:41 +0800617 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700618 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700619 mov sp, x2
620 .cfi_restore sp
621
Andreas Gamped58342c2014-06-05 14:18:08 -0700622 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700623 .cfi_restore x29
624 .cfi_restore x30
625
626 ret
627
628.endm
629
630
Stuart Monteithb95a5342014-03-12 13:32:32 +0000631/*
632 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
633 * uint32_t *args, x1
634 * uint32_t argsize, w2
635 * Thread *self, x3
636 * JValue *result, x4
637 * char *shorty); x5
638 * +----------------------+
639 * | |
640 * | C/C++ frame |
641 * | LR'' |
642 * | FP'' | <- SP'
643 * +----------------------+
644 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800645 * | x28 | <- TODO: Remove callee-saves.
646 * | : |
647 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000648 * | SP' |
649 * | X5 |
650 * | X4 | Saved registers
651 * | LR' |
652 * | FP' | <- FP
653 * +----------------------+
654 * | uint32_t out[n-1] |
655 * | : : | Outs
656 * | uint32_t out[0] |
Andreas Gampecf4035a2014-05-28 22:43:01 -0700657 * | StackRef<ArtMethod> | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000658 * +----------------------+
659 *
660 * Outgoing registers:
661 * x0 - Method*
662 * x1-x7 - integer parameters.
663 * d0-d7 - Floating point parameters.
664 * xSELF = self
665 * SP = & of ArtMethod*
666 * x1 = "this" pointer.
667 *
668 */
669ENTRY art_quick_invoke_stub
670 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700671 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000672
673 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
674 // Parse the passed shorty to determine which register to load.
675 // Load addresses for routines that load WXSD registers.
676 adr x11, .LstoreW2
677 adr x12, .LstoreX2
678 adr x13, .LstoreS0
679 adr x14, .LstoreD0
680
681 // Initialize routine offsets to 0 for integers and floats.
682 // x8 for integers, x15 for floating point.
683 mov x8, #0
684 mov x15, #0
685
686 add x10, x5, #1 // Load shorty address, plus one to skip return value.
687 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
688
689 // Loop to fill registers.
690.LfillRegisters:
691 ldrb w17, [x10], #1 // Load next character in signature, and increment.
692 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
693
694 cmp w17, #'F' // is this a float?
695 bne .LisDouble
696
697 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700698 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000699
700 add x17, x13, x15 // Calculate subroutine to jump to.
701 br x17
702
703.LisDouble:
704 cmp w17, #'D' // is this a double?
705 bne .LisLong
706
707 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700708 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000709
710 add x17, x14, x15 // Calculate subroutine to jump to.
711 br x17
712
713.LisLong:
714 cmp w17, #'J' // is this a long?
715 bne .LisOther
716
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700717 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700718 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000719
720 add x17, x12, x8 // Calculate subroutine to jump to.
721 br x17
722
Stuart Monteithb95a5342014-03-12 13:32:32 +0000723.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700724 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700725 beq .Ladvance4
726
Stuart Monteithb95a5342014-03-12 13:32:32 +0000727 add x17, x11, x8 // Calculate subroutine to jump to.
728 br x17
729
Andreas Gampe03906cf2014-04-07 12:08:28 -0700730.Ladvance4:
731 add x9, x9, #4
732 b .LfillRegisters
733
734.Ladvance8:
735 add x9, x9, #8
736 b .LfillRegisters
737
Stuart Monteithb95a5342014-03-12 13:32:32 +0000738// Macro for loading a parameter into a register.
739// counter - the register with offset into these tables
740// size - the size of the register - 4 or 8 bytes.
741// register - the name of the register to be loaded.
742.macro LOADREG counter size register return
743 ldr \register , [x9], #\size
744 add \counter, \counter, 12
745 b \return
746.endm
747
748// Store ints.
749.LstoreW2:
750 LOADREG x8 4 w2 .LfillRegisters
751 LOADREG x8 4 w3 .LfillRegisters
752 LOADREG x8 4 w4 .LfillRegisters
753 LOADREG x8 4 w5 .LfillRegisters
754 LOADREG x8 4 w6 .LfillRegisters
755 LOADREG x8 4 w7 .LfillRegisters
756
757// Store longs.
758.LstoreX2:
759 LOADREG x8 8 x2 .LfillRegisters
760 LOADREG x8 8 x3 .LfillRegisters
761 LOADREG x8 8 x4 .LfillRegisters
762 LOADREG x8 8 x5 .LfillRegisters
763 LOADREG x8 8 x6 .LfillRegisters
764 LOADREG x8 8 x7 .LfillRegisters
765
766// Store singles.
767.LstoreS0:
768 LOADREG x15 4 s0 .LfillRegisters
769 LOADREG x15 4 s1 .LfillRegisters
770 LOADREG x15 4 s2 .LfillRegisters
771 LOADREG x15 4 s3 .LfillRegisters
772 LOADREG x15 4 s4 .LfillRegisters
773 LOADREG x15 4 s5 .LfillRegisters
774 LOADREG x15 4 s6 .LfillRegisters
775 LOADREG x15 4 s7 .LfillRegisters
776
777// Store doubles.
778.LstoreD0:
779 LOADREG x15 8 d0 .LfillRegisters
780 LOADREG x15 8 d1 .LfillRegisters
781 LOADREG x15 8 d2 .LfillRegisters
782 LOADREG x15 8 d3 .LfillRegisters
783 LOADREG x15 8 d4 .LfillRegisters
784 LOADREG x15 8 d5 .LfillRegisters
785 LOADREG x15 8 d6 .LfillRegisters
786 LOADREG x15 8 d7 .LfillRegisters
787
788
789.LcallFunction:
790
Andreas Gampe03906cf2014-04-07 12:08:28 -0700791 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000792
Stuart Monteithb95a5342014-03-12 13:32:32 +0000793END art_quick_invoke_stub
794
795/* extern"C"
796 * void art_quick_invoke_static_stub(ArtMethod *method, x0
797 * uint32_t *args, x1
798 * uint32_t argsize, w2
799 * Thread *self, x3
800 * JValue *result, x4
801 * char *shorty); x5
802 */
803ENTRY art_quick_invoke_static_stub
804 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700805 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000806
807 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
808 // Parse the passed shorty to determine which register to load.
809 // Load addresses for routines that load WXSD registers.
810 adr x11, .LstoreW1_2
811 adr x12, .LstoreX1_2
812 adr x13, .LstoreS0_2
813 adr x14, .LstoreD0_2
814
815 // Initialize routine offsets to 0 for integers and floats.
816 // x8 for integers, x15 for floating point.
817 mov x8, #0
818 mov x15, #0
819
820 add x10, x5, #1 // Load shorty address, plus one to skip return value.
821
822 // Loop to fill registers.
823.LfillRegisters2:
824 ldrb w17, [x10], #1 // Load next character in signature, and increment.
825 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
826
827 cmp w17, #'F' // is this a float?
828 bne .LisDouble2
829
830 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700831 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000832
833 add x17, x13, x15 // Calculate subroutine to jump to.
834 br x17
835
836.LisDouble2:
837 cmp w17, #'D' // is this a double?
838 bne .LisLong2
839
840 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700841 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000842
843 add x17, x14, x15 // Calculate subroutine to jump to.
844 br x17
845
846.LisLong2:
847 cmp w17, #'J' // is this a long?
848 bne .LisOther2
849
850 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700851 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000852
853 add x17, x12, x8 // Calculate subroutine to jump to.
854 br x17
855
Stuart Monteithb95a5342014-03-12 13:32:32 +0000856.LisOther2: // Everything else takes one vReg.
857 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700858 beq .Ladvance4_2
859
Stuart Monteithb95a5342014-03-12 13:32:32 +0000860 add x17, x11, x8 // Calculate subroutine to jump to.
861 br x17
862
Andreas Gampe03906cf2014-04-07 12:08:28 -0700863.Ladvance4_2:
864 add x9, x9, #4
865 b .LfillRegisters2
866
867.Ladvance8_2:
868 add x9, x9, #8
869 b .LfillRegisters2
870
Stuart Monteithb95a5342014-03-12 13:32:32 +0000871// Store ints.
872.LstoreW1_2:
873 LOADREG x8 4 w1 .LfillRegisters2
874 LOADREG x8 4 w2 .LfillRegisters2
875 LOADREG x8 4 w3 .LfillRegisters2
876 LOADREG x8 4 w4 .LfillRegisters2
877 LOADREG x8 4 w5 .LfillRegisters2
878 LOADREG x8 4 w6 .LfillRegisters2
879 LOADREG x8 4 w7 .LfillRegisters2
880
881// Store longs.
882.LstoreX1_2:
883 LOADREG x8 8 x1 .LfillRegisters2
884 LOADREG x8 8 x2 .LfillRegisters2
885 LOADREG x8 8 x3 .LfillRegisters2
886 LOADREG x8 8 x4 .LfillRegisters2
887 LOADREG x8 8 x5 .LfillRegisters2
888 LOADREG x8 8 x6 .LfillRegisters2
889 LOADREG x8 8 x7 .LfillRegisters2
890
891// Store singles.
892.LstoreS0_2:
893 LOADREG x15 4 s0 .LfillRegisters2
894 LOADREG x15 4 s1 .LfillRegisters2
895 LOADREG x15 4 s2 .LfillRegisters2
896 LOADREG x15 4 s3 .LfillRegisters2
897 LOADREG x15 4 s4 .LfillRegisters2
898 LOADREG x15 4 s5 .LfillRegisters2
899 LOADREG x15 4 s6 .LfillRegisters2
900 LOADREG x15 4 s7 .LfillRegisters2
901
902// Store doubles.
903.LstoreD0_2:
904 LOADREG x15 8 d0 .LfillRegisters2
905 LOADREG x15 8 d1 .LfillRegisters2
906 LOADREG x15 8 d2 .LfillRegisters2
907 LOADREG x15 8 d3 .LfillRegisters2
908 LOADREG x15 8 d4 .LfillRegisters2
909 LOADREG x15 8 d5 .LfillRegisters2
910 LOADREG x15 8 d6 .LfillRegisters2
911 LOADREG x15 8 d7 .LfillRegisters2
912
913
914.LcallFunction2:
915
Andreas Gampe03906cf2014-04-07 12:08:28 -0700916 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000917
Stuart Monteithb95a5342014-03-12 13:32:32 +0000918END art_quick_invoke_static_stub
919
Andreas Gampe03906cf2014-04-07 12:08:28 -0700920
Stuart Monteithb95a5342014-03-12 13:32:32 +0000921
922 /*
923 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
924 */
925
926ENTRY art_quick_do_long_jump
927 // Load FPRs
928 ldp d0, d1, [x1], #16
929 ldp d2, d3, [x1], #16
930 ldp d4, d5, [x1], #16
931 ldp d6, d7, [x1], #16
932 ldp d8, d9, [x1], #16
933 ldp d10, d11, [x1], #16
934 ldp d12, d13, [x1], #16
935 ldp d14, d15, [x1], #16
936 ldp d16, d17, [x1], #16
937 ldp d18, d19, [x1], #16
938 ldp d20, d21, [x1], #16
939 ldp d22, d23, [x1], #16
940 ldp d24, d25, [x1], #16
941 ldp d26, d27, [x1], #16
942 ldp d28, d29, [x1], #16
943 ldp d30, d31, [x1]
944
945 // Load GPRs
946 // TODO: lots of those are smashed, could optimize.
947 add x0, x0, #30*8
948 ldp x30, x1, [x0], #-16
949 ldp x28, x29, [x0], #-16
950 ldp x26, x27, [x0], #-16
951 ldp x24, x25, [x0], #-16
952 ldp x22, x23, [x0], #-16
953 ldp x20, x21, [x0], #-16
954 ldp x18, x19, [x0], #-16
955 ldp x16, x17, [x0], #-16
956 ldp x14, x15, [x0], #-16
957 ldp x12, x13, [x0], #-16
958 ldp x10, x11, [x0], #-16
959 ldp x8, x9, [x0], #-16
960 ldp x6, x7, [x0], #-16
961 ldp x4, x5, [x0], #-16
962 ldp x2, x3, [x0], #-16
963 mov sp, x1
964
965 // TODO: Is it really OK to use LR for the target PC?
966 mov x0, #0
967 mov x1, #0
968 br xLR
969END art_quick_do_long_jump
970
Andreas Gampef4e910b2014-04-29 16:55:52 -0700971 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700972 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
973 * possibly null object to lock.
974 *
975 * Derived from arm32 code.
976 */
977 .extern artLockObjectFromCode
978ENTRY art_quick_lock_object
979 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700980 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700981.Lretry_lock:
982 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
983 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800984 mov x3, x1
985 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
986 cbnz w3, .Lnot_unlocked // already thin locked
987 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
988 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700989 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800990 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700991 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700992 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -0800993.Lnot_unlocked: // x1: original lock word
994 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700995 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
996 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
997 uxth w2, w2 // zero top 16 bits
998 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
999 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001000 mov x3, x1 // copy the lock word to check count overflow.
1001 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits.
1002 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow
1003 lsr w3, w2, LOCK_WORD_READ_BARRIER_STATE_SHIFT // if either of the upper two bits (28-29) are set, we overflowed.
1004 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1005 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1006 stxr w3, w2, [x4]
1007 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001008 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001009.Llock_stxr_fail:
1010 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001011.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001012 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001013 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001014 bl artLockObjectFromCode // (Object* obj, Thread*)
1015 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001016 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1017END art_quick_lock_object
1018
1019 /*
1020 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1021 * x0 holds the possibly null object to lock.
1022 *
1023 * Derived from arm32 code.
1024 */
1025 .extern artUnlockObjectFromCode
1026ENTRY art_quick_unlock_object
1027 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001028 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1029.Lretry_unlock:
1030#ifndef USE_READ_BARRIER
1031 ldr w1, [x4]
1032#else
1033 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1034#endif
1035 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001036 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1037 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001038 mov x3, x1 // copy lock word to check thread id equality
1039 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1040 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001041 uxth w3, w3 // zero top 16 bits
1042 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001043 mov x3, x1 // copy lock word to detect transition to unlocked
1044 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1045 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001046 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001047 // transition to unlocked
1048 mov x3, x1
1049 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK // w3: zero except for the preserved read barrier bits
Andreas Gampe675967d2014-05-14 16:28:34 -07001050 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001051#ifndef USE_READ_BARRIER
1052 str w3, [x4]
1053#else
1054 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1055 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1056#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001057 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001058.Lrecursive_thin_unlock: // w1: original lock word
1059 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1060#ifndef USE_READ_BARRIER
1061 str w1, [x4]
1062#else
1063 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1064 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1065#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001066 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001067.Lunlock_stxr_fail:
1068 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001069.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001070 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001071 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001072 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1073 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001074 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1075END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001076
1077 /*
1078 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1079 * artThrowClassCastException.
1080 */
1081 .extern artThrowClassCastException
1082ENTRY art_quick_check_cast
1083 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001084 // Stack needs to be 16B aligned on calls.
1085 stp x0, x1, [sp,#-32]!
Andreas Gampe525cde22014-04-22 15:44:50 -07001086 .cfi_adjust_cfa_offset 32
Andreas Gampe525cde22014-04-22 15:44:50 -07001087 .cfi_rel_offset x0, 0
1088 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001089 str xLR, [sp, #24]
Andreas Gampe525cde22014-04-22 15:44:50 -07001090 .cfi_rel_offset x30, 24
1091
1092 // Call runtime code
1093 bl artIsAssignableFromCode
1094
1095 // Check for exception
1096 cbz x0, .Lthrow_class_cast_exception
1097
1098 // Restore and return
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001099 ldr xLR, [sp, #24]
1100 .cfi_restore x30
1101 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001102 .cfi_restore x0
1103 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001104 .cfi_adjust_cfa_offset -32
1105 ret
1106
1107.Lthrow_class_cast_exception:
1108 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001109 ldr xLR, [sp, #24]
1110 .cfi_restore x30
1111 ldp x0, x1, [sp], #32
Andreas Gampe525cde22014-04-22 15:44:50 -07001112 .cfi_restore x0
1113 .cfi_restore x1
Andreas Gampe525cde22014-04-22 15:44:50 -07001114 .cfi_adjust_cfa_offset -32
1115
1116 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1117 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001118 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001119 brk 0 // We should not return here...
1120END art_quick_check_cast
1121
Andreas Gampef4e910b2014-04-29 16:55:52 -07001122 /*
1123 * Entry from managed code for array put operations of objects where the value being stored
1124 * needs to be checked for compatibility.
1125 * x0 = array, x1 = index, x2 = value
1126 *
1127 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1128 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1129 * using index-zero-extension in load/stores.
1130 *
1131 * Temporaries: x3, x4
1132 * TODO: x4 OK? ip seems wrong here.
1133 */
1134ENTRY art_quick_aput_obj_with_null_and_bound_check
1135 tst x0, x0
1136 bne art_quick_aput_obj_with_bound_check
1137 b art_quick_throw_null_pointer_exception
1138END art_quick_aput_obj_with_null_and_bound_check
1139
1140ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001141 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001142 cmp w3, w1
1143 bhi art_quick_aput_obj
1144 mov x0, x1
1145 mov x1, x3
1146 b art_quick_throw_array_bounds
1147END art_quick_aput_obj_with_bound_check
1148
1149ENTRY art_quick_aput_obj
1150 cbz x2, .Ldo_aput_null
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001151 ldr w3, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001152 // This also zero-extends to x3
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001153 ldr w4, [x2, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001154 // This also zero-extends to x4
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001155 ldr w3, [x3, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001156 // This also zero-extends to x3
1157 cmp w3, w4 // value's type == array's component type - trivial assignability
1158 bne .Lcheck_assignability
1159.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001160 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001161 // "Compress" = do nothing
1162 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1163 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1164 lsr x0, x0, #7
1165 strb w3, [x3, x0]
1166 ret
1167.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001168 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001169 // "Compress" = do nothing
1170 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1171 ret
1172.Lcheck_assignability:
1173 // Store arguments and link register
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001174 stp x0, x1, [sp,#-32]!
1175 .cfi_adjust_cfa_offset 32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001176 .cfi_rel_offset x0, 0
1177 .cfi_rel_offset x1, 8
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001178 stp x2, xLR, [sp, #16]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001179 .cfi_rel_offset x2, 16
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001180 .cfi_rel_offset x30, 24
Andreas Gampef4e910b2014-04-29 16:55:52 -07001181
1182 // Call runtime code
1183 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1184 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1185 bl artIsAssignableFromCode
1186
1187 // Check for exception
1188 cbz x0, .Lthrow_array_store_exception
1189
1190 // Restore
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001191 ldp x2, x30, [sp, #16]
1192 .cfi_restore x2
1193 .cfi_restore x30
1194 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001195 .cfi_restore x0
1196 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001197 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001198
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001199 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001200 // "Compress" = do nothing
1201 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1202 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1203 lsr x0, x0, #7
1204 strb w3, [x3, x0]
1205 ret
1206.Lthrow_array_store_exception:
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001207 ldp x2, x30, [sp, #16]
1208 .cfi_restore x2
1209 .cfi_restore x30
1210 ldp x0, x1, [sp], #32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001211 .cfi_restore x0
1212 .cfi_restore x1
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001213 .cfi_adjust_cfa_offset -32
Andreas Gampef4e910b2014-04-29 16:55:52 -07001214
1215 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1216 mov x1, x2 // Pass value.
1217 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001218 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001219 brk 0 // Unreached.
1220END art_quick_aput_obj
1221
Stuart Monteithb95a5342014-03-12 13:32:32 +00001222// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001223.macro ONE_ARG_DOWNCALL name, entrypoint, return
1224 .extern \entrypoint
1225ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001226 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001227 mov x1, xSELF // pass Thread::Current
1228 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1229 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1230 \return
1231END \name
1232.endm
1233
1234// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001235.macro TWO_ARG_DOWNCALL name, entrypoint, return
1236 .extern \entrypoint
1237ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001238 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001239 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001240 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1241 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001242 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001243END \name
1244.endm
1245
Jeff Hao848f70a2014-01-15 13:49:50 -08001246// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001247.macro THREE_ARG_DOWNCALL name, entrypoint, return
1248 .extern \entrypoint
1249ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001250 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001251 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001252 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001253 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001254 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001255END \name
1256.endm
1257
Jeff Hao848f70a2014-01-15 13:49:50 -08001258// Macro to facilitate adding new allocation entrypoints.
1259.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1260 .extern \entrypoint
1261ENTRY \name
1262 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1263 mov x4, xSELF // pass Thread::Current
1264 bl \entrypoint //
1265 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1266 \return
1267 DELIVER_PENDING_EXCEPTION
1268END \name
1269.endm
1270
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001271// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001272.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1273 .extern \entrypoint
1274ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001275 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001276 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001277 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001278 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001279 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001280 \return
1281END \name
1282.endm
1283
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001284.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1285 .extern \entrypoint
1286ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001287 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001288 ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001289 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001290 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001291 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001292 \return
1293END \name
1294.endm
1295
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001296.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1297 .extern \entrypoint
1298ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001299 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001300 ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001301 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001302 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001303 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001304 \return
1305END \name
1306.endm
1307
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001308.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1309 cbz w0, 1f // result zero branch over
1310 ret // return
13111:
1312 DELIVER_PENDING_EXCEPTION
1313.endm
1314
Matteo Franchindfd891a2014-04-30 12:17:17 +01001315 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001316 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1317 * failure.
1318 */
1319TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1320
1321 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001322 * Entry from managed code when uninitialized static storage, this stub will run the class
1323 * initializer and deliver the exception on error. On success the static storage base is
1324 * returned.
1325 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001326ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001327
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001328ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1329ONE_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 +01001330
Fred Shih37f05ef2014-07-16 18:38:08 -07001331ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1332ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1333ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1334ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001335ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1336ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1337ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1338
Fred Shih37f05ef2014-07-16 18:38:08 -07001339TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1340TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1341TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1342TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001343TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1344TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1345TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1346
Fred Shih37f05ef2014-07-16 18:38:08 -07001347TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1348TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001349TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1350TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1351
Fred Shih37f05ef2014-07-16 18:38:08 -07001352THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1353THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001354THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001355THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001356THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1357
1358// This is separated out as the argument order is different.
1359 .extern artSet64StaticFromCode
1360ENTRY art_quick_set64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001361 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001362 mov x3, x1 // Store value
Andreas Gampecf4035a2014-05-28 22:43:01 -07001363 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001364 mov x2, x3 // Put value param
1365 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001366 bl artSet64StaticFromCode
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001367 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001368 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1369END art_quick_set64_static
1370
Matteo Franchindfd891a2014-04-30 12:17:17 +01001371 /*
1372 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001373 * exception on error. On success the String is returned. w0 holds the string index. The fast
1374 * path check for hit in strings cache has already been performed.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001375 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001376ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001377
Stuart Monteithb95a5342014-03-12 13:32:32 +00001378// Generate the allocation entrypoints for each allocator.
1379GENERATE_ALL_ALLOC_ENTRYPOINTS
1380
Zheng Xu48241e72014-05-23 11:52:42 +08001381 /*
Zheng Xu69a50302015-04-14 20:04:41 +08001382 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08001383 */
1384 .extern artTestSuspendFromCode
1385ENTRY art_quick_test_suspend
1386 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
Zheng Xu48241e72014-05-23 11:52:42 +08001387 cbnz w0, .Lneed_suspend // check flags == 0
1388 ret // return if flags == 0
1389.Lneed_suspend:
1390 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001391 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1392 bl artTestSuspendFromCode // (Thread*)
1393 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +08001394END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001395
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001396ENTRY art_quick_implicit_suspend
1397 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001398 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1399 bl artTestSuspendFromCode // (Thread*)
1400 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001401END art_quick_implicit_suspend
1402
Andreas Gampee62a07e2014-03-26 14:53:21 -07001403 /*
1404 * Called by managed code that is attempting to call a method on a proxy class. On entry
1405 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1406 * method agrees with a ref and args callee save frame.
1407 */
1408 .extern artQuickProxyInvokeHandler
1409ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001410 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001411 mov x2, xSELF // pass Thread::Current
1412 mov x3, sp // pass SP
1413 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001414 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001415 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001416 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07001417 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001418 ret // return on success
1419.Lexception_in_proxy:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001420 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001421 DELIVER_PENDING_EXCEPTION
1422END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001423
Andreas Gampe51f76352014-05-21 08:28:48 -07001424 /*
Zheng Xub551fdc2014-07-25 11:49:42 +08001425 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's
Andreas Gampe51f76352014-05-21 08:28:48 -07001426 * dex method index.
1427 */
1428ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001429 mov x0, xIP1
Andreas Gampe51f76352014-05-21 08:28:48 -07001430 b art_quick_invoke_interface_trampoline
1431END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001432
1433ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001434 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001435 mov x2, xSELF
1436 mov x3, sp
1437 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001438 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001439 mov xIP0, x0 // Remember returned code pointer in xIP0.
Andreas Gampecf4035a2014-05-28 22:43:01 -07001440 ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001441 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001442 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000014431:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001444 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001445 DELIVER_PENDING_EXCEPTION
1446END art_quick_resolution_trampoline
1447
1448/*
1449 * Generic JNI frame layout:
1450 *
1451 * #-------------------#
1452 * | |
1453 * | caller method... |
1454 * #-------------------# <--- SP on entry
1455 * | Return X30/LR |
1456 * | X29/FP | callee save
1457 * | X28 | callee save
1458 * | X27 | callee save
1459 * | X26 | callee save
1460 * | X25 | callee save
1461 * | X24 | callee save
1462 * | X23 | callee save
1463 * | X22 | callee save
1464 * | X21 | callee save
1465 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08001466 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001467 * | X7 | arg7
1468 * | X6 | arg6
1469 * | X5 | arg5
1470 * | X4 | arg4
1471 * | X3 | arg3
1472 * | X2 | arg2
1473 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001474 * | D7 | float arg 8
1475 * | D6 | float arg 7
1476 * | D5 | float arg 6
1477 * | D4 | float arg 5
1478 * | D3 | float arg 4
1479 * | D2 | float arg 3
1480 * | D1 | float arg 2
1481 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001482 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001483 * #-------------------#
1484 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001485 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001486 * #-------------------#
1487 * | JNI Call Stack |
1488 * #-------------------# <--- SP on native call
1489 * | |
1490 * | Stack for Regs | The trampoline assembly will pop these values
1491 * | | into registers for native call
1492 * #-------------------#
1493 * | Native code ptr |
1494 * #-------------------#
1495 * | Free scratch |
1496 * #-------------------#
1497 * | Ptr to (1) | <--- SP
1498 * #-------------------#
1499 */
1500 /*
1501 * Called to do a generic JNI down-call
1502 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001503ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001504 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001505
1506 // Save SP , so we can have static CFI info.
1507 mov x28, sp
1508 .cfi_def_cfa_register x28
1509
1510 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001511 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001512 mov xFP, sp
1513
Zheng Xub551fdc2014-07-25 11:49:42 +08001514 mov xIP0, #5120
1515 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001516
1517 // prepare for artQuickGenericJniTrampoline call
1518 // (Thread*, SP)
1519 // x0 x1 <= C calling convention
1520 // xSELF xFP <= where they are
1521
1522 mov x0, xSELF // Thread*
1523 mov x1, xFP
1524 bl artQuickGenericJniTrampoline // (Thread*, sp)
1525
Andreas Gampec200a4a2014-06-16 18:39:09 -07001526 // The C call will have registered the complete save-frame on success.
1527 // The result of the call is:
1528 // x0: pointer to native code, 0 on error.
1529 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001530
Andreas Gampec200a4a2014-06-16 18:39:09 -07001531 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001532 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00001533
Andreas Gampec200a4a2014-06-16 18:39:09 -07001534 // Release part of the alloca.
1535 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001536
Andreas Gampec200a4a2014-06-16 18:39:09 -07001537 // Save the code pointer
1538 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001539
1540 // Load parameters from frame into registers.
1541 // TODO Check with artQuickGenericJniTrampoline.
1542 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001543 ldp x0, x1, [sp]
1544 ldp x2, x3, [sp, #16]
1545 ldp x4, x5, [sp, #32]
1546 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001547
Andreas Gampec200a4a2014-06-16 18:39:09 -07001548 ldp d0, d1, [sp, #64]
1549 ldp d2, d3, [sp, #80]
1550 ldp d4, d5, [sp, #96]
1551 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001552
Andreas Gampec200a4a2014-06-16 18:39:09 -07001553 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001554
Zheng Xub551fdc2014-07-25 11:49:42 +08001555 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001556
1557 // result sign extension is handled in C code
1558 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001559 // (Thread*, result, result_f)
1560 // x0 x1 x2 <= C calling convention
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001561 mov x1, x0 // Result (from saved).
1562 mov x0, xSELF // Thread register.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001563 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001564
1565 bl artQuickGenericJniEndTrampoline
1566
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001567 // Pending exceptions possible.
Serban Constantinescu9bd88b02015-04-22 16:24:46 +01001568 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001569 cbnz x2, .Lexception_in_native
1570
Stuart Monteithb95a5342014-03-12 13:32:32 +00001571 // Tear down the alloca.
1572 mov sp, x28
1573 .cfi_def_cfa_register sp
1574
Stuart Monteithb95a5342014-03-12 13:32:32 +00001575 // Tear down the callee-save frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001576 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001577
1578 // store into fpr, for when it's a fpr return...
1579 fmov d0, x0
1580 ret
1581
Stuart Monteithb95a5342014-03-12 13:32:32 +00001582.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001583 // Move to x1 then sp to please assembler.
1584 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
1585 mov sp, x1
1586 .cfi_def_cfa_register sp
1587 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001588 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001589END art_quick_generic_jni_trampoline
1590
1591/*
1592 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1593 * of a quick call:
1594 * x0 = method being called/to bridge to.
1595 * x1..x7, d0..d7 = arguments to that method.
1596 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001597ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001598 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001599
1600 // x0 will contain mirror::ArtMethod* method.
1601 mov x1, xSELF // How to get Thread::Current() ???
1602 mov x2, sp
1603
1604 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1605 // mirror::ArtMethod** sp)
1606 bl artQuickToInterpreterBridge
1607
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001608 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001609
1610 fmov d0, x0
1611
1612 RETURN_OR_DELIVER_PENDING_EXCEPTION
1613END art_quick_to_interpreter_bridge
1614
Andreas Gamped58342c2014-06-05 14:18:08 -07001615
1616//
1617// Instrumentation-related stubs
1618//
1619 .extern artInstrumentationMethodEntryFromCode
1620ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001621 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001622
Zheng Xub551fdc2014-07-25 11:49:42 +08001623 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07001624
1625 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001626 mov x3, xLR
1627 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07001628
Zheng Xub551fdc2014-07-25 11:49:42 +08001629 mov xIP0, x0 // x0 = result of call.
1630 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07001631
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001632 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07001633 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08001634 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07001635END art_quick_instrumentation_entry
1636
1637 .extern artInstrumentationMethodExitFromCode
1638ENTRY art_quick_instrumentation_exit
1639 mov xLR, #0 // Clobber LR for later checks.
1640
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001641 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001642
1643 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
1644 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
1645 // easier to have an extra small stack area.
1646
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001647 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07001648 .cfi_adjust_cfa_offset 16
1649 str d0, [sp, #8] // Save floating-point result.
1650
Andreas Gamped58342c2014-06-05 14:18:08 -07001651 add x1, sp, #16 // Pass SP.
1652 mov x2, x0 // Pass integer result.
1653 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001654 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07001655 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
1656
Zheng Xub551fdc2014-07-25 11:49:42 +08001657 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07001658 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
1659
1660 ldr d0, [sp, #8] // Restore floating-point result.
1661 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
1662 .cfi_adjust_cfa_offset 16
1663
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001664 POP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001665
Zheng Xub551fdc2014-07-25 11:49:42 +08001666 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07001667END art_quick_instrumentation_exit
1668
1669 /*
1670 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1671 * will long jump to the upcall with a special exception of -1.
1672 */
1673 .extern artDeoptimize
1674ENTRY art_quick_deoptimize
1675 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1676 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001677 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01001678 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07001679END art_quick_deoptimize
1680
1681
Serban Constantinescu169489b2014-06-11 16:43:35 +01001682 /*
1683 * String's indexOf.
1684 *
1685 * TODO: Not very optimized.
1686 * On entry:
1687 * x0: string object (known non-null)
1688 * w1: char to match (known <= 0xFFFF)
1689 * w2: Starting offset in string data
1690 */
1691ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001692 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001693 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01001694
1695 /* Clamp start to [0..count] */
1696 cmp w2, #0
1697 csel w2, wzr, w2, lt
1698 cmp w2, w3
1699 csel w2, w3, w2, gt
1700
Serban Constantinescu169489b2014-06-11 16:43:35 +01001701 /* Save a copy to compute result */
1702 mov x5, x0
1703
1704 /* Build pointer to start of data to compare and pre-bias */
1705 add x0, x0, x2, lsl #1
1706 sub x0, x0, #2
1707
1708 /* Compute iteration count */
1709 sub w2, w3, w2
1710
1711 /*
1712 * At this point we have:
1713 * x0: start of the data to test
1714 * w1: char to compare
1715 * w2: iteration count
1716 * x5: original start of string data
1717 */
1718
1719 subs w2, w2, #4
1720 b.lt .Lindexof_remainder
1721
1722.Lindexof_loop4:
1723 ldrh w6, [x0, #2]!
1724 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08001725 ldrh wIP0, [x0, #2]!
1726 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01001727 cmp w6, w1
1728 b.eq .Lmatch_0
1729 cmp w7, w1
1730 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08001731 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001732 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08001733 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001734 b.eq .Lmatch_3
1735 subs w2, w2, #4
1736 b.ge .Lindexof_loop4
1737
1738.Lindexof_remainder:
1739 adds w2, w2, #4
1740 b.eq .Lindexof_nomatch
1741
1742.Lindexof_loop1:
1743 ldrh w6, [x0, #2]!
1744 cmp w6, w1
1745 b.eq .Lmatch_3
1746 subs w2, w2, #1
1747 b.ne .Lindexof_loop1
1748
1749.Lindexof_nomatch:
1750 mov x0, #-1
1751 ret
1752
1753.Lmatch_0:
1754 sub x0, x0, #6
1755 sub x0, x0, x5
1756 asr x0, x0, #1
1757 ret
1758.Lmatch_1:
1759 sub x0, x0, #4
1760 sub x0, x0, x5
1761 asr x0, x0, #1
1762 ret
1763.Lmatch_2:
1764 sub x0, x0, #2
1765 sub x0, x0, x5
1766 asr x0, x0, #1
1767 ret
1768.Lmatch_3:
1769 sub x0, x0, x5
1770 asr x0, x0, #1
1771 ret
1772END art_quick_indexof
Andreas Gampe266340d2014-05-02 07:55:24 -07001773
1774 /*
1775 * String's compareTo.
1776 *
1777 * TODO: Not very optimized.
1778 *
1779 * On entry:
1780 * x0: this object pointer
1781 * x1: comp object pointer
1782 *
1783 */
Serban Constantinescu86797a72014-06-19 16:17:56 +01001784 .extern __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001785ENTRY art_quick_string_compareto
1786 mov x2, x0 // x0 is return, use x2 for first input.
1787 sub x0, x2, x1 // Same string object?
1788 cbnz x0,1f
1789 ret
17901: // Different string objects.
1791
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001792 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET]
1793 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001794 add x2, x2, #MIRROR_STRING_VALUE_OFFSET
1795 add x1, x1, #MIRROR_STRING_VALUE_OFFSET
Andreas Gampe266340d2014-05-02 07:55:24 -07001796
1797 /*
Jeff Hao848f70a2014-01-15 13:49:50 -08001798 * Now: Data* Count
1799 * first arg x2 w4
1800 * second arg x1 w3
Andreas Gampe266340d2014-05-02 07:55:24 -07001801 */
1802
1803 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4.
1804 subs x0, x4, x3
1805 // Min(count1, count2) into w3.
1806 csel x3, x3, x4, ge
1807
Serban Constantinescu169489b2014-06-11 16:43:35 +01001808 // TODO: Tune this value.
Andreas Gampe266340d2014-05-02 07:55:24 -07001809 // Check for long string, do memcmp16 for them.
1810 cmp w3, #28 // Constant from arm32.
1811 bgt .Ldo_memcmp16
1812
1813 /*
1814 * Now:
1815 * x2: *first string data
1816 * x1: *second string data
1817 * w3: iteration count
1818 * x0: return value if comparison equal
1819 * x4, x5, x6, x7: free
1820 */
1821
1822 // Do a simple unrolled loop.
1823.Lloop:
1824 // At least two more elements?
1825 subs w3, w3, #2
1826 b.lt .Lremainder_or_done
1827
1828 ldrh w4, [x2], #2
1829 ldrh w5, [x1], #2
1830
1831 ldrh w6, [x2], #2
1832 ldrh w7, [x1], #2
1833
1834 subs w4, w4, w5
1835 b.ne .Lw4_result
1836
1837 subs w6, w6, w7
1838 b.ne .Lw6_result
1839
1840 b .Lloop
1841
1842.Lremainder_or_done:
1843 adds w3, w3, #1
1844 b.eq .Lremainder
1845 ret
1846
1847.Lremainder:
1848 ldrh w4, [x2], #2
1849 ldrh w5, [x1], #2
1850 subs w4, w4, w5
1851 b.ne .Lw4_result
1852 ret
1853
1854// Result is in w4
1855.Lw4_result:
1856 sxtw x0, w4
1857 ret
1858
1859// Result is in w6
1860.Lw6_result:
1861 sxtw x0, w6
1862 ret
1863
1864.Ldo_memcmp16:
Zheng Xu62ddb322014-08-12 17:19:12 +08001865 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps.
1866 mov x15, xLR // TODO: Codify and check that?
Andreas Gampe266340d2014-05-02 07:55:24 -07001867
1868 mov x0, x2
1869 uxtw x2, w3
Serban Constantinescu86797a72014-06-19 16:17:56 +01001870 bl __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001871
Zheng Xu62ddb322014-08-12 17:19:12 +08001872 mov xLR, x15 // Restore LR.
Andreas Gampe266340d2014-05-02 07:55:24 -07001873
Serban Constantinescu86797a72014-06-19 16:17:56 +01001874 cmp x0, #0 // Check the memcmp difference.
Zheng Xu62ddb322014-08-12 17:19:12 +08001875 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1.
Andreas Gampe266340d2014-05-02 07:55:24 -07001876 ret
1877END art_quick_string_compareto