blob: 6b16a2e55d601f4b7272669b754624da07cd09fb [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
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070035 ldr wIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070036
37 sub sp, sp, #176
38 .cfi_adjust_cfa_offset 176
39
40 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +080041#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176)
42#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043#endif
44
45 // FP callee-saves
46 stp d8, d9, [sp, #8]
47 stp d10, d11, [sp, #24]
48 stp d12, d13, [sp, #40]
49 stp d14, d15, [sp, #56]
50
Zheng Xu69a50302015-04-14 20:04:41 +080051 // Thread register and x19 (callee-save)
52 stp xSELF, x19, [sp, #72]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070053 .cfi_rel_offset x18, 72
54 .cfi_rel_offset x19, 80
55
Zheng Xub551fdc2014-07-25 11:49:42 +080056 // callee-saves
Andreas Gampe5c1e4352014-04-21 19:28:24 -070057 stp x20, x21, [sp, #88]
58 .cfi_rel_offset x20, 88
59 .cfi_rel_offset x21, 96
60
61 stp x22, x23, [sp, #104]
62 .cfi_rel_offset x22, 104
63 .cfi_rel_offset x23, 112
64
65 stp x24, x25, [sp, #120]
66 .cfi_rel_offset x24, 120
67 .cfi_rel_offset x25, 128
68
69 stp x26, x27, [sp, #136]
70 .cfi_rel_offset x26, 136
71 .cfi_rel_offset x27, 144
72
Zheng Xub551fdc2014-07-25 11:49:42 +080073 stp x28, x29, [sp, #152]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070074 .cfi_rel_offset x28, 152
75 .cfi_rel_offset x29, 160
76
77 str xLR, [sp, #168]
78 .cfi_rel_offset x30, 168
79
80 // Loads appropriate callee-save-method
Zheng Xub551fdc2014-07-25 11:49:42 +080081 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070082 // Place sp in Thread::Current()->top_quick_frame.
83 mov xIP0, sp
84 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +000085.endm
86
Zheng Xub551fdc2014-07-25 11:49:42 +080087 /*
88 * Macro that sets up the callee save frame to conform with
89 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
90 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070091.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +080092 adrp xIP0, :got:_ZN3art7Runtime9instance_E
93 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
94
95 // Our registers aren't intermixed - just spill in order.
96 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
97
98 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
99 THIS_LOAD_REQUIRES_READ_BARRIER
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700100 ldr wIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
Zheng Xub551fdc2014-07-25 11:49:42 +0800101
Zheng Xu69a50302015-04-14 20:04:41 +0800102 sub sp, sp, #112
103 .cfi_adjust_cfa_offset 112
Zheng Xub551fdc2014-07-25 11:49:42 +0800104
105 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xu69a50302015-04-14 20:04:41 +0800106#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 112)
Zheng Xub551fdc2014-07-25 11:49:42 +0800107#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
108#endif
109
110 // Callee-saves
Zheng Xu69a50302015-04-14 20:04:41 +0800111 stp x19, x20, [sp, #16]
112 .cfi_rel_offset x19, 16
113 .cfi_rel_offset x20, 24
Zheng Xub551fdc2014-07-25 11:49:42 +0800114
Zheng Xu69a50302015-04-14 20:04:41 +0800115 stp x21, x22, [sp, #32]
116 .cfi_rel_offset x21, 32
117 .cfi_rel_offset x22, 40
Zheng Xub551fdc2014-07-25 11:49:42 +0800118
Zheng Xu69a50302015-04-14 20:04:41 +0800119 stp x23, x24, [sp, #48]
120 .cfi_rel_offset x23, 48
121 .cfi_rel_offset x24, 56
Zheng Xub551fdc2014-07-25 11:49:42 +0800122
Zheng Xu69a50302015-04-14 20:04:41 +0800123 stp x25, x26, [sp, #64]
124 .cfi_rel_offset x25, 64
125 .cfi_rel_offset x26, 72
Zheng Xub551fdc2014-07-25 11:49:42 +0800126
Zheng Xu69a50302015-04-14 20:04:41 +0800127 stp x27, x28, [sp, #80]
128 .cfi_rel_offset x27, 80
129 .cfi_rel_offset x28, 88
Zheng Xub551fdc2014-07-25 11:49:42 +0800130
Zheng Xu69a50302015-04-14 20:04:41 +0800131 // x29(callee-save) and LR
132 stp x29, xLR, [sp, #96]
133 .cfi_rel_offset x29, 96
134 .cfi_rel_offset x30, 104
Zheng Xub551fdc2014-07-25 11:49:42 +0800135
136 // Save xSELF to xETR.
137 mov xETR, xSELF
138
139 // Loads appropriate callee-save-method
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700140 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsOnly]
141 // Place sp in Thread::Current()->top_quick_frame.
142 mov xIP0, sp
143 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Zheng Xub551fdc2014-07-25 11:49:42 +0800144.endm
145
146// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700147.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800148 // Restore xSELF.
149 mov xSELF, xETR
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700150
Zheng Xub551fdc2014-07-25 11:49:42 +0800151 // Callee-saves
Zheng Xu69a50302015-04-14 20:04:41 +0800152 ldp x19, x20, [sp, #16]
153 .cfi_restore x19
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700154 .cfi_restore x20
Zheng Xu69a50302015-04-14 20:04:41 +0800155
156 ldp x21, x22, [sp, #32]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700157 .cfi_restore x21
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700158 .cfi_restore x22
Zheng Xu69a50302015-04-14 20:04:41 +0800159
160 ldp x23, x24, [sp, #48]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700161 .cfi_restore x23
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700162 .cfi_restore x24
Zheng Xu69a50302015-04-14 20:04:41 +0800163
164 ldp x25, x26, [sp, #64]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700165 .cfi_restore x25
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700166 .cfi_restore x26
Zheng Xu69a50302015-04-14 20:04:41 +0800167
168 ldp x27, x28, [sp, #80]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700169 .cfi_restore x27
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700170 .cfi_restore x28
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700171
Zheng Xu69a50302015-04-14 20:04:41 +0800172 // x29(callee-save) and LR
173 ldp x29, xLR, [sp, #96]
174 .cfi_restore x29
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700175 .cfi_restore x30
176
Zheng Xu69a50302015-04-14 20:04:41 +0800177 add sp, sp, #112
178 .cfi_adjust_cfa_offset -112
Stuart Monteithb95a5342014-03-12 13:32:32 +0000179.endm
180
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700181.macro POP_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800182 // Restore xSELF as it might be scratched.
183 mov xSELF, xETR
184 // ETR
Sebastien Hertz27a4a9d2015-05-05 20:03:50 +0200185 ldr xETR, [sp, #32]
Zheng Xub551fdc2014-07-25 11:49:42 +0800186 .cfi_restore x21
187
Zheng Xu69a50302015-04-14 20:04:41 +0800188 add sp, sp, #112
189 .cfi_adjust_cfa_offset -112
Andreas Gamped58342c2014-06-05 14:18:08 -0700190.endm
191
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700192.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
193 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Zheng Xu48241e72014-05-23 11:52:42 +0800194 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000195.endm
196
197
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700198.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800199 sub sp, sp, #224
200 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000201
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700202 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +0800203#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700204#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
205#endif
206
Zheng Xu69a50302015-04-14 20:04:41 +0800207 // FP args.
208 stp d0, d1, [sp, #8]
209 stp d2, d3, [sp, #24]
210 stp d4, d5, [sp, #40]
211 stp d6, d7, [sp, #56]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000212
Zheng Xu69a50302015-04-14 20:04:41 +0800213 // Core args.
214 str x1, [sp, 72]
215 .cfi_rel_offset x1, 72
Stuart Monteithb95a5342014-03-12 13:32:32 +0000216
Zheng Xu69a50302015-04-14 20:04:41 +0800217 stp x2, x3, [sp, #80]
218 .cfi_rel_offset x2, 80
219 .cfi_rel_offset x3, 88
Andreas Gampe03906cf2014-04-07 12:08:28 -0700220
Zheng Xu69a50302015-04-14 20:04:41 +0800221 stp x4, x5, [sp, #96]
222 .cfi_rel_offset x4, 96
223 .cfi_rel_offset x5, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700224
Zheng Xu69a50302015-04-14 20:04:41 +0800225 stp x6, x7, [sp, #112]
226 .cfi_rel_offset x6, 112
227 .cfi_rel_offset x7, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700228
Zheng Xub551fdc2014-07-25 11:49:42 +0800229 // Callee-saves.
Zheng Xu69a50302015-04-14 20:04:41 +0800230 stp x19, x20, [sp, #128]
231 .cfi_rel_offset x19, 128
232 .cfi_rel_offset x20, 136
233
Zheng Xub551fdc2014-07-25 11:49:42 +0800234 stp x21, x22, [sp, #144]
235 .cfi_rel_offset x21, 144
236 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700237
Zheng Xub551fdc2014-07-25 11:49:42 +0800238 stp x23, x24, [sp, #160]
239 .cfi_rel_offset x23, 160
240 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700241
Zheng Xub551fdc2014-07-25 11:49:42 +0800242 stp x25, x26, [sp, #176]
243 .cfi_rel_offset x25, 176
244 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700245
Zheng Xub551fdc2014-07-25 11:49:42 +0800246 stp x27, x28, [sp, #192]
247 .cfi_rel_offset x27, 192
248 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700249
Zheng Xub551fdc2014-07-25 11:49:42 +0800250 // x29(callee-save) and LR
251 stp x29, xLR, [sp, #208]
252 .cfi_rel_offset x29, 208
253 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700254
Zheng Xub551fdc2014-07-25 11:49:42 +0800255 // Save xSELF to xETR.
256 mov xETR, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000257.endm
258
259 /*
260 * Macro that sets up the callee save frame to conform with
261 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
262 *
263 * TODO This is probably too conservative - saving FP & LR.
264 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700265.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800266 adrp xIP0, :got:_ZN3art7Runtime9instance_E
267 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000268
269 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +0800270 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +0000271
Zheng Xub551fdc2014-07-25 11:49:42 +0800272 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -0700273 THIS_LOAD_REQUIRES_READ_BARRIER
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700274 ldr wIP0, [xIP0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000275
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700276 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Stuart Monteithb95a5342014-03-12 13:32:32 +0000277
Zheng Xub551fdc2014-07-25 11:49:42 +0800278 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700279 // Place sp in Thread::Current()->top_quick_frame.
280 mov xIP0, sp
281 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
282.endm
283
284.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
285 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
286 str x0, [sp, #0] // Store ArtMethod* to bottom of stack.
287 // Place sp in Thread::Current()->top_quick_frame.
288 mov xIP0, sp
289 str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000290.endm
291
Zheng Xub551fdc2014-07-25 11:49:42 +0800292// TODO: Probably no need to restore registers preserved by aapcs64.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700293.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800294 // Restore xSELF.
295 mov xSELF, xETR
Stuart Monteithb95a5342014-03-12 13:32:32 +0000296
Zheng Xu69a50302015-04-14 20:04:41 +0800297 // FP args.
298 ldp d0, d1, [sp, #8]
299 ldp d2, d3, [sp, #24]
300 ldp d4, d5, [sp, #40]
301 ldp d6, d7, [sp, #56]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000302
Zheng Xu69a50302015-04-14 20:04:41 +0800303 // Core args.
304 ldr x1, [sp, 72]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700305 .cfi_restore x1
Zheng Xu69a50302015-04-14 20:04:41 +0800306
307 ldp x2, x3, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700308 .cfi_restore x2
Andreas Gampe03906cf2014-04-07 12:08:28 -0700309 .cfi_restore x3
Zheng Xu69a50302015-04-14 20:04:41 +0800310
311 ldp x4, x5, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700312 .cfi_restore x4
Andreas Gampe03906cf2014-04-07 12:08:28 -0700313 .cfi_restore x5
Andreas Gampe03906cf2014-04-07 12:08:28 -0700314
Zheng Xu69a50302015-04-14 20:04:41 +0800315 ldp x6, x7, [sp, #112]
316 .cfi_restore x6
Andreas Gampe03906cf2014-04-07 12:08:28 -0700317 .cfi_restore x7
Andreas Gampe03906cf2014-04-07 12:08:28 -0700318
Zheng Xub551fdc2014-07-25 11:49:42 +0800319 // Callee-saves.
Zheng Xu69a50302015-04-14 20:04:41 +0800320 ldp x19, x20, [sp, #128]
321 .cfi_restore x19
322 .cfi_restore x20
323
Zheng Xub551fdc2014-07-25 11:49:42 +0800324 ldp x21, x22, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700325 .cfi_restore x21
326 .cfi_restore x22
327
Zheng Xub551fdc2014-07-25 11:49:42 +0800328 ldp x23, x24, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700329 .cfi_restore x23
330 .cfi_restore x24
331
Zheng Xub551fdc2014-07-25 11:49:42 +0800332 ldp x25, x26, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700333 .cfi_restore x25
334 .cfi_restore x26
335
Zheng Xub551fdc2014-07-25 11:49:42 +0800336 ldp x27, x28, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700337 .cfi_restore x27
338 .cfi_restore x28
339
Zheng Xub551fdc2014-07-25 11:49:42 +0800340 // x29(callee-save) and LR
341 ldp x29, xLR, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700342 .cfi_restore x29
343 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000344
Zheng Xub551fdc2014-07-25 11:49:42 +0800345 add sp, sp, #224
346 .cfi_adjust_cfa_offset -224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000347.endm
348
349.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700350 cbnz x0, 1f // result non-zero branch over
351 ret // return
3521:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000353.endm
354
355.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700356 cbz x0, 1f // result zero branch over
357 ret // return
3581:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000359.endm
360
361 /*
362 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
363 * exception is Thread::Current()->exception_
364 */
365.macro DELIVER_PENDING_EXCEPTION
366 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
367 mov x0, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000368
369 // Point of no return.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700370 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000371 brk 0 // Unreached
372.endm
373
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700374.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
375 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
376 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000377 ret
3781:
379 DELIVER_PENDING_EXCEPTION
380.endm
381
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700382.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800383 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700384.endm
385
386// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
387.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
388 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
389.endm
390
391.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
392 cbnz w0, 1f // result non-zero branch over
393 ret // return
3941:
395 DELIVER_PENDING_EXCEPTION
396.endm
397
Stuart Monteithb95a5342014-03-12 13:32:32 +0000398.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
399 .extern \cxx_name
400ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700401 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800402 mov x0, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700403 b \cxx_name // \cxx_name(Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000404END \c_name
405.endm
406
407.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
408 .extern \cxx_name
409ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100410 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800411 mov x1, xSELF // pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700412 b \cxx_name // \cxx_name(arg, Thread*).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000413 brk 0
414END \c_name
415.endm
416
417.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
418 .extern \cxx_name
419ENTRY \c_name
420 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800421 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700422 b \cxx_name // \cxx_name(arg1, arg2, Thread*)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000423 brk 0
424END \c_name
425.endm
426
427 /*
428 * Called by managed code, saves callee saves and then calls artThrowException
429 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
430 */
431ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
432
433 /*
434 * Called by managed code to create and deliver a NullPointerException.
435 */
436NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
437
438 /*
439 * Called by managed code to create and deliver an ArithmeticException.
440 */
441NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
442
443 /*
444 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
445 * index, arg2 holds limit.
446 */
447TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
448
449 /*
450 * Called by managed code to create and deliver a StackOverflowError.
451 */
452NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
453
454 /*
455 * Called by managed code to create and deliver a NoSuchMethodError.
456 */
457ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
458
459 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000460 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700461 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100462 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700463 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000464 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700465 * 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 +0000466 * of the target Method* in x0 and method->code_ in x1.
467 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700468 * If unsuccessful, the helper will return null/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000469 * thread and we branch to another stub to deliver it.
470 *
471 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
472 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700473 *
474 * Adapted from ARM32 code.
475 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800476 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000477 */
478.macro INVOKE_TRAMPOLINE c_name, cxx_name
479 .extern \cxx_name
480ENTRY \c_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700481 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC
Andreas Gampe51f76352014-05-21 08:28:48 -0700482 // Helper signature is always
483 // (method_idx, *this_object, *caller_method, *self, sp)
484
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100485 mov x2, xSELF // pass Thread::Current
486 mov x3, sp
487 bl \cxx_name // (method_idx, this, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800488 mov xIP0, x1 // save Method*->code_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700489 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampe51f76352014-05-21 08:28:48 -0700490 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800491 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07004921:
493 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +0000494END \c_name
495.endm
496
497INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
498INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
499
500INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
501INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
502INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
503INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
504
Andreas Gampe03906cf2014-04-07 12:08:28 -0700505
506.macro INVOKE_STUB_CREATE_FRAME
507
Zheng Xu69a50302015-04-14 20:04:41 +0800508SAVE_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 -0700509SAVE_SIZE_AND_METHOD=SAVE_SIZE+STACK_REFERENCE_SIZE
510
Andreas Gampe03906cf2014-04-07 12:08:28 -0700511
Zheng Xu48241e72014-05-23 11:52:42 +0800512 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700513 .cfi_register sp,x9
514
Zheng Xu48241e72014-05-23 11:52:42 +0800515 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
516 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
517 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
518 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700519
Zheng Xu48241e72014-05-23 11:52:42 +0800520 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
521 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700522 .cfi_adjust_cfa_offset SAVE_SIZE
523
Nicolas Geoffray48088462014-12-12 10:29:38 +0000524 str x28, [x10, #112]
525 .cfi_rel_offset x28, 112
526
527 stp x26, x27, [x10, #96]
528 .cfi_rel_offset x26, 96
529 .cfi_rel_offset x27, 104
530
531 stp x24, x25, [x10, #80]
532 .cfi_rel_offset x24, 80
533 .cfi_rel_offset x25, 88
534
535 stp x22, x23, [x10, #64]
536 .cfi_rel_offset x22, 64
537 .cfi_rel_offset x23, 72
538
539 stp x20, x21, [x10, #48]
540 .cfi_rel_offset x20, 48
541 .cfi_rel_offset x21, 56
542
Zheng Xu69a50302015-04-14 20:04:41 +0800543 stp x9, x19, [x10, #32] // Save old stack pointer and x19.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700544 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700545 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700546
Zheng Xu48241e72014-05-23 11:52:42 +0800547 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700548 .cfi_rel_offset x4, 16
549 .cfi_rel_offset x5, 24
550
Zheng Xu48241e72014-05-23 11:52:42 +0800551 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700552 .cfi_rel_offset x29, 0
553 .cfi_rel_offset x30, 8
554
Zheng Xu48241e72014-05-23 11:52:42 +0800555 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700556 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800557 mov xSELF, x3 // Move thread pointer into SELF register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700558
559 // Copy arguments into stack frame.
560 // Use simple copy routine for now.
561 // 4 bytes per slot.
562 // X1 - source address
563 // W2 - args length
564 // X9 - destination address.
565 // W10 - temporary
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700566 add x9, sp, #4 // Destination address is bottom of stack + null.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700567
568 // Use \@ to differentiate between macro invocations.
569.LcopyParams\@:
570 cmp w2, #0
571 beq .LendCopyParams\@
572 sub w2, w2, #4 // Need 65536 bytes of range.
573 ldr w10, [x1, x2]
574 str w10, [x9, x2]
575
576 b .LcopyParams\@
577
578.LendCopyParams\@:
579
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700580 // Store null into StackReference<Method>* at bottom of frame.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700581 str wzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700582
Andreas Gampecf4035a2014-05-28 22:43:01 -0700583#if (STACK_REFERENCE_SIZE != 4)
584#error "STACK_REFERENCE_SIZE(ARM64) size not as expected."
585#endif
Andreas Gampe03906cf2014-04-07 12:08:28 -0700586.endm
587
588.macro INVOKE_STUB_CALL_AND_RETURN
589
590 // load method-> METHOD_QUICK_CODE_OFFSET
Mathieu Chartier2d721012014-11-10 11:08:06 -0800591 ldr x9, [x0 , #MIRROR_ART_METHOD_QUICK_CODE_OFFSET_64]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700592 // Branch to method.
593 blr x9
594
595 // Restore return value address and shorty address.
596 ldp x4,x5, [xFP, #16]
597 .cfi_restore x4
598 .cfi_restore x5
599
Nicolas Geoffray48088462014-12-12 10:29:38 +0000600 ldr x28, [xFP, #112]
601 .cfi_restore x28
602
603 ldp x26, x27, [xFP, #96]
604 .cfi_restore x26
605 .cfi_restore x27
606
607 ldp x24, x25, [xFP, #80]
608 .cfi_restore x24
609 .cfi_restore x25
610
611 ldp x22, x23, [xFP, #64]
612 .cfi_restore x22
613 .cfi_restore x23
614
615 ldp x20, x21, [xFP, #48]
616 .cfi_restore x20
617 .cfi_restore x21
618
Andreas Gampe03906cf2014-04-07 12:08:28 -0700619 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
620 ldrb w10, [x5]
621
622 // Don't set anything for a void type.
623 cmp w10, #'V'
624 beq .Lexit_art_quick_invoke_stub\@
625
626 cmp w10, #'D'
627 bne .Lreturn_is_float\@
628 str d0, [x4]
629 b .Lexit_art_quick_invoke_stub\@
630
631.Lreturn_is_float\@:
632 cmp w10, #'F'
633 bne .Lreturn_is_int\@
634 str s0, [x4]
635 b .Lexit_art_quick_invoke_stub\@
636
637 // Just store x0. Doesn't matter if it is 64 or 32 bits.
638.Lreturn_is_int\@:
639 str x0, [x4]
640
641.Lexit_art_quick_invoke_stub\@:
Zheng Xu69a50302015-04-14 20:04:41 +0800642 ldp x2, x19, [xFP, #32] // Restore stack pointer and x19.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700643 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700644 mov sp, x2
645 .cfi_restore sp
646
Andreas Gamped58342c2014-06-05 14:18:08 -0700647 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700648 .cfi_restore x29
649 .cfi_restore x30
650
651 ret
652
653.endm
654
655
Stuart Monteithb95a5342014-03-12 13:32:32 +0000656/*
657 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
658 * uint32_t *args, x1
659 * uint32_t argsize, w2
660 * Thread *self, x3
661 * JValue *result, x4
662 * char *shorty); x5
663 * +----------------------+
664 * | |
665 * | C/C++ frame |
666 * | LR'' |
667 * | FP'' | <- SP'
668 * +----------------------+
669 * +----------------------+
Zheng Xu69a50302015-04-14 20:04:41 +0800670 * | x28 | <- TODO: Remove callee-saves.
671 * | : |
672 * | x19 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000673 * | SP' |
674 * | X5 |
675 * | X4 | Saved registers
676 * | LR' |
677 * | FP' | <- FP
678 * +----------------------+
679 * | uint32_t out[n-1] |
680 * | : : | Outs
681 * | uint32_t out[0] |
Andreas Gampecf4035a2014-05-28 22:43:01 -0700682 * | StackRef<ArtMethod> | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000683 * +----------------------+
684 *
685 * Outgoing registers:
686 * x0 - Method*
687 * x1-x7 - integer parameters.
688 * d0-d7 - Floating point parameters.
689 * xSELF = self
690 * SP = & of ArtMethod*
691 * x1 = "this" pointer.
692 *
693 */
694ENTRY art_quick_invoke_stub
695 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700696 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000697
698 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
699 // Parse the passed shorty to determine which register to load.
700 // Load addresses for routines that load WXSD registers.
701 adr x11, .LstoreW2
702 adr x12, .LstoreX2
703 adr x13, .LstoreS0
704 adr x14, .LstoreD0
705
706 // Initialize routine offsets to 0 for integers and floats.
707 // x8 for integers, x15 for floating point.
708 mov x8, #0
709 mov x15, #0
710
711 add x10, x5, #1 // Load shorty address, plus one to skip return value.
712 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
713
714 // Loop to fill registers.
715.LfillRegisters:
716 ldrb w17, [x10], #1 // Load next character in signature, and increment.
717 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
718
719 cmp w17, #'F' // is this a float?
720 bne .LisDouble
721
722 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700723 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000724
725 add x17, x13, x15 // Calculate subroutine to jump to.
726 br x17
727
728.LisDouble:
729 cmp w17, #'D' // is this a double?
730 bne .LisLong
731
732 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700733 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000734
735 add x17, x14, x15 // Calculate subroutine to jump to.
736 br x17
737
738.LisLong:
739 cmp w17, #'J' // is this a long?
740 bne .LisOther
741
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700742 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700743 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000744
745 add x17, x12, x8 // Calculate subroutine to jump to.
746 br x17
747
Stuart Monteithb95a5342014-03-12 13:32:32 +0000748.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700749 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700750 beq .Ladvance4
751
Stuart Monteithb95a5342014-03-12 13:32:32 +0000752 add x17, x11, x8 // Calculate subroutine to jump to.
753 br x17
754
Andreas Gampe03906cf2014-04-07 12:08:28 -0700755.Ladvance4:
756 add x9, x9, #4
757 b .LfillRegisters
758
759.Ladvance8:
760 add x9, x9, #8
761 b .LfillRegisters
762
Stuart Monteithb95a5342014-03-12 13:32:32 +0000763// Macro for loading a parameter into a register.
764// counter - the register with offset into these tables
765// size - the size of the register - 4 or 8 bytes.
766// register - the name of the register to be loaded.
767.macro LOADREG counter size register return
768 ldr \register , [x9], #\size
769 add \counter, \counter, 12
770 b \return
771.endm
772
773// Store ints.
774.LstoreW2:
775 LOADREG x8 4 w2 .LfillRegisters
776 LOADREG x8 4 w3 .LfillRegisters
777 LOADREG x8 4 w4 .LfillRegisters
778 LOADREG x8 4 w5 .LfillRegisters
779 LOADREG x8 4 w6 .LfillRegisters
780 LOADREG x8 4 w7 .LfillRegisters
781
782// Store longs.
783.LstoreX2:
784 LOADREG x8 8 x2 .LfillRegisters
785 LOADREG x8 8 x3 .LfillRegisters
786 LOADREG x8 8 x4 .LfillRegisters
787 LOADREG x8 8 x5 .LfillRegisters
788 LOADREG x8 8 x6 .LfillRegisters
789 LOADREG x8 8 x7 .LfillRegisters
790
791// Store singles.
792.LstoreS0:
793 LOADREG x15 4 s0 .LfillRegisters
794 LOADREG x15 4 s1 .LfillRegisters
795 LOADREG x15 4 s2 .LfillRegisters
796 LOADREG x15 4 s3 .LfillRegisters
797 LOADREG x15 4 s4 .LfillRegisters
798 LOADREG x15 4 s5 .LfillRegisters
799 LOADREG x15 4 s6 .LfillRegisters
800 LOADREG x15 4 s7 .LfillRegisters
801
802// Store doubles.
803.LstoreD0:
804 LOADREG x15 8 d0 .LfillRegisters
805 LOADREG x15 8 d1 .LfillRegisters
806 LOADREG x15 8 d2 .LfillRegisters
807 LOADREG x15 8 d3 .LfillRegisters
808 LOADREG x15 8 d4 .LfillRegisters
809 LOADREG x15 8 d5 .LfillRegisters
810 LOADREG x15 8 d6 .LfillRegisters
811 LOADREG x15 8 d7 .LfillRegisters
812
813
814.LcallFunction:
815
Andreas Gampe03906cf2014-04-07 12:08:28 -0700816 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000817
Stuart Monteithb95a5342014-03-12 13:32:32 +0000818END art_quick_invoke_stub
819
820/* extern"C"
821 * void art_quick_invoke_static_stub(ArtMethod *method, x0
822 * uint32_t *args, x1
823 * uint32_t argsize, w2
824 * Thread *self, x3
825 * JValue *result, x4
826 * char *shorty); x5
827 */
828ENTRY art_quick_invoke_static_stub
829 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700830 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000831
832 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
833 // Parse the passed shorty to determine which register to load.
834 // Load addresses for routines that load WXSD registers.
835 adr x11, .LstoreW1_2
836 adr x12, .LstoreX1_2
837 adr x13, .LstoreS0_2
838 adr x14, .LstoreD0_2
839
840 // Initialize routine offsets to 0 for integers and floats.
841 // x8 for integers, x15 for floating point.
842 mov x8, #0
843 mov x15, #0
844
845 add x10, x5, #1 // Load shorty address, plus one to skip return value.
846
847 // Loop to fill registers.
848.LfillRegisters2:
849 ldrb w17, [x10], #1 // Load next character in signature, and increment.
850 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
851
852 cmp w17, #'F' // is this a float?
853 bne .LisDouble2
854
855 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700856 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000857
858 add x17, x13, x15 // Calculate subroutine to jump to.
859 br x17
860
861.LisDouble2:
862 cmp w17, #'D' // is this a double?
863 bne .LisLong2
864
865 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700866 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000867
868 add x17, x14, x15 // Calculate subroutine to jump to.
869 br x17
870
871.LisLong2:
872 cmp w17, #'J' // is this a long?
873 bne .LisOther2
874
875 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700876 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000877
878 add x17, x12, x8 // Calculate subroutine to jump to.
879 br x17
880
Stuart Monteithb95a5342014-03-12 13:32:32 +0000881.LisOther2: // Everything else takes one vReg.
882 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700883 beq .Ladvance4_2
884
Stuart Monteithb95a5342014-03-12 13:32:32 +0000885 add x17, x11, x8 // Calculate subroutine to jump to.
886 br x17
887
Andreas Gampe03906cf2014-04-07 12:08:28 -0700888.Ladvance4_2:
889 add x9, x9, #4
890 b .LfillRegisters2
891
892.Ladvance8_2:
893 add x9, x9, #8
894 b .LfillRegisters2
895
Stuart Monteithb95a5342014-03-12 13:32:32 +0000896// Store ints.
897.LstoreW1_2:
898 LOADREG x8 4 w1 .LfillRegisters2
899 LOADREG x8 4 w2 .LfillRegisters2
900 LOADREG x8 4 w3 .LfillRegisters2
901 LOADREG x8 4 w4 .LfillRegisters2
902 LOADREG x8 4 w5 .LfillRegisters2
903 LOADREG x8 4 w6 .LfillRegisters2
904 LOADREG x8 4 w7 .LfillRegisters2
905
906// Store longs.
907.LstoreX1_2:
908 LOADREG x8 8 x1 .LfillRegisters2
909 LOADREG x8 8 x2 .LfillRegisters2
910 LOADREG x8 8 x3 .LfillRegisters2
911 LOADREG x8 8 x4 .LfillRegisters2
912 LOADREG x8 8 x5 .LfillRegisters2
913 LOADREG x8 8 x6 .LfillRegisters2
914 LOADREG x8 8 x7 .LfillRegisters2
915
916// Store singles.
917.LstoreS0_2:
918 LOADREG x15 4 s0 .LfillRegisters2
919 LOADREG x15 4 s1 .LfillRegisters2
920 LOADREG x15 4 s2 .LfillRegisters2
921 LOADREG x15 4 s3 .LfillRegisters2
922 LOADREG x15 4 s4 .LfillRegisters2
923 LOADREG x15 4 s5 .LfillRegisters2
924 LOADREG x15 4 s6 .LfillRegisters2
925 LOADREG x15 4 s7 .LfillRegisters2
926
927// Store doubles.
928.LstoreD0_2:
929 LOADREG x15 8 d0 .LfillRegisters2
930 LOADREG x15 8 d1 .LfillRegisters2
931 LOADREG x15 8 d2 .LfillRegisters2
932 LOADREG x15 8 d3 .LfillRegisters2
933 LOADREG x15 8 d4 .LfillRegisters2
934 LOADREG x15 8 d5 .LfillRegisters2
935 LOADREG x15 8 d6 .LfillRegisters2
936 LOADREG x15 8 d7 .LfillRegisters2
937
938
939.LcallFunction2:
940
Andreas Gampe03906cf2014-04-07 12:08:28 -0700941 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000942
Stuart Monteithb95a5342014-03-12 13:32:32 +0000943END art_quick_invoke_static_stub
944
Andreas Gampe03906cf2014-04-07 12:08:28 -0700945
Stuart Monteithb95a5342014-03-12 13:32:32 +0000946
947 /*
948 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
949 */
950
951ENTRY art_quick_do_long_jump
952 // Load FPRs
953 ldp d0, d1, [x1], #16
954 ldp d2, d3, [x1], #16
955 ldp d4, d5, [x1], #16
956 ldp d6, d7, [x1], #16
957 ldp d8, d9, [x1], #16
958 ldp d10, d11, [x1], #16
959 ldp d12, d13, [x1], #16
960 ldp d14, d15, [x1], #16
961 ldp d16, d17, [x1], #16
962 ldp d18, d19, [x1], #16
963 ldp d20, d21, [x1], #16
964 ldp d22, d23, [x1], #16
965 ldp d24, d25, [x1], #16
966 ldp d26, d27, [x1], #16
967 ldp d28, d29, [x1], #16
968 ldp d30, d31, [x1]
969
970 // Load GPRs
971 // TODO: lots of those are smashed, could optimize.
972 add x0, x0, #30*8
973 ldp x30, x1, [x0], #-16
974 ldp x28, x29, [x0], #-16
975 ldp x26, x27, [x0], #-16
976 ldp x24, x25, [x0], #-16
977 ldp x22, x23, [x0], #-16
978 ldp x20, x21, [x0], #-16
979 ldp x18, x19, [x0], #-16
980 ldp x16, x17, [x0], #-16
981 ldp x14, x15, [x0], #-16
982 ldp x12, x13, [x0], #-16
983 ldp x10, x11, [x0], #-16
984 ldp x8, x9, [x0], #-16
985 ldp x6, x7, [x0], #-16
986 ldp x4, x5, [x0], #-16
987 ldp x2, x3, [x0], #-16
988 mov sp, x1
989
990 // TODO: Is it really OK to use LR for the target PC?
991 mov x0, #0
992 mov x1, #0
993 br xLR
994END art_quick_do_long_jump
995
Andreas Gampef4e910b2014-04-29 16:55:52 -0700996 /*
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700997 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
998 * possibly null object to lock.
999 *
1000 * Derived from arm32 code.
1001 */
1002 .extern artLockObjectFromCode
1003ENTRY art_quick_lock_object
1004 cbz w0, .Lslow_lock
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001005 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001006.Lretry_lock:
1007 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
1008 ldxr w1, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001009 mov x3, x1
1010 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1011 cbnz w3, .Lnot_unlocked // already thin locked
1012 // unlocked case - x1: original lock word that's zero except for the read barrier bits.
1013 orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001014 stxr w3, w2, [x4]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001015 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -07001016 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001017 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001018.Lnot_unlocked: // x1: original lock word
1019 lsr w3, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001020 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1021 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1022 uxth w2, w2 // zero top 16 bits
1023 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1024 // else contention, go to slow path
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001025 mov x3, x1 // copy the lock word to check count overflow.
1026 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits.
1027 add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow
1028 lsr w3, w2, LOCK_WORD_READ_BARRIER_STATE_SHIFT // if either of the upper two bits (28-29) are set, we overflowed.
1029 cbnz w3, .Lslow_lock // if we overflow the count go slow path
1030 add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real
1031 stxr w3, w2, [x4]
1032 cbnz w3, .Llock_stxr_fail // store failed, retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001033 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001034.Llock_stxr_fail:
1035 b .Lretry_lock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001036.Lslow_lock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001037 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001038 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001039 bl artLockObjectFromCode // (Object* obj, Thread*)
1040 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001041 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1042END art_quick_lock_object
1043
1044 /*
1045 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1046 * x0 holds the possibly null object to lock.
1047 *
1048 * Derived from arm32 code.
1049 */
1050 .extern artUnlockObjectFromCode
1051ENTRY art_quick_unlock_object
1052 cbz x0, .Lslow_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001053 add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore
1054.Lretry_unlock:
1055#ifndef USE_READ_BARRIER
1056 ldr w1, [x4]
1057#else
1058 ldxr w1, [x4] // Need to use atomic instructions for read barrier
1059#endif
1060 lsr w2, w1, LOCK_WORD_STATE_SHIFT
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001061 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1062 ldr w2, [xSELF, #THREAD_ID_OFFSET]
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001063 mov x3, x1 // copy lock word to check thread id equality
1064 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1065 eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId()
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001066 uxth w3, w3 // zero top 16 bits
1067 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001068 mov x3, x1 // copy lock word to detect transition to unlocked
1069 and w3, w3, #LOCK_WORD_READ_BARRIER_STATE_MASK_TOGGLED // zero the read barrier bits
1070 cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001071 bpl .Lrecursive_thin_unlock
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001072 // transition to unlocked
1073 mov x3, x1
1074 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 -07001075 dmb ish // full (LoadStore|StoreStore) memory barrier
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001076#ifndef USE_READ_BARRIER
1077 str w3, [x4]
1078#else
1079 stxr w2, w3, [x4] // Need to use atomic instructions for read barrier
1080 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1081#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001082 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001083.Lrecursive_thin_unlock: // w1: original lock word
1084 sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count
1085#ifndef USE_READ_BARRIER
1086 str w1, [x4]
1087#else
1088 stxr w2, w1, [x4] // Need to use atomic instructions for read barrier
1089 cbnz w2, .Lunlock_stxr_fail // store failed, retry
1090#endif
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001091 ret
Hiroshi Yamauchie15ea082015-02-09 17:11:42 -08001092.Lunlock_stxr_fail:
1093 b .Lretry_unlock // retry
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001094.Lslow_unlock:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001095 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001096 mov x1, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001097 bl artUnlockObjectFromCode // (Object* obj, Thread*)
1098 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001099 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1100END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001101
1102 /*
1103 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1104 * artThrowClassCastException.
1105 */
1106 .extern artThrowClassCastException
1107ENTRY art_quick_check_cast
1108 // Store arguments and link register
1109 sub sp, sp, #32 // Stack needs to be 16b aligned on calls
1110 .cfi_adjust_cfa_offset 32
1111 stp x0, x1, [sp]
1112 .cfi_rel_offset x0, 0
1113 .cfi_rel_offset x1, 8
1114 stp xSELF, xLR, [sp, #16]
1115 .cfi_rel_offset x18, 16
1116 .cfi_rel_offset x30, 24
1117
1118 // Call runtime code
1119 bl artIsAssignableFromCode
1120
1121 // Check for exception
1122 cbz x0, .Lthrow_class_cast_exception
1123
1124 // Restore and return
1125 ldp x0, x1, [sp]
1126 .cfi_restore x0
1127 .cfi_restore x1
1128 ldp xSELF, xLR, [sp, #16]
1129 .cfi_restore x18
1130 .cfi_restore x30
1131 add sp, sp, #32
1132 .cfi_adjust_cfa_offset -32
1133 ret
1134
1135.Lthrow_class_cast_exception:
1136 // Restore
1137 ldp x0, x1, [sp]
1138 .cfi_restore x0
1139 .cfi_restore x1
1140 ldp xSELF, xLR, [sp, #16]
1141 .cfi_restore x18
1142 .cfi_restore x30
1143 add sp, sp, #32
1144 .cfi_adjust_cfa_offset -32
1145
1146 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1147 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001148 b artThrowClassCastException // (Class*, Class*, Thread*)
Andreas Gampe525cde22014-04-22 15:44:50 -07001149 brk 0 // We should not return here...
1150END art_quick_check_cast
1151
Andreas Gampef4e910b2014-04-29 16:55:52 -07001152 /*
1153 * Entry from managed code for array put operations of objects where the value being stored
1154 * needs to be checked for compatibility.
1155 * x0 = array, x1 = index, x2 = value
1156 *
1157 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1158 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1159 * using index-zero-extension in load/stores.
1160 *
1161 * Temporaries: x3, x4
1162 * TODO: x4 OK? ip seems wrong here.
1163 */
1164ENTRY art_quick_aput_obj_with_null_and_bound_check
1165 tst x0, x0
1166 bne art_quick_aput_obj_with_bound_check
1167 b art_quick_throw_null_pointer_exception
1168END art_quick_aput_obj_with_null_and_bound_check
1169
1170ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001171 ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET]
Andreas Gampef4e910b2014-04-29 16:55:52 -07001172 cmp w3, w1
1173 bhi art_quick_aput_obj
1174 mov x0, x1
1175 mov x1, x3
1176 b art_quick_throw_array_bounds
1177END art_quick_aput_obj_with_bound_check
1178
1179ENTRY art_quick_aput_obj
1180 cbz x2, .Ldo_aput_null
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001181 ldr w3, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001182 // This also zero-extends to x3
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001183 ldr w4, [x2, #MIRROR_OBJECT_CLASS_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001184 // This also zero-extends to x4
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001185 ldr w3, [x3, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b
Andreas Gampef4e910b2014-04-29 16:55:52 -07001186 // This also zero-extends to x3
1187 cmp w3, w4 // value's type == array's component type - trivial assignability
1188 bne .Lcheck_assignability
1189.Ldo_aput:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001190 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001191 // "Compress" = do nothing
1192 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1193 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1194 lsr x0, x0, #7
1195 strb w3, [x3, x0]
1196 ret
1197.Ldo_aput_null:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001198 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001199 // "Compress" = do nothing
1200 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1201 ret
1202.Lcheck_assignability:
1203 // Store arguments and link register
1204 sub sp, sp, #48 // Stack needs to be 16b aligned on calls
1205 .cfi_adjust_cfa_offset 48
1206 stp x0, x1, [sp]
1207 .cfi_rel_offset x0, 0
1208 .cfi_rel_offset x1, 8
1209 stp x2, xSELF, [sp, #16]
1210 .cfi_rel_offset x2, 16
1211 .cfi_rel_offset x18, 24
1212 str xLR, [sp, #32]
1213 .cfi_rel_offset x30, 32
1214
1215 // Call runtime code
1216 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1217 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1218 bl artIsAssignableFromCode
1219
1220 // Check for exception
1221 cbz x0, .Lthrow_array_store_exception
1222
1223 // Restore
1224 ldp x0, x1, [sp]
1225 .cfi_restore x0
1226 .cfi_restore x1
1227 ldp x2, xSELF, [sp, #16]
1228 .cfi_restore x2
1229 .cfi_restore x18
1230 ldr xLR, [sp, #32]
1231 .cfi_restore x30
1232 add sp, sp, #48
1233 .cfi_adjust_cfa_offset -48
1234
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001235 add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET
Andreas Gampef4e910b2014-04-29 16:55:52 -07001236 // "Compress" = do nothing
1237 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1238 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1239 lsr x0, x0, #7
1240 strb w3, [x3, x0]
1241 ret
1242.Lthrow_array_store_exception:
1243 ldp x0, x1, [sp]
1244 .cfi_restore x0
1245 .cfi_restore x1
1246 ldp x2, xSELF, [sp, #16]
1247 .cfi_restore x2
1248 .cfi_restore x18
1249 ldr xLR, [sp, #32]
1250 .cfi_restore x30
1251 add sp, sp, #48
1252 .cfi_adjust_cfa_offset -48
1253
1254 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1255 mov x1, x2 // Pass value.
1256 mov x2, xSELF // Pass Thread::Current.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001257 b artThrowArrayStoreException // (Object*, Object*, Thread*).
Andreas Gampef4e910b2014-04-29 16:55:52 -07001258 brk 0 // Unreached.
1259END art_quick_aput_obj
1260
Stuart Monteithb95a5342014-03-12 13:32:32 +00001261// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001262.macro ONE_ARG_DOWNCALL name, entrypoint, return
1263 .extern \entrypoint
1264ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001265 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001266 mov x1, xSELF // pass Thread::Current
1267 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1268 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1269 \return
1270END \name
1271.endm
1272
1273// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001274.macro TWO_ARG_DOWNCALL name, entrypoint, return
1275 .extern \entrypoint
1276ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001277 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001278 mov x2, xSELF // pass Thread::Current
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001279 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*)
1280 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001281 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001282END \name
1283.endm
1284
Jeff Hao848f70a2014-01-15 13:49:50 -08001285// Macro to facilitate adding new allocation entrypoints.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001286.macro THREE_ARG_DOWNCALL name, entrypoint, return
1287 .extern \entrypoint
1288ENTRY \name
Jeff Hao848f70a2014-01-15 13:49:50 -08001289 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001290 mov x3, xSELF // pass Thread::Current
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001291 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001292 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001293 \return
Stuart Monteithb95a5342014-03-12 13:32:32 +00001294END \name
1295.endm
1296
Jeff Hao848f70a2014-01-15 13:49:50 -08001297// Macro to facilitate adding new allocation entrypoints.
1298.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1299 .extern \entrypoint
1300ENTRY \name
1301 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1302 mov x4, xSELF // pass Thread::Current
1303 bl \entrypoint //
1304 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1305 \return
1306 DELIVER_PENDING_EXCEPTION
1307END \name
1308.endm
1309
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001310// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001311.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1312 .extern \entrypoint
1313ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001314 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001315 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001316 mov x2, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001317 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001318 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001319 \return
1320END \name
1321.endm
1322
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001323.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1324 .extern \entrypoint
1325ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001326 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001327 ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001328 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001329 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001330 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001331 \return
1332END \name
1333.endm
1334
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001335.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1336 .extern \entrypoint
1337ENTRY \name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001338 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001339 ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001340 mov x4, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001341 bl \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001342 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001343 \return
1344END \name
1345.endm
1346
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001347.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1348 cbz w0, 1f // result zero branch over
1349 ret // return
13501:
1351 DELIVER_PENDING_EXCEPTION
1352.endm
1353
Matteo Franchindfd891a2014-04-30 12:17:17 +01001354 /*
Vladimir Marko3b370732014-10-09 18:34:28 +01001355 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1356 * failure.
1357 */
1358TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1359
1360 /*
Matteo Franchindfd891a2014-04-30 12:17:17 +01001361 * Entry from managed code when uninitialized static storage, this stub will run the class
1362 * initializer and deliver the exception on error. On success the static storage base is
1363 * returned.
1364 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001365ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Matteo Franchindfd891a2014-04-30 12:17:17 +01001366
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001367ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1368ONE_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 +01001369
Fred Shih37f05ef2014-07-16 18:38:08 -07001370ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1371ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1372ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1373ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001374ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1375ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1376ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1377
Fred Shih37f05ef2014-07-16 18:38:08 -07001378TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1379TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1380TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1381TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001382TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1383TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1384TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1385
Fred Shih37f05ef2014-07-16 18:38:08 -07001386TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1387TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001388TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1389TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1390
Fred Shih37f05ef2014-07-16 18:38:08 -07001391THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1392THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001393THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Stephen Kyle0ff20d52014-10-22 15:23:46 +01001394THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001395THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1396
1397// This is separated out as the argument order is different.
1398 .extern artSet64StaticFromCode
1399ENTRY art_quick_set64_static
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001400 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001401 mov x3, x1 // Store value
Andreas Gampecf4035a2014-05-28 22:43:01 -07001402 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001403 mov x2, x3 // Put value param
1404 mov x3, xSELF // pass Thread::Current
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001405 bl artSet64StaticFromCode
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001406 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001407 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1408END art_quick_set64_static
1409
Matteo Franchindfd891a2014-04-30 12:17:17 +01001410 /*
1411 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001412 * exception on error. On success the String is returned. w0 holds the string index. The fast
1413 * path check for hit in strings cache has already been performed.
Matteo Franchindfd891a2014-04-30 12:17:17 +01001414 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001415ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001416
Stuart Monteithb95a5342014-03-12 13:32:32 +00001417// Generate the allocation entrypoints for each allocator.
1418GENERATE_ALL_ALLOC_ENTRYPOINTS
1419
Zheng Xu48241e72014-05-23 11:52:42 +08001420 /*
Zheng Xu69a50302015-04-14 20:04:41 +08001421 * Called by managed code when the thread has been asked to suspend.
Zheng Xu48241e72014-05-23 11:52:42 +08001422 */
1423 .extern artTestSuspendFromCode
1424ENTRY art_quick_test_suspend
1425 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
Zheng Xu48241e72014-05-23 11:52:42 +08001426 cbnz w0, .Lneed_suspend // check flags == 0
1427 ret // return if flags == 0
1428.Lneed_suspend:
1429 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001430 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1431 bl artTestSuspendFromCode // (Thread*)
1432 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +08001433END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001434
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001435ENTRY art_quick_implicit_suspend
1436 mov x0, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001437 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1438 bl artTestSuspendFromCode // (Thread*)
1439 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001440END art_quick_implicit_suspend
1441
Andreas Gampee62a07e2014-03-26 14:53:21 -07001442 /*
1443 * Called by managed code that is attempting to call a method on a proxy class. On entry
1444 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1445 * method agrees with a ref and args callee save frame.
1446 */
1447 .extern artQuickProxyInvokeHandler
1448ENTRY art_quick_proxy_invoke_handler
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001449 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Andreas Gampee62a07e2014-03-26 14:53:21 -07001450 mov x2, xSELF // pass Thread::Current
1451 mov x3, sp // pass SP
1452 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +08001453 // Use xETR as xSELF might be scratched by native function above.
1454 ldr x2, [xETR, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001455 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001456 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
Andreas Gamped1e91672014-06-02 22:50:05 -07001457 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001458 ret // return on success
1459.Lexception_in_proxy:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001460 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampee62a07e2014-03-26 14:53:21 -07001461 DELIVER_PENDING_EXCEPTION
1462END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001463
Andreas Gampe51f76352014-05-21 08:28:48 -07001464 /*
Zheng Xub551fdc2014-07-25 11:49:42 +08001465 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's
Andreas Gampe51f76352014-05-21 08:28:48 -07001466 * dex method index.
1467 */
1468ENTRY art_quick_imt_conflict_trampoline
Andreas Gampecf4035a2014-05-28 22:43:01 -07001469 ldr w0, [sp, #0] // load caller Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001470 ldr w0, [x0, #MIRROR_ART_METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods
1471 add x0, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET // get starting address of data
Zheng Xub551fdc2014-07-25 11:49:42 +08001472 ldr w0, [x0, xIP1, lsl 2] // load the target method
Andreas Gampe51f76352014-05-21 08:28:48 -07001473 b art_quick_invoke_interface_trampoline
1474END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001475
1476ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001477 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001478 mov x2, xSELF
1479 mov x3, sp
1480 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001481 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001482 mov xIP0, x0 // Remember returned code pointer in xIP0.
Andreas Gampecf4035a2014-05-28 22:43:01 -07001483 ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001484 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001485 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000014861:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001487 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001488 DELIVER_PENDING_EXCEPTION
1489END art_quick_resolution_trampoline
1490
1491/*
1492 * Generic JNI frame layout:
1493 *
1494 * #-------------------#
1495 * | |
1496 * | caller method... |
1497 * #-------------------# <--- SP on entry
1498 * | Return X30/LR |
1499 * | X29/FP | callee save
1500 * | X28 | callee save
1501 * | X27 | callee save
1502 * | X26 | callee save
1503 * | X25 | callee save
1504 * | X24 | callee save
1505 * | X23 | callee save
1506 * | X22 | callee save
1507 * | X21 | callee save
1508 * | X20 | callee save
Zheng Xu69a50302015-04-14 20:04:41 +08001509 * | X19 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001510 * | X7 | arg7
1511 * | X6 | arg6
1512 * | X5 | arg5
1513 * | X4 | arg4
1514 * | X3 | arg3
1515 * | X2 | arg2
1516 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001517 * | D7 | float arg 8
1518 * | D6 | float arg 7
1519 * | D5 | float arg 6
1520 * | D4 | float arg 5
1521 * | D3 | float arg 4
1522 * | D2 | float arg 3
1523 * | D1 | float arg 2
1524 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001525 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001526 * #-------------------#
1527 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001528 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001529 * #-------------------#
1530 * | JNI Call Stack |
1531 * #-------------------# <--- SP on native call
1532 * | |
1533 * | Stack for Regs | The trampoline assembly will pop these values
1534 * | | into registers for native call
1535 * #-------------------#
1536 * | Native code ptr |
1537 * #-------------------#
1538 * | Free scratch |
1539 * #-------------------#
1540 * | Ptr to (1) | <--- SP
1541 * #-------------------#
1542 */
1543 /*
1544 * Called to do a generic JNI down-call
1545 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001546ENTRY art_quick_generic_jni_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001547 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001548
1549 // Save SP , so we can have static CFI info.
1550 mov x28, sp
1551 .cfi_def_cfa_register x28
1552
1553 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001554 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001555 mov xFP, sp
1556
Zheng Xub551fdc2014-07-25 11:49:42 +08001557 mov xIP0, #5120
1558 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001559
1560 // prepare for artQuickGenericJniTrampoline call
1561 // (Thread*, SP)
1562 // x0 x1 <= C calling convention
1563 // xSELF xFP <= where they are
1564
1565 mov x0, xSELF // Thread*
1566 mov x1, xFP
1567 bl artQuickGenericJniTrampoline // (Thread*, sp)
1568
Andreas Gampec200a4a2014-06-16 18:39:09 -07001569 // The C call will have registered the complete save-frame on success.
1570 // The result of the call is:
1571 // x0: pointer to native code, 0 on error.
1572 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001573
Andreas Gampec200a4a2014-06-16 18:39:09 -07001574 // Check for error = 0.
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001575 cbz x0, .Lexception_in_native
Stuart Monteithb95a5342014-03-12 13:32:32 +00001576
Andreas Gampec200a4a2014-06-16 18:39:09 -07001577 // Release part of the alloca.
1578 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001579
Andreas Gampec200a4a2014-06-16 18:39:09 -07001580 // Save the code pointer
1581 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001582
1583 // Load parameters from frame into registers.
1584 // TODO Check with artQuickGenericJniTrampoline.
1585 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001586 ldp x0, x1, [sp]
1587 ldp x2, x3, [sp, #16]
1588 ldp x4, x5, [sp, #32]
1589 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001590
Andreas Gampec200a4a2014-06-16 18:39:09 -07001591 ldp d0, d1, [sp, #64]
1592 ldp d2, d3, [sp, #80]
1593 ldp d4, d5, [sp, #96]
1594 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001595
Andreas Gampec200a4a2014-06-16 18:39:09 -07001596 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001597
Zheng Xub551fdc2014-07-25 11:49:42 +08001598 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001599
1600 // result sign extension is handled in C code
1601 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001602 // (Thread*, result, result_f)
1603 // x0 x1 x2 <= C calling convention
1604 mov x1, x0 // Result (from saved)
Zheng Xub551fdc2014-07-25 11:49:42 +08001605 mov x0, xETR // Thread register, original xSELF might be scratched by native code.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001606 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001607
1608 bl artQuickGenericJniEndTrampoline
1609
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001610 // Pending exceptions possible.
1611 // Use xETR as xSELF might be scratched by native code
1612 ldr x2, [xETR, THREAD_EXCEPTION_OFFSET]
1613 cbnz x2, .Lexception_in_native
1614
Stuart Monteithb95a5342014-03-12 13:32:32 +00001615 // Tear down the alloca.
1616 mov sp, x28
1617 .cfi_def_cfa_register sp
1618
Stuart Monteithb95a5342014-03-12 13:32:32 +00001619 // Tear down the callee-save frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001620 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +00001621
1622 // store into fpr, for when it's a fpr return...
1623 fmov d0, x0
1624 ret
1625
Stuart Monteithb95a5342014-03-12 13:32:32 +00001626.Lexception_in_native:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001627 // Restore xSELF. It might have been scratched by native code.
1628 mov xSELF, xETR
1629 // Move to x1 then sp to please assembler.
1630 ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET]
1631 mov sp, x1
1632 .cfi_def_cfa_register sp
1633 # This will create a new save-all frame, required by the runtime.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001634 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001635END art_quick_generic_jni_trampoline
1636
1637/*
1638 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1639 * of a quick call:
1640 * x0 = method being called/to bridge to.
1641 * x1..x7, d0..d7 = arguments to that method.
1642 */
Ian Rogers6f3dbba2014-10-14 17:41:57 -07001643ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001644 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001645
1646 // x0 will contain mirror::ArtMethod* method.
1647 mov x1, xSELF // How to get Thread::Current() ???
1648 mov x2, sp
1649
1650 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1651 // mirror::ArtMethod** sp)
1652 bl artQuickToInterpreterBridge
1653
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001654 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001655
1656 fmov d0, x0
1657
1658 RETURN_OR_DELIVER_PENDING_EXCEPTION
1659END art_quick_to_interpreter_bridge
1660
Andreas Gamped58342c2014-06-05 14:18:08 -07001661
1662//
1663// Instrumentation-related stubs
1664//
1665 .extern artInstrumentationMethodEntryFromCode
1666ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001667 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001668
Zheng Xub551fdc2014-07-25 11:49:42 +08001669 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07001670
1671 mov x2, xSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001672 mov x3, xLR
1673 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR)
Andreas Gamped58342c2014-06-05 14:18:08 -07001674
Zheng Xub551fdc2014-07-25 11:49:42 +08001675 mov xIP0, x0 // x0 = result of call.
1676 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07001677
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001678 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
Andreas Gamped58342c2014-06-05 14:18:08 -07001679 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08001680 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07001681END art_quick_instrumentation_entry
1682
1683 .extern artInstrumentationMethodExitFromCode
1684ENTRY art_quick_instrumentation_exit
1685 mov xLR, #0 // Clobber LR for later checks.
1686
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001687 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001688
1689 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
1690 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
1691 // easier to have an extra small stack area.
1692
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001693 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07001694 .cfi_adjust_cfa_offset 16
1695 str d0, [sp, #8] // Save floating-point result.
1696
Andreas Gamped58342c2014-06-05 14:18:08 -07001697 add x1, sp, #16 // Pass SP.
1698 mov x2, x0 // Pass integer result.
1699 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001700 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07001701 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
1702
Zheng Xub551fdc2014-07-25 11:49:42 +08001703 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07001704 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
1705
1706 ldr d0, [sp, #8] // Restore floating-point result.
1707 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
1708 .cfi_adjust_cfa_offset 16
1709
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001710 POP_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gamped58342c2014-06-05 14:18:08 -07001711
Zheng Xub551fdc2014-07-25 11:49:42 +08001712 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07001713END art_quick_instrumentation_exit
1714
1715 /*
1716 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1717 * will long jump to the upcall with a special exception of -1.
1718 */
1719 .extern artDeoptimize
1720ENTRY art_quick_deoptimize
1721 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1722 mov x0, xSELF // Pass thread.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001723 bl artDeoptimize // artDeoptimize(Thread*)
Serban Constantinescu86797a72014-06-19 16:17:56 +01001724 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07001725END art_quick_deoptimize
1726
1727
Serban Constantinescu169489b2014-06-11 16:43:35 +01001728 /*
1729 * String's indexOf.
1730 *
1731 * TODO: Not very optimized.
1732 * On entry:
1733 * x0: string object (known non-null)
1734 * w1: char to match (known <= 0xFFFF)
1735 * w2: Starting offset in string data
1736 */
1737ENTRY art_quick_indexof
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001738 ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001739 add x0, x0, #MIRROR_STRING_VALUE_OFFSET
Serban Constantinescu169489b2014-06-11 16:43:35 +01001740
1741 /* Clamp start to [0..count] */
1742 cmp w2, #0
1743 csel w2, wzr, w2, lt
1744 cmp w2, w3
1745 csel w2, w3, w2, gt
1746
Serban Constantinescu169489b2014-06-11 16:43:35 +01001747 /* Save a copy to compute result */
1748 mov x5, x0
1749
1750 /* Build pointer to start of data to compare and pre-bias */
1751 add x0, x0, x2, lsl #1
1752 sub x0, x0, #2
1753
1754 /* Compute iteration count */
1755 sub w2, w3, w2
1756
1757 /*
1758 * At this point we have:
1759 * x0: start of the data to test
1760 * w1: char to compare
1761 * w2: iteration count
1762 * x5: original start of string data
1763 */
1764
1765 subs w2, w2, #4
1766 b.lt .Lindexof_remainder
1767
1768.Lindexof_loop4:
1769 ldrh w6, [x0, #2]!
1770 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08001771 ldrh wIP0, [x0, #2]!
1772 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01001773 cmp w6, w1
1774 b.eq .Lmatch_0
1775 cmp w7, w1
1776 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08001777 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001778 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08001779 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001780 b.eq .Lmatch_3
1781 subs w2, w2, #4
1782 b.ge .Lindexof_loop4
1783
1784.Lindexof_remainder:
1785 adds w2, w2, #4
1786 b.eq .Lindexof_nomatch
1787
1788.Lindexof_loop1:
1789 ldrh w6, [x0, #2]!
1790 cmp w6, w1
1791 b.eq .Lmatch_3
1792 subs w2, w2, #1
1793 b.ne .Lindexof_loop1
1794
1795.Lindexof_nomatch:
1796 mov x0, #-1
1797 ret
1798
1799.Lmatch_0:
1800 sub x0, x0, #6
1801 sub x0, x0, x5
1802 asr x0, x0, #1
1803 ret
1804.Lmatch_1:
1805 sub x0, x0, #4
1806 sub x0, x0, x5
1807 asr x0, x0, #1
1808 ret
1809.Lmatch_2:
1810 sub x0, x0, #2
1811 sub x0, x0, x5
1812 asr x0, x0, #1
1813 ret
1814.Lmatch_3:
1815 sub x0, x0, x5
1816 asr x0, x0, #1
1817 ret
1818END art_quick_indexof
Andreas Gampe266340d2014-05-02 07:55:24 -07001819
1820 /*
1821 * String's compareTo.
1822 *
1823 * TODO: Not very optimized.
1824 *
1825 * On entry:
1826 * x0: this object pointer
1827 * x1: comp object pointer
1828 *
1829 */
Serban Constantinescu86797a72014-06-19 16:17:56 +01001830 .extern __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001831ENTRY art_quick_string_compareto
1832 mov x2, x0 // x0 is return, use x2 for first input.
1833 sub x0, x2, x1 // Same string object?
1834 cbnz x0,1f
1835 ret
18361: // Different string objects.
1837
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001838 ldr w4, [x2, #MIRROR_STRING_COUNT_OFFSET]
1839 ldr w3, [x1, #MIRROR_STRING_COUNT_OFFSET]
Jeff Hao848f70a2014-01-15 13:49:50 -08001840 add x2, x2, #MIRROR_STRING_VALUE_OFFSET
1841 add x1, x1, #MIRROR_STRING_VALUE_OFFSET
Andreas Gampe266340d2014-05-02 07:55:24 -07001842
1843 /*
Jeff Hao848f70a2014-01-15 13:49:50 -08001844 * Now: Data* Count
1845 * first arg x2 w4
1846 * second arg x1 w3
Andreas Gampe266340d2014-05-02 07:55:24 -07001847 */
1848
1849 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4.
1850 subs x0, x4, x3
1851 // Min(count1, count2) into w3.
1852 csel x3, x3, x4, ge
1853
Serban Constantinescu169489b2014-06-11 16:43:35 +01001854 // TODO: Tune this value.
Andreas Gampe266340d2014-05-02 07:55:24 -07001855 // Check for long string, do memcmp16 for them.
1856 cmp w3, #28 // Constant from arm32.
1857 bgt .Ldo_memcmp16
1858
1859 /*
1860 * Now:
1861 * x2: *first string data
1862 * x1: *second string data
1863 * w3: iteration count
1864 * x0: return value if comparison equal
1865 * x4, x5, x6, x7: free
1866 */
1867
1868 // Do a simple unrolled loop.
1869.Lloop:
1870 // At least two more elements?
1871 subs w3, w3, #2
1872 b.lt .Lremainder_or_done
1873
1874 ldrh w4, [x2], #2
1875 ldrh w5, [x1], #2
1876
1877 ldrh w6, [x2], #2
1878 ldrh w7, [x1], #2
1879
1880 subs w4, w4, w5
1881 b.ne .Lw4_result
1882
1883 subs w6, w6, w7
1884 b.ne .Lw6_result
1885
1886 b .Lloop
1887
1888.Lremainder_or_done:
1889 adds w3, w3, #1
1890 b.eq .Lremainder
1891 ret
1892
1893.Lremainder:
1894 ldrh w4, [x2], #2
1895 ldrh w5, [x1], #2
1896 subs w4, w4, w5
1897 b.ne .Lw4_result
1898 ret
1899
1900// Result is in w4
1901.Lw4_result:
1902 sxtw x0, w4
1903 ret
1904
1905// Result is in w6
1906.Lw6_result:
1907 sxtw x0, w6
1908 ret
1909
1910.Ldo_memcmp16:
Zheng Xu62ddb322014-08-12 17:19:12 +08001911 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps.
1912 mov x15, xLR // TODO: Codify and check that?
Andreas Gampe266340d2014-05-02 07:55:24 -07001913
1914 mov x0, x2
1915 uxtw x2, w3
Serban Constantinescu86797a72014-06-19 16:17:56 +01001916 bl __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001917
Zheng Xu62ddb322014-08-12 17:19:12 +08001918 mov xLR, x15 // Restore LR.
Andreas Gampe266340d2014-05-02 07:55:24 -07001919
Serban Constantinescu86797a72014-06-19 16:17:56 +01001920 cmp x0, #0 // Check the memcmp difference.
Zheng Xu62ddb322014-08-12 17:19:12 +08001921 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1.
Andreas Gampe266340d2014-05-02 07:55:24 -07001922 ret
1923END art_quick_string_compareto
Zheng Xu0210d112014-06-17 12:25:48 +08001924
1925// Macro to facilitate adding new entrypoints which call to native function directly.
1926// Currently, xSELF is the only thing we need to take care of between managed code and AAPCS.
1927// But we might introduce more differences.
1928.macro NATIVE_DOWNCALL name, entrypoint
1929 .extern \entrypoint
1930ENTRY \name
Serban Constantinescu86797a72014-06-19 16:17:56 +01001931 stp xSELF, xLR, [sp, #-16]!
Zheng Xu0210d112014-06-17 12:25:48 +08001932 bl \entrypoint
Serban Constantinescu86797a72014-06-19 16:17:56 +01001933 ldp xSELF, xLR, [sp], #16
Zheng Xu0210d112014-06-17 12:25:48 +08001934 ret
1935END \name
1936.endm
1937
1938NATIVE_DOWNCALL art_quick_fmod fmod
1939NATIVE_DOWNCALL art_quick_fmodf fmodf
1940NATIVE_DOWNCALL art_quick_memcpy memcpy
Serban Constantinescu86797a72014-06-19 16:17:56 +01001941NATIVE_DOWNCALL art_quick_assignable_from_code artIsAssignableFromCode