blob: 62ae099c1c7ba2782d177819a17895d0093a4668 [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
Zheng Xub551fdc2014-07-25 11:49:42 +080035 ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ]
Andreas Gampe5c1e4352014-04-21 19:28:24 -070036
37 sub sp, sp, #176
38 .cfi_adjust_cfa_offset 176
39
40 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +080041#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 176)
42#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070043#endif
44
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 Xub551fdc2014-07-25 11:49:42 +080051 // Reserved registers
52 stp xSELF, xSUSPEND, [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]
Stuart Monteithb95a5342014-03-12 13:32:32 +000082.endm
83
Zheng Xub551fdc2014-07-25 11:49:42 +080084 /*
85 * Macro that sets up the callee save frame to conform with
86 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
87 */
88.macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME
89 adrp xIP0, :got:_ZN3art7Runtime9instance_E
90 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
91
92 // Our registers aren't intermixed - just spill in order.
93 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
94
95 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
96 THIS_LOAD_REQUIRES_READ_BARRIER
97 ldr xIP0, [xIP0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
98
99 sub sp, sp, #96
100 .cfi_adjust_cfa_offset 96
101
102 // Ugly compile-time check, but we only have the preprocessor.
103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 96)
104#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
105#endif
106
107 // Callee-saves
108 stp x20, x21, [sp, #8]
109 .cfi_rel_offset x20, 8
110 .cfi_rel_offset x21, 16
111
112 stp x22, x23, [sp, #24]
113 .cfi_rel_offset x22, 24
114 .cfi_rel_offset x23, 32
115
116 stp x24, x25, [sp, #40]
117 .cfi_rel_offset x24, 40
118 .cfi_rel_offset x25, 48
119
120 stp x26, x27, [sp, #56]
121 .cfi_rel_offset x26, 56
122 .cfi_rel_offset x27, 64
123
124 stp x28, x29, [sp, #72]
125 .cfi_rel_offset x28, 72
126 .cfi_rel_offset x29, 80
127
128 // LR
129 str xLR, [sp, #88]
130 .cfi_rel_offset x30, 88
131
132 // Save xSELF to xETR.
133 mov xETR, xSELF
134
135 // Loads appropriate callee-save-method
136 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
137.endm
138
139// TODO: Probably no need to restore registers preserved by aapcs64.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000140.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800141 // Restore xSELF.
142 mov xSELF, xETR
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700143
Zheng Xub551fdc2014-07-25 11:49:42 +0800144 // Callee-saves
145 ldp x20, x21, [sp, #8]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700146 .cfi_restore x20
147 .cfi_restore x21
148
Zheng Xub551fdc2014-07-25 11:49:42 +0800149 ldp x22, x23, [sp, #24]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700150 .cfi_restore x22
151 .cfi_restore x23
152
Zheng Xub551fdc2014-07-25 11:49:42 +0800153 ldp x24, x25, [sp, #40]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700154 .cfi_restore x24
155 .cfi_restore x25
156
Zheng Xub551fdc2014-07-25 11:49:42 +0800157 ldp x26, x27, [sp, #56]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700158 .cfi_restore x26
159 .cfi_restore x27
160
Zheng Xub551fdc2014-07-25 11:49:42 +0800161 ldp x28, x29, [sp, #72]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700162 .cfi_restore x28
163 .cfi_restore x29
164
Zheng Xub551fdc2014-07-25 11:49:42 +0800165 // LR
166 ldr xLR, [sp, #88]
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700167 .cfi_restore x30
168
Zheng Xub551fdc2014-07-25 11:49:42 +0800169 add sp, sp, #96
170 .cfi_adjust_cfa_offset -96
Stuart Monteithb95a5342014-03-12 13:32:32 +0000171.endm
172
Andreas Gamped58342c2014-06-05 14:18:08 -0700173.macro POP_REF_ONLY_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800174 // Restore xSELF as it might be scratched.
175 mov xSELF, xETR
176 // ETR
177 ldr xETR, [sp, #16]
178 .cfi_restore x21
179
180 add sp, sp, #96
181 .cfi_adjust_cfa_offset -96
Andreas Gamped58342c2014-06-05 14:18:08 -0700182.endm
183
Stuart Monteithb95a5342014-03-12 13:32:32 +0000184.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Zheng Xu48241e72014-05-23 11:52:42 +0800185 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
186 ret
Stuart Monteithb95a5342014-03-12 13:32:32 +0000187.endm
188
189
190.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Zheng Xub551fdc2014-07-25 11:49:42 +0800191 sub sp, sp, #224
192 .cfi_adjust_cfa_offset 224
Stuart Monteithb95a5342014-03-12 13:32:32 +0000193
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700194 // Ugly compile-time check, but we only have the preprocessor.
Zheng Xub551fdc2014-07-25 11:49:42 +0800195#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 224)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700196#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
197#endif
198
Zheng Xub551fdc2014-07-25 11:49:42 +0800199 // FP args
200 stp d0, d1, [sp, #16]
201 stp d2, d3, [sp, #32]
202 stp d4, d5, [sp, #48]
203 stp d6, d7, [sp, #64]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000204
Zheng Xub551fdc2014-07-25 11:49:42 +0800205 // args and x20(callee-save)
206 stp x1, x2, [sp, #80]
207 .cfi_rel_offset x1, 80
208 .cfi_rel_offset x2, 88
Stuart Monteithb95a5342014-03-12 13:32:32 +0000209
Zheng Xub551fdc2014-07-25 11:49:42 +0800210 stp x3, x4, [sp, #96]
211 .cfi_rel_offset x3, 96
212 .cfi_rel_offset x4, 104
Andreas Gampe03906cf2014-04-07 12:08:28 -0700213
Zheng Xub551fdc2014-07-25 11:49:42 +0800214 stp x5, x6, [sp, #112]
215 .cfi_rel_offset x5, 112
216 .cfi_rel_offset x6, 120
Andreas Gampe03906cf2014-04-07 12:08:28 -0700217
Zheng Xub551fdc2014-07-25 11:49:42 +0800218 stp x7, x20, [sp, #128]
219 .cfi_rel_offset x7, 128
220 .cfi_rel_offset x20, 136
Andreas Gampe03906cf2014-04-07 12:08:28 -0700221
Zheng Xub551fdc2014-07-25 11:49:42 +0800222 // Callee-saves.
223 stp x21, x22, [sp, #144]
224 .cfi_rel_offset x21, 144
225 .cfi_rel_offset x22, 152
Andreas Gampe03906cf2014-04-07 12:08:28 -0700226
Zheng Xub551fdc2014-07-25 11:49:42 +0800227 stp x23, x24, [sp, #160]
228 .cfi_rel_offset x23, 160
229 .cfi_rel_offset x24, 168
Andreas Gampe03906cf2014-04-07 12:08:28 -0700230
Zheng Xub551fdc2014-07-25 11:49:42 +0800231 stp x25, x26, [sp, #176]
232 .cfi_rel_offset x25, 176
233 .cfi_rel_offset x26, 184
Andreas Gampe03906cf2014-04-07 12:08:28 -0700234
Zheng Xub551fdc2014-07-25 11:49:42 +0800235 stp x27, x28, [sp, #192]
236 .cfi_rel_offset x27, 192
237 .cfi_rel_offset x28, 200
Andreas Gampe03906cf2014-04-07 12:08:28 -0700238
Zheng Xub551fdc2014-07-25 11:49:42 +0800239 // x29(callee-save) and LR
240 stp x29, xLR, [sp, #208]
241 .cfi_rel_offset x29, 208
242 .cfi_rel_offset x30, 216
Andreas Gampe03906cf2014-04-07 12:08:28 -0700243
Zheng Xub551fdc2014-07-25 11:49:42 +0800244 // Save xSELF to xETR.
245 mov xETR, xSELF
Stuart Monteithb95a5342014-03-12 13:32:32 +0000246.endm
247
248 /*
249 * Macro that sets up the callee save frame to conform with
250 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
251 *
252 * TODO This is probably too conservative - saving FP & LR.
253 */
254.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800255 adrp xIP0, :got:_ZN3art7Runtime9instance_E
256 ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000257
258 // Our registers aren't intermixed - just spill in order.
Zheng Xub551fdc2014-07-25 11:49:42 +0800259 ldr xIP0, [xIP0] // xIP0 = & (art::Runtime * art::Runtime.instance_) .
Stuart Monteithb95a5342014-03-12 13:32:32 +0000260
Zheng Xub551fdc2014-07-25 11:49:42 +0800261 // xIP0 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
Hiroshi Yamauchiab088112014-07-14 13:00:14 -0700262 THIS_LOAD_REQUIRES_READ_BARRIER
Zheng Xub551fdc2014-07-25 11:49:42 +0800263 ldr xIP0, [xIP0, RUNTIME_REF_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000264
265 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
266
Zheng Xub551fdc2014-07-25 11:49:42 +0800267 str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000268.endm
269
Zheng Xub551fdc2014-07-25 11:49:42 +0800270// TODO: Probably no need to restore registers preserved by aapcs64.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000271.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +0800272 // Restore xSELF.
273 mov xSELF, xETR
Stuart Monteithb95a5342014-03-12 13:32:32 +0000274
Zheng Xub551fdc2014-07-25 11:49:42 +0800275 // FP args
276 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 Xub551fdc2014-07-25 11:49:42 +0800281 // args and x20(callee-save)
282 ldp x1, x2, [sp, #80]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700283 .cfi_restore x1
284 .cfi_restore x2
285
Zheng Xub551fdc2014-07-25 11:49:42 +0800286 ldp x3, x4, [sp, #96]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700287 .cfi_restore x3
288 .cfi_restore x4
289
Zheng Xub551fdc2014-07-25 11:49:42 +0800290 ldp x5, x6, [sp, #112]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700291 .cfi_restore x5
292 .cfi_restore x6
293
Zheng Xub551fdc2014-07-25 11:49:42 +0800294 ldp x7, x20, [sp, #128]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700295 .cfi_restore x7
Andreas Gampe03906cf2014-04-07 12:08:28 -0700296 .cfi_restore x20
297
Zheng Xub551fdc2014-07-25 11:49:42 +0800298 // Callee-saves.
299 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
Zheng Xub551fdc2014-07-25 11:49:42 +0800315 // x29(callee-save) and LR
316 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
343 mov x1, sp
344
345 // Point of no return.
346 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*, SP)
347 brk 0 // Unreached
348.endm
349
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700350.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg
351 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
352 cbnz \reg, 1f
Stuart Monteithb95a5342014-03-12 13:32:32 +0000353 ret
3541:
355 DELIVER_PENDING_EXCEPTION
356.endm
357
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700358.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
Zheng Xub551fdc2014-07-25 11:49:42 +0800359 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0
Andreas Gampe6e4e59c2014-05-05 20:11:02 -0700360.endm
361
362// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register.
363.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
364 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1
365.endm
366
367.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER
368 cbnz w0, 1f // result non-zero branch over
369 ret // return
3701:
371 DELIVER_PENDING_EXCEPTION
372.endm
373
Stuart Monteithb95a5342014-03-12 13:32:32 +0000374.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
375 .extern \cxx_name
376ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700377 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800378 mov x0, xSELF // pass Thread::Current
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700379 mov x1, sp // pass SP
380 b \cxx_name // \cxx_name(Thread*, SP)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000381END \c_name
382.endm
383
384.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
385 .extern \cxx_name
386ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100387 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
Zheng Xub551fdc2014-07-25 11:49:42 +0800388 mov x1, xSELF // pass Thread::Current.
Serban Constantinescu75b91132014-04-09 18:39:10 +0100389 mov x2, sp // pass SP.
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700390 b \cxx_name // \cxx_name(arg, Thread*, SP).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000391 brk 0
392END \c_name
393.endm
394
395.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
396 .extern \cxx_name
397ENTRY \c_name
398 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Zheng Xub551fdc2014-07-25 11:49:42 +0800399 mov x2, xSELF // pass Thread::Current
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700400 mov x3, sp // pass SP
401 b \cxx_name // \cxx_name(arg1, arg2, Thread*, SP)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000402 brk 0
403END \c_name
404.endm
405
406 /*
407 * Called by managed code, saves callee saves and then calls artThrowException
408 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
409 */
410ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
411
412 /*
413 * Called by managed code to create and deliver a NullPointerException.
414 */
415NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
416
417 /*
418 * Called by managed code to create and deliver an ArithmeticException.
419 */
420NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
421
422 /*
423 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
424 * index, arg2 holds limit.
425 */
426TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
427
428 /*
429 * Called by managed code to create and deliver a StackOverflowError.
430 */
431NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
432
433 /*
434 * Called by managed code to create and deliver a NoSuchMethodError.
435 */
436ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
437
Stuart Monteithd5c78f42014-06-11 16:44:46 +0100438 /*
439 * Invoke stack overflow exception from signal handler.
440 * On entry:
441 * xSELF: thread
442 * SP: address of last known frame
443 * IP0: address of next valid SP below protected region in stack
444 *
445 * This is deceptively simple but hides some complexity. It is called in the case of
446 * a stack overflow condition during implicit checks. The signal handler has been
447 * called by the kernel due to a load from the protected stack region. The handler
448 * works out the address of the previous frame and passes this in SP. However there
449 * is a piece of memory somewhere below the current SP that is not accessible (the
450 * memory that caused the signal). The signal handler works out the next
451 * accessible value of SP and passes this in x16/IP0. This code then sets up the SP
452 * to be this new value and calls the code to create and throw the stack overflow
453 * exception.
454 */
455ENTRY art_quick_throw_stack_overflow_from_signal
456 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
457 mov x0, xSELF // pass Thread::Current
458 mov x1, sp // pass SP
459 mov sp, xIP0 // move SP down to below protected region.
460 b artThrowStackOverflowFromCode // artThrowStackOverflowFromCode(Thread*, SP)
461END art_quick_throw_stack_overflow_from_signal
462
Stuart Monteithb95a5342014-03-12 13:32:32 +0000463 /*
Stuart Monteithb95a5342014-03-12 13:32:32 +0000464 * All generated callsites for interface invokes and invocation slow paths will load arguments
Andreas Gampe51f76352014-05-21 08:28:48 -0700465 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain
466 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000467 * stack and call the appropriate C helper.
Andreas Gampe51f76352014-05-21 08:28:48 -0700468 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000469 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700470 * 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 +0000471 * of the target Method* in x0 and method->code_ in x1.
472 *
Andreas Gampe51f76352014-05-21 08:28:48 -0700473 * If unsuccessful, the helper will return NULL/????. There will be a pending exception in the
Stuart Monteithb95a5342014-03-12 13:32:32 +0000474 * thread and we branch to another stub to deliver it.
475 *
476 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
477 * pointing back to the original caller.
Andreas Gampe51f76352014-05-21 08:28:48 -0700478 *
479 * Adapted from ARM32 code.
480 *
Zheng Xub551fdc2014-07-25 11:49:42 +0800481 * Clobbers xIP0.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000482 */
483.macro INVOKE_TRAMPOLINE c_name, cxx_name
484 .extern \cxx_name
485ENTRY \c_name
Andreas Gampe51f76352014-05-21 08:28:48 -0700486 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC
487 // Helper signature is always
488 // (method_idx, *this_object, *caller_method, *self, sp)
489
Alexei Zavjalov41c507a2014-05-15 16:02:46 +0700490 ldr w2, [sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE] // pass caller Method*
Andreas Gampe51f76352014-05-21 08:28:48 -0700491 mov x3, xSELF // pass Thread::Current
492 mov x4, sp
493 bl \cxx_name // (method_idx, this, caller, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +0800494 mov xIP0, x1 // save Method*->code_
Andreas Gampe51f76352014-05-21 08:28:48 -0700495 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
496 cbz x0, 1f // did we find the target? if not go to exception delivery
Zheng Xub551fdc2014-07-25 11:49:42 +0800497 br xIP0 // tail call to target
Andreas Gampe51f76352014-05-21 08:28:48 -07004981:
499 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +0000500END \c_name
501.endm
502
503INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
504INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
505
506INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
507INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
508INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
509INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
510
Andreas Gampe03906cf2014-04-07 12:08:28 -0700511
512.macro INVOKE_STUB_CREATE_FRAME
513
Zheng Xub551fdc2014-07-25 11:49:42 +0800514SAVE_SIZE=6*8 // x4, x5, xSUSPEND, SP, LR & FP saved.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700515SAVE_SIZE_AND_METHOD=SAVE_SIZE+STACK_REFERENCE_SIZE
516
Andreas Gampe03906cf2014-04-07 12:08:28 -0700517
Zheng Xu48241e72014-05-23 11:52:42 +0800518 mov x9, sp // Save stack pointer.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700519 .cfi_register sp,x9
520
Zheng Xu48241e72014-05-23 11:52:42 +0800521 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
522 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
523 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
524 mov sp, x10 // Set new SP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700525
Zheng Xu48241e72014-05-23 11:52:42 +0800526 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
527 .cfi_def_cfa_register x10 // before this.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700528 .cfi_adjust_cfa_offset SAVE_SIZE
529
Zheng Xub551fdc2014-07-25 11:49:42 +0800530 stp x9, xSUSPEND, [x10, #32] // Save old stack pointer and xSUSPEND
Andreas Gampe03906cf2014-04-07 12:08:28 -0700531 .cfi_rel_offset sp, 32
Andreas Gampecf4035a2014-05-28 22:43:01 -0700532 .cfi_rel_offset x19, 40
Andreas Gampe03906cf2014-04-07 12:08:28 -0700533
Zheng Xu48241e72014-05-23 11:52:42 +0800534 stp x4, x5, [x10, #16] // Save result and shorty addresses.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700535 .cfi_rel_offset x4, 16
536 .cfi_rel_offset x5, 24
537
Zheng Xu48241e72014-05-23 11:52:42 +0800538 stp xFP, xLR, [x10] // Store LR & FP.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700539 .cfi_rel_offset x29, 0
540 .cfi_rel_offset x30, 8
541
Zheng Xu48241e72014-05-23 11:52:42 +0800542 mov xFP, x10 // Use xFP now, as it's callee-saved.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700543 .cfi_def_cfa_register x29
Zheng Xu48241e72014-05-23 11:52:42 +0800544 mov xSELF, x3 // Move thread pointer into SELF register.
545 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to suspend check interval
Andreas Gampe03906cf2014-04-07 12:08:28 -0700546
547 // Copy arguments into stack frame.
548 // Use simple copy routine for now.
549 // 4 bytes per slot.
550 // X1 - source address
551 // W2 - args length
552 // X9 - destination address.
553 // W10 - temporary
Andreas Gampecf4035a2014-05-28 22:43:01 -0700554 add x9, sp, #4 // Destination address is bottom of stack + NULL.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700555
556 // Use \@ to differentiate between macro invocations.
557.LcopyParams\@:
558 cmp w2, #0
559 beq .LendCopyParams\@
560 sub w2, w2, #4 // Need 65536 bytes of range.
561 ldr w10, [x1, x2]
562 str w10, [x9, x2]
563
564 b .LcopyParams\@
565
566.LendCopyParams\@:
567
Andreas Gampecf4035a2014-05-28 22:43:01 -0700568 // Store NULL into StackReference<Method>* at bottom of frame.
569 str wzr, [sp]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700570
Andreas Gampecf4035a2014-05-28 22:43:01 -0700571#if (STACK_REFERENCE_SIZE != 4)
572#error "STACK_REFERENCE_SIZE(ARM64) size not as expected."
573#endif
Andreas Gampe03906cf2014-04-07 12:08:28 -0700574.endm
575
576.macro INVOKE_STUB_CALL_AND_RETURN
577
578 // load method-> METHOD_QUICK_CODE_OFFSET
579 ldr x9, [x0 , #METHOD_QUICK_CODE_OFFSET]
580 // Branch to method.
581 blr x9
582
583 // Restore return value address and shorty address.
584 ldp x4,x5, [xFP, #16]
585 .cfi_restore x4
586 .cfi_restore x5
587
588 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
589 ldrb w10, [x5]
590
591 // Don't set anything for a void type.
592 cmp w10, #'V'
593 beq .Lexit_art_quick_invoke_stub\@
594
595 cmp w10, #'D'
596 bne .Lreturn_is_float\@
597 str d0, [x4]
598 b .Lexit_art_quick_invoke_stub\@
599
600.Lreturn_is_float\@:
601 cmp w10, #'F'
602 bne .Lreturn_is_int\@
603 str s0, [x4]
604 b .Lexit_art_quick_invoke_stub\@
605
606 // Just store x0. Doesn't matter if it is 64 or 32 bits.
607.Lreturn_is_int\@:
608 str x0, [x4]
609
610.Lexit_art_quick_invoke_stub\@:
Zheng Xub551fdc2014-07-25 11:49:42 +0800611 ldp x2, xSUSPEND, [xFP, #32] // Restore stack pointer and xSUSPEND.
Andreas Gampecf4035a2014-05-28 22:43:01 -0700612 .cfi_restore x19
Andreas Gampe03906cf2014-04-07 12:08:28 -0700613 mov sp, x2
614 .cfi_restore sp
615
Andreas Gamped58342c2014-06-05 14:18:08 -0700616 ldp xFP, xLR, [xFP] // Restore old frame pointer and link register.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700617 .cfi_restore x29
618 .cfi_restore x30
619
620 ret
621
622.endm
623
624
Stuart Monteithb95a5342014-03-12 13:32:32 +0000625/*
626 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
627 * uint32_t *args, x1
628 * uint32_t argsize, w2
629 * Thread *self, x3
630 * JValue *result, x4
631 * char *shorty); x5
632 * +----------------------+
633 * | |
634 * | C/C++ frame |
635 * | LR'' |
636 * | FP'' | <- SP'
637 * +----------------------+
638 * +----------------------+
Zheng Xub551fdc2014-07-25 11:49:42 +0800639 * | x19 | <- Used as wSUSPEND, won't be restored by managed code.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000640 * | SP' |
641 * | X5 |
642 * | X4 | Saved registers
643 * | LR' |
644 * | FP' | <- FP
645 * +----------------------+
646 * | uint32_t out[n-1] |
647 * | : : | Outs
648 * | uint32_t out[0] |
Andreas Gampecf4035a2014-05-28 22:43:01 -0700649 * | StackRef<ArtMethod> | <- SP value=null
Stuart Monteithb95a5342014-03-12 13:32:32 +0000650 * +----------------------+
651 *
652 * Outgoing registers:
653 * x0 - Method*
654 * x1-x7 - integer parameters.
655 * d0-d7 - Floating point parameters.
656 * xSELF = self
Zheng Xu48241e72014-05-23 11:52:42 +0800657 * wSUSPEND = suspend count
Stuart Monteithb95a5342014-03-12 13:32:32 +0000658 * SP = & of ArtMethod*
659 * x1 = "this" pointer.
660 *
661 */
662ENTRY art_quick_invoke_stub
663 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700664 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000665
666 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
667 // Parse the passed shorty to determine which register to load.
668 // Load addresses for routines that load WXSD registers.
669 adr x11, .LstoreW2
670 adr x12, .LstoreX2
671 adr x13, .LstoreS0
672 adr x14, .LstoreD0
673
674 // Initialize routine offsets to 0 for integers and floats.
675 // x8 for integers, x15 for floating point.
676 mov x8, #0
677 mov x15, #0
678
679 add x10, x5, #1 // Load shorty address, plus one to skip return value.
680 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
681
682 // Loop to fill registers.
683.LfillRegisters:
684 ldrb w17, [x10], #1 // Load next character in signature, and increment.
685 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
686
687 cmp w17, #'F' // is this a float?
688 bne .LisDouble
689
690 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700691 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000692
693 add x17, x13, x15 // Calculate subroutine to jump to.
694 br x17
695
696.LisDouble:
697 cmp w17, #'D' // is this a double?
698 bne .LisLong
699
700 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700701 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000702
703 add x17, x14, x15 // Calculate subroutine to jump to.
704 br x17
705
706.LisLong:
707 cmp w17, #'J' // is this a long?
708 bne .LisOther
709
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700710 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700711 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000712
713 add x17, x12, x8 // Calculate subroutine to jump to.
714 br x17
715
Stuart Monteithb95a5342014-03-12 13:32:32 +0000716.LisOther: // Everything else takes one vReg.
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 .Ladvance4
719
Stuart Monteithb95a5342014-03-12 13:32:32 +0000720 add x17, x11, x8 // Calculate subroutine to jump to.
721 br x17
722
Andreas Gampe03906cf2014-04-07 12:08:28 -0700723.Ladvance4:
724 add x9, x9, #4
725 b .LfillRegisters
726
727.Ladvance8:
728 add x9, x9, #8
729 b .LfillRegisters
730
Stuart Monteithb95a5342014-03-12 13:32:32 +0000731// Macro for loading a parameter into a register.
732// counter - the register with offset into these tables
733// size - the size of the register - 4 or 8 bytes.
734// register - the name of the register to be loaded.
735.macro LOADREG counter size register return
736 ldr \register , [x9], #\size
737 add \counter, \counter, 12
738 b \return
739.endm
740
741// Store ints.
742.LstoreW2:
743 LOADREG x8 4 w2 .LfillRegisters
744 LOADREG x8 4 w3 .LfillRegisters
745 LOADREG x8 4 w4 .LfillRegisters
746 LOADREG x8 4 w5 .LfillRegisters
747 LOADREG x8 4 w6 .LfillRegisters
748 LOADREG x8 4 w7 .LfillRegisters
749
750// Store longs.
751.LstoreX2:
752 LOADREG x8 8 x2 .LfillRegisters
753 LOADREG x8 8 x3 .LfillRegisters
754 LOADREG x8 8 x4 .LfillRegisters
755 LOADREG x8 8 x5 .LfillRegisters
756 LOADREG x8 8 x6 .LfillRegisters
757 LOADREG x8 8 x7 .LfillRegisters
758
759// Store singles.
760.LstoreS0:
761 LOADREG x15 4 s0 .LfillRegisters
762 LOADREG x15 4 s1 .LfillRegisters
763 LOADREG x15 4 s2 .LfillRegisters
764 LOADREG x15 4 s3 .LfillRegisters
765 LOADREG x15 4 s4 .LfillRegisters
766 LOADREG x15 4 s5 .LfillRegisters
767 LOADREG x15 4 s6 .LfillRegisters
768 LOADREG x15 4 s7 .LfillRegisters
769
770// Store doubles.
771.LstoreD0:
772 LOADREG x15 8 d0 .LfillRegisters
773 LOADREG x15 8 d1 .LfillRegisters
774 LOADREG x15 8 d2 .LfillRegisters
775 LOADREG x15 8 d3 .LfillRegisters
776 LOADREG x15 8 d4 .LfillRegisters
777 LOADREG x15 8 d5 .LfillRegisters
778 LOADREG x15 8 d6 .LfillRegisters
779 LOADREG x15 8 d7 .LfillRegisters
780
781
782.LcallFunction:
783
Andreas Gampe03906cf2014-04-07 12:08:28 -0700784 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000785
Stuart Monteithb95a5342014-03-12 13:32:32 +0000786END art_quick_invoke_stub
787
788/* extern"C"
789 * void art_quick_invoke_static_stub(ArtMethod *method, x0
790 * uint32_t *args, x1
791 * uint32_t argsize, w2
792 * Thread *self, x3
793 * JValue *result, x4
794 * char *shorty); x5
795 */
796ENTRY art_quick_invoke_static_stub
797 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700798 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000799
800 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
801 // Parse the passed shorty to determine which register to load.
802 // Load addresses for routines that load WXSD registers.
803 adr x11, .LstoreW1_2
804 adr x12, .LstoreX1_2
805 adr x13, .LstoreS0_2
806 adr x14, .LstoreD0_2
807
808 // Initialize routine offsets to 0 for integers and floats.
809 // x8 for integers, x15 for floating point.
810 mov x8, #0
811 mov x15, #0
812
813 add x10, x5, #1 // Load shorty address, plus one to skip return value.
814
815 // Loop to fill registers.
816.LfillRegisters2:
817 ldrb w17, [x10], #1 // Load next character in signature, and increment.
818 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
819
820 cmp w17, #'F' // is this a float?
821 bne .LisDouble2
822
823 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700824 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000825
826 add x17, x13, x15 // Calculate subroutine to jump to.
827 br x17
828
829.LisDouble2:
830 cmp w17, #'D' // is this a double?
831 bne .LisLong2
832
833 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700834 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000835
836 add x17, x14, x15 // Calculate subroutine to jump to.
837 br x17
838
839.LisLong2:
840 cmp w17, #'J' // is this a long?
841 bne .LisOther2
842
843 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700844 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000845
846 add x17, x12, x8 // Calculate subroutine to jump to.
847 br x17
848
Stuart Monteithb95a5342014-03-12 13:32:32 +0000849.LisOther2: // Everything else takes one vReg.
850 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700851 beq .Ladvance4_2
852
Stuart Monteithb95a5342014-03-12 13:32:32 +0000853 add x17, x11, x8 // Calculate subroutine to jump to.
854 br x17
855
Andreas Gampe03906cf2014-04-07 12:08:28 -0700856.Ladvance4_2:
857 add x9, x9, #4
858 b .LfillRegisters2
859
860.Ladvance8_2:
861 add x9, x9, #8
862 b .LfillRegisters2
863
Stuart Monteithb95a5342014-03-12 13:32:32 +0000864// Store ints.
865.LstoreW1_2:
866 LOADREG x8 4 w1 .LfillRegisters2
867 LOADREG x8 4 w2 .LfillRegisters2
868 LOADREG x8 4 w3 .LfillRegisters2
869 LOADREG x8 4 w4 .LfillRegisters2
870 LOADREG x8 4 w5 .LfillRegisters2
871 LOADREG x8 4 w6 .LfillRegisters2
872 LOADREG x8 4 w7 .LfillRegisters2
873
874// Store longs.
875.LstoreX1_2:
876 LOADREG x8 8 x1 .LfillRegisters2
877 LOADREG x8 8 x2 .LfillRegisters2
878 LOADREG x8 8 x3 .LfillRegisters2
879 LOADREG x8 8 x4 .LfillRegisters2
880 LOADREG x8 8 x5 .LfillRegisters2
881 LOADREG x8 8 x6 .LfillRegisters2
882 LOADREG x8 8 x7 .LfillRegisters2
883
884// Store singles.
885.LstoreS0_2:
886 LOADREG x15 4 s0 .LfillRegisters2
887 LOADREG x15 4 s1 .LfillRegisters2
888 LOADREG x15 4 s2 .LfillRegisters2
889 LOADREG x15 4 s3 .LfillRegisters2
890 LOADREG x15 4 s4 .LfillRegisters2
891 LOADREG x15 4 s5 .LfillRegisters2
892 LOADREG x15 4 s6 .LfillRegisters2
893 LOADREG x15 4 s7 .LfillRegisters2
894
895// Store doubles.
896.LstoreD0_2:
897 LOADREG x15 8 d0 .LfillRegisters2
898 LOADREG x15 8 d1 .LfillRegisters2
899 LOADREG x15 8 d2 .LfillRegisters2
900 LOADREG x15 8 d3 .LfillRegisters2
901 LOADREG x15 8 d4 .LfillRegisters2
902 LOADREG x15 8 d5 .LfillRegisters2
903 LOADREG x15 8 d6 .LfillRegisters2
904 LOADREG x15 8 d7 .LfillRegisters2
905
906
907.LcallFunction2:
908
Andreas Gampe03906cf2014-04-07 12:08:28 -0700909 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000910
Stuart Monteithb95a5342014-03-12 13:32:32 +0000911END art_quick_invoke_static_stub
912
Andreas Gampe03906cf2014-04-07 12:08:28 -0700913
Stuart Monteithb95a5342014-03-12 13:32:32 +0000914
915 /*
916 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
917 */
918
919ENTRY art_quick_do_long_jump
920 // Load FPRs
921 ldp d0, d1, [x1], #16
922 ldp d2, d3, [x1], #16
923 ldp d4, d5, [x1], #16
924 ldp d6, d7, [x1], #16
925 ldp d8, d9, [x1], #16
926 ldp d10, d11, [x1], #16
927 ldp d12, d13, [x1], #16
928 ldp d14, d15, [x1], #16
929 ldp d16, d17, [x1], #16
930 ldp d18, d19, [x1], #16
931 ldp d20, d21, [x1], #16
932 ldp d22, d23, [x1], #16
933 ldp d24, d25, [x1], #16
934 ldp d26, d27, [x1], #16
935 ldp d28, d29, [x1], #16
936 ldp d30, d31, [x1]
937
938 // Load GPRs
939 // TODO: lots of those are smashed, could optimize.
940 add x0, x0, #30*8
941 ldp x30, x1, [x0], #-16
942 ldp x28, x29, [x0], #-16
943 ldp x26, x27, [x0], #-16
944 ldp x24, x25, [x0], #-16
945 ldp x22, x23, [x0], #-16
946 ldp x20, x21, [x0], #-16
947 ldp x18, x19, [x0], #-16
948 ldp x16, x17, [x0], #-16
949 ldp x14, x15, [x0], #-16
950 ldp x12, x13, [x0], #-16
951 ldp x10, x11, [x0], #-16
952 ldp x8, x9, [x0], #-16
953 ldp x6, x7, [x0], #-16
954 ldp x4, x5, [x0], #-16
955 ldp x2, x3, [x0], #-16
956 mov sp, x1
957
958 // TODO: Is it really OK to use LR for the target PC?
959 mov x0, #0
960 mov x1, #0
961 br xLR
962END art_quick_do_long_jump
963
Andreas Gampef4e910b2014-04-29 16:55:52 -0700964 /*
965 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
966 * failure.
967 */
968 .extern artHandleFillArrayDataFromCode
Andreas Gampef4e910b2014-04-29 16:55:52 -0700969ENTRY art_quick_handle_fill_data
970 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // Save callee saves in case exception allocation triggers GC.
971 mov x2, xSELF // Pass Thread::Current.
972 mov x3, sp // Pass SP.
973 bl artHandleFillArrayDataFromCode // (Array*, const DexFile::Payload*, Thread*, SP)
974 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
975 RETURN_IF_RESULT_IS_ZERO
976 DELIVER_PENDING_EXCEPTION
977END art_quick_handle_fill_data
Stuart Monteithb95a5342014-03-12 13:32:32 +0000978
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700979 /*
980 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the
981 * possibly null object to lock.
982 *
983 * Derived from arm32 code.
984 */
985 .extern artLockObjectFromCode
986ENTRY art_quick_lock_object
987 cbz w0, .Lslow_lock
988 add x4, x0, #LOCK_WORD_OFFSET // exclusive load/store had no immediate anymore
989.Lretry_lock:
990 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop?
991 ldxr w1, [x4]
992 cbnz w1, .Lnot_unlocked // already thin locked
993 stxr w3, w2, [x4]
994 cbnz w3, .Lstrex_fail // store failed, retry
Andreas Gampe675967d2014-05-14 16:28:34 -0700995 dmb ishld // full (LoadLoad|LoadStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -0700996 ret
997.Lstrex_fail:
998 b .Lretry_lock // unlikely forward branch, need to reload and recheck r1/r2
999.Lnot_unlocked:
1000 lsr w3, w1, 30
1001 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path
1002 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1003 uxth w2, w2 // zero top 16 bits
1004 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock
1005 // else contention, go to slow path
1006 add w2, w1, #65536 // increment count in lock word placing in w2 for storing
1007 lsr w1, w2, 30 // if either of the top two bits are set, we overflowed.
1008 cbnz w1, .Lslow_lock // if we overflow the count go slow path
1009 str w2, [x0, #LOCK_WORD_OFFSET]// no need for stxr as we hold the lock
1010 ret
1011.Lslow_lock:
1012 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block
1013 mov x1, xSELF // pass Thread::Current
1014 mov x2, sp // pass SP
1015 bl artLockObjectFromCode // (Object* obj, Thread*, SP)
1016 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1017 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1018END art_quick_lock_object
1019
1020 /*
1021 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1022 * x0 holds the possibly null object to lock.
1023 *
1024 * Derived from arm32 code.
1025 */
1026 .extern artUnlockObjectFromCode
1027ENTRY art_quick_unlock_object
1028 cbz x0, .Lslow_unlock
1029 ldr w1, [x0, #LOCK_WORD_OFFSET]
1030 lsr w2, w1, 30
1031 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path
1032 ldr w2, [xSELF, #THREAD_ID_OFFSET]
1033 eor w3, w1, w2 // lock_word.ThreadId() ^ self->ThreadId()
1034 uxth w3, w3 // zero top 16 bits
1035 cbnz w3, .Lslow_unlock // do lock word and self thread id's match?
1036 cmp w1, #65536
1037 bpl .Lrecursive_thin_unlock
1038 // transition to unlocked, w3 holds 0
Andreas Gampe675967d2014-05-14 16:28:34 -07001039 dmb ish // full (LoadStore|StoreStore) memory barrier
Andreas Gampe4fc046e2014-05-06 16:56:39 -07001040 str w3, [x0, #LOCK_WORD_OFFSET]
1041 ret
1042.Lrecursive_thin_unlock:
1043 sub w1, w1, #65536
1044 str w1, [x0, #LOCK_WORD_OFFSET]
1045 ret
1046.Lslow_unlock:
1047 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC
1048 mov x1, xSELF // pass Thread::Current
1049 mov x2, sp // pass SP
1050 bl artUnlockObjectFromCode // (Object* obj, Thread*, SP)
1051 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1052 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1053END art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -07001054
1055 /*
1056 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
1057 * artThrowClassCastException.
1058 */
1059 .extern artThrowClassCastException
1060ENTRY art_quick_check_cast
1061 // Store arguments and link register
1062 sub sp, sp, #32 // Stack needs to be 16b aligned on calls
1063 .cfi_adjust_cfa_offset 32
1064 stp x0, x1, [sp]
1065 .cfi_rel_offset x0, 0
1066 .cfi_rel_offset x1, 8
1067 stp xSELF, xLR, [sp, #16]
1068 .cfi_rel_offset x18, 16
1069 .cfi_rel_offset x30, 24
1070
1071 // Call runtime code
1072 bl artIsAssignableFromCode
1073
1074 // Check for exception
1075 cbz x0, .Lthrow_class_cast_exception
1076
1077 // Restore and return
1078 ldp x0, x1, [sp]
1079 .cfi_restore x0
1080 .cfi_restore x1
1081 ldp xSELF, xLR, [sp, #16]
1082 .cfi_restore x18
1083 .cfi_restore x30
1084 add sp, sp, #32
1085 .cfi_adjust_cfa_offset -32
1086 ret
1087
1088.Lthrow_class_cast_exception:
1089 // Restore
1090 ldp x0, x1, [sp]
1091 .cfi_restore x0
1092 .cfi_restore x1
1093 ldp xSELF, xLR, [sp, #16]
1094 .cfi_restore x18
1095 .cfi_restore x30
1096 add sp, sp, #32
1097 .cfi_adjust_cfa_offset -32
1098
1099 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1100 mov x2, xSELF // pass Thread::Current
1101 mov x3, sp // pass SP
1102 b artThrowClassCastException // (Class*, Class*, Thread*, SP)
1103 brk 0 // We should not return here...
1104END art_quick_check_cast
1105
Andreas Gampef4e910b2014-04-29 16:55:52 -07001106 /*
1107 * Entry from managed code for array put operations of objects where the value being stored
1108 * needs to be checked for compatibility.
1109 * x0 = array, x1 = index, x2 = value
1110 *
1111 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We
1112 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by
1113 * using index-zero-extension in load/stores.
1114 *
1115 * Temporaries: x3, x4
1116 * TODO: x4 OK? ip seems wrong here.
1117 */
1118ENTRY art_quick_aput_obj_with_null_and_bound_check
1119 tst x0, x0
1120 bne art_quick_aput_obj_with_bound_check
1121 b art_quick_throw_null_pointer_exception
1122END art_quick_aput_obj_with_null_and_bound_check
1123
1124ENTRY art_quick_aput_obj_with_bound_check
1125 ldr w3, [x0, #ARRAY_LENGTH_OFFSET]
1126 cmp w3, w1
1127 bhi art_quick_aput_obj
1128 mov x0, x1
1129 mov x1, x3
1130 b art_quick_throw_array_bounds
1131END art_quick_aput_obj_with_bound_check
1132
1133ENTRY art_quick_aput_obj
1134 cbz x2, .Ldo_aput_null
1135 ldr w3, [x0, #CLASS_OFFSET] // Heap reference = 32b
1136 // This also zero-extends to x3
1137 ldr w4, [x2, #CLASS_OFFSET] // Heap reference = 32b
1138 // This also zero-extends to x4
1139 ldr w3, [x3, #CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b
1140 // This also zero-extends to x3
1141 cmp w3, w4 // value's type == array's component type - trivial assignability
1142 bne .Lcheck_assignability
1143.Ldo_aput:
1144 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET
1145 // "Compress" = do nothing
1146 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1147 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1148 lsr x0, x0, #7
1149 strb w3, [x3, x0]
1150 ret
1151.Ldo_aput_null:
1152 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET
1153 // "Compress" = do nothing
1154 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1155 ret
1156.Lcheck_assignability:
1157 // Store arguments and link register
1158 sub sp, sp, #48 // Stack needs to be 16b aligned on calls
1159 .cfi_adjust_cfa_offset 48
1160 stp x0, x1, [sp]
1161 .cfi_rel_offset x0, 0
1162 .cfi_rel_offset x1, 8
1163 stp x2, xSELF, [sp, #16]
1164 .cfi_rel_offset x2, 16
1165 .cfi_rel_offset x18, 24
1166 str xLR, [sp, #32]
1167 .cfi_rel_offset x30, 32
1168
1169 // Call runtime code
1170 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1171 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended
1172 bl artIsAssignableFromCode
1173
1174 // Check for exception
1175 cbz x0, .Lthrow_array_store_exception
1176
1177 // Restore
1178 ldp x0, x1, [sp]
1179 .cfi_restore x0
1180 .cfi_restore x1
1181 ldp x2, xSELF, [sp, #16]
1182 .cfi_restore x2
1183 .cfi_restore x18
1184 ldr xLR, [sp, #32]
1185 .cfi_restore x30
1186 add sp, sp, #48
1187 .cfi_adjust_cfa_offset -48
1188
1189 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET
1190 // "Compress" = do nothing
1191 str w2, [x3, x1, lsl #2] // Heap reference = 32b
1192 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET]
1193 lsr x0, x0, #7
1194 strb w3, [x3, x0]
1195 ret
1196.Lthrow_array_store_exception:
1197 ldp x0, x1, [sp]
1198 .cfi_restore x0
1199 .cfi_restore x1
1200 ldp x2, xSELF, [sp, #16]
1201 .cfi_restore x2
1202 .cfi_restore x18
1203 ldr xLR, [sp, #32]
1204 .cfi_restore x30
1205 add sp, sp, #48
1206 .cfi_adjust_cfa_offset -48
1207
1208 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1209 mov x1, x2 // Pass value.
1210 mov x2, xSELF // Pass Thread::Current.
1211 mov x3, sp // Pass SP.
1212 b artThrowArrayStoreException // (Object*, Object*, Thread*, SP).
1213 brk 0 // Unreached.
1214END art_quick_aput_obj
1215
Stuart Monteithb95a5342014-03-12 13:32:32 +00001216// Macro to facilitate adding new allocation entrypoints.
1217.macro TWO_ARG_DOWNCALL name, entrypoint, return
1218 .extern \entrypoint
1219ENTRY \name
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001220 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1221 mov x2, xSELF // pass Thread::Current
1222 mov x3, sp // pass SP
1223 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
1224 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1225 \return
1226 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001227END \name
1228.endm
1229
1230// Macro to facilitate adding new array allocation entrypoints.
1231.macro THREE_ARG_DOWNCALL name, entrypoint, return
1232 .extern \entrypoint
1233ENTRY \name
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001234 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1235 mov x3, xSELF // pass Thread::Current
1236 mov x4, sp // pass SP
1237 bl \entrypoint
1238 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1239 \return
1240 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001241END \name
1242.endm
1243
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001244// Macros taking opportunity of code similarities for downcalls with referrer.
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001245.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return
1246 .extern \entrypoint
1247ENTRY \name
1248 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001249 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001250 mov x2, xSELF // pass Thread::Current
1251 mov x3, sp // pass SP
1252 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
1253 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1254 \return
1255END \name
1256.endm
1257
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001258.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return
1259 .extern \entrypoint
1260ENTRY \name
1261 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001262 ldr w2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001263 mov x3, xSELF // pass Thread::Current
1264 mov x4, sp // pass SP
1265 bl \entrypoint
1266 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1267 \return
1268END \name
1269.endm
1270
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001271.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return
1272 .extern \entrypoint
1273ENTRY \name
1274 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
Andreas Gampecf4035a2014-05-28 22:43:01 -07001275 ldr w3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001276 mov x4, xSELF // pass Thread::Current
1277 mov x5, sp // pass SP
1278 bl \entrypoint
1279 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1280 \return
1281END \name
1282.endm
1283
Matteo Franchindfd891a2014-04-30 12:17:17 +01001284 /*
1285 * Entry from managed code when uninitialized static storage, this stub will run the class
1286 * initializer and deliver the exception on error. On success the static storage base is
1287 * returned.
1288 */
1289TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO
1290
Andreas Gampe6aac3552014-06-09 14:55:53 -07001291TWO_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO
1292TWO_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Matteo Franchindfd891a2014-04-30 12:17:17 +01001293
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001294ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1295ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1296ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1297
1298TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1299TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1300TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1
1301
1302TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1303TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1304
1305THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1306THREE_ARG_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1307THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER
1308
1309// This is separated out as the argument order is different.
1310 .extern artSet64StaticFromCode
1311ENTRY art_quick_set64_static
1312 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1313 mov x3, x1 // Store value
Andreas Gampecf4035a2014-05-28 22:43:01 -07001314 ldr w1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001315 mov x2, x3 // Put value param
1316 mov x3, xSELF // pass Thread::Current
1317 mov x4, sp // pass SP
1318 bl artSet64StaticFromCode
1319 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1320 RETURN_IF_W0_IS_ZERO_OR_DELIVER
1321END art_quick_set64_static
1322
Matteo Franchindfd891a2014-04-30 12:17:17 +01001323 /*
1324 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1325 * exception on error. On success the String is returned. x0 holds the referring method,
1326 * w1 holds the string index. The fast path check for hit in strings cache has already been
1327 * performed.
1328 */
1329TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe6e4e59c2014-05-05 20:11:02 -07001330
Stuart Monteithb95a5342014-03-12 13:32:32 +00001331// Generate the allocation entrypoints for each allocator.
1332GENERATE_ALL_ALLOC_ENTRYPOINTS
1333
Zheng Xu48241e72014-05-23 11:52:42 +08001334 /*
1335 * Called by managed code when the value in wSUSPEND has been decremented to 0.
1336 */
1337 .extern artTestSuspendFromCode
1338ENTRY art_quick_test_suspend
1339 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags
1340 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to SUSPEND_CHECK_INTERVAL
1341 cbnz w0, .Lneed_suspend // check flags == 0
1342 ret // return if flags == 0
1343.Lneed_suspend:
1344 mov x0, xSELF
1345 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1346 mov x1, sp
1347 bl artTestSuspendFromCode // (Thread*, SP)
1348 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
1349END art_quick_test_suspend
Stuart Monteithb95a5342014-03-12 13:32:32 +00001350
Stuart Monteithd5c78f42014-06-11 16:44:46 +01001351ENTRY art_quick_implicit_suspend
1352 mov x0, xSELF
1353 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl
1354 mov x1, sp
1355 bl artTestSuspendFromCode // (Thread*, SP)
1356 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
1357END art_quick_implicit_suspend
1358
Andreas Gampee62a07e2014-03-26 14:53:21 -07001359 /*
1360 * Called by managed code that is attempting to call a method on a proxy class. On entry
1361 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1362 * method agrees with a ref and args callee save frame.
1363 */
1364 .extern artQuickProxyInvokeHandler
1365ENTRY art_quick_proxy_invoke_handler
1366 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1367 str x0, [sp, #0] // place proxy method at bottom of frame
1368 mov x2, xSELF // pass Thread::Current
1369 mov x3, sp // pass SP
1370 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
Zheng Xub551fdc2014-07-25 11:49:42 +08001371 // Use xETR as xSELF might be scratched by native function above.
1372 ldr x2, [xETR, THREAD_EXCEPTION_OFFSET]
Andreas Gampee62a07e2014-03-26 14:53:21 -07001373 cbnz x2, .Lexception_in_proxy // success if no exception is pending
Andreas Gamped1e91672014-06-02 22:50:05 -07001374 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // Restore frame
1375 fmov d0, x0 // Store result in d0 in case it was float or double
Andreas Gampee62a07e2014-03-26 14:53:21 -07001376 ret // return on success
1377.Lexception_in_proxy:
1378 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1379 DELIVER_PENDING_EXCEPTION
1380END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001381
Andreas Gampe51f76352014-05-21 08:28:48 -07001382 /*
Zheng Xub551fdc2014-07-25 11:49:42 +08001383 * Called to resolve an imt conflict. xIP1 is a hidden argument that holds the target method's
Andreas Gampe51f76352014-05-21 08:28:48 -07001384 * dex method index.
1385 */
1386ENTRY art_quick_imt_conflict_trampoline
Andreas Gampecf4035a2014-05-28 22:43:01 -07001387 ldr w0, [sp, #0] // load caller Method*
Andreas Gampe51f76352014-05-21 08:28:48 -07001388 ldr w0, [x0, #METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods
1389 add x0, x0, #OBJECT_ARRAY_DATA_OFFSET // get starting address of data
Zheng Xub551fdc2014-07-25 11:49:42 +08001390 ldr w0, [x0, xIP1, lsl 2] // load the target method
Andreas Gampe51f76352014-05-21 08:28:48 -07001391 b art_quick_invoke_interface_trampoline
1392END art_quick_imt_conflict_trampoline
Stuart Monteithb95a5342014-03-12 13:32:32 +00001393
1394ENTRY art_quick_resolution_trampoline
1395 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1396 mov x2, xSELF
1397 mov x3, sp
1398 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Matteo Franchindfd891a2014-04-30 12:17:17 +01001399 cbz x0, 1f
Zheng Xub551fdc2014-07-25 11:49:42 +08001400 mov xIP0, x0 // Remember returned code pointer in xIP0.
Andreas Gampecf4035a2014-05-28 22:43:01 -07001401 ldr w0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001402 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
Zheng Xub551fdc2014-07-25 11:49:42 +08001403 br xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +000014041:
1405 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1406 DELIVER_PENDING_EXCEPTION
1407END art_quick_resolution_trampoline
1408
1409/*
1410 * Generic JNI frame layout:
1411 *
1412 * #-------------------#
1413 * | |
1414 * | caller method... |
1415 * #-------------------# <--- SP on entry
1416 * | Return X30/LR |
1417 * | X29/FP | callee save
1418 * | X28 | callee save
1419 * | X27 | callee save
1420 * | X26 | callee save
1421 * | X25 | callee save
1422 * | X24 | callee save
1423 * | X23 | callee save
1424 * | X22 | callee save
1425 * | X21 | callee save
1426 * | X20 | callee save
Stuart Monteithb95a5342014-03-12 13:32:32 +00001427 * | X7 | arg7
1428 * | X6 | arg6
1429 * | X5 | arg5
1430 * | X4 | arg4
1431 * | X3 | arg3
1432 * | X2 | arg2
1433 * | X1 | arg1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001434 * | D7 | float arg 8
1435 * | D6 | float arg 7
1436 * | D5 | float arg 6
1437 * | D4 | float arg 5
1438 * | D3 | float arg 4
1439 * | D2 | float arg 3
1440 * | D1 | float arg 2
1441 * | D0 | float arg 1
Andreas Gampecf4035a2014-05-28 22:43:01 -07001442 * | Method* | <- X0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001443 * #-------------------#
1444 * | local ref cookie | // 4B
Mathieu Chartier421c5372014-05-14 14:11:40 -07001445 * | handle scope size | // 4B
Stuart Monteithb95a5342014-03-12 13:32:32 +00001446 * #-------------------#
1447 * | JNI Call Stack |
1448 * #-------------------# <--- SP on native call
1449 * | |
1450 * | Stack for Regs | The trampoline assembly will pop these values
1451 * | | into registers for native call
1452 * #-------------------#
1453 * | Native code ptr |
1454 * #-------------------#
1455 * | Free scratch |
1456 * #-------------------#
1457 * | Ptr to (1) | <--- SP
1458 * #-------------------#
1459 */
1460 /*
1461 * Called to do a generic JNI down-call
1462 */
1463ENTRY art_quick_generic_jni_trampoline
1464 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
1465 str x0, [sp, #0] // Store native ArtMethod* to bottom of stack.
1466
1467 // Save SP , so we can have static CFI info.
1468 mov x28, sp
1469 .cfi_def_cfa_register x28
1470
1471 // This looks the same, but is different: this will be updated to point to the bottom
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001472 // of the frame when the handle scope is inserted.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001473 mov xFP, sp
1474
Zheng Xub551fdc2014-07-25 11:49:42 +08001475 mov xIP0, #5120
1476 sub sp, sp, xIP0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001477
1478 // prepare for artQuickGenericJniTrampoline call
1479 // (Thread*, SP)
1480 // x0 x1 <= C calling convention
1481 // xSELF xFP <= where they are
1482
1483 mov x0, xSELF // Thread*
1484 mov x1, xFP
1485 bl artQuickGenericJniTrampoline // (Thread*, sp)
1486
Andreas Gampec200a4a2014-06-16 18:39:09 -07001487 // The C call will have registered the complete save-frame on success.
1488 // The result of the call is:
1489 // x0: pointer to native code, 0 on error.
1490 // x1: pointer to the bottom of the used area of the alloca, can restore stack till there.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001491
Andreas Gampec200a4a2014-06-16 18:39:09 -07001492 // Check for error = 0.
1493 cbz x0, .Lentry_error
Stuart Monteithb95a5342014-03-12 13:32:32 +00001494
Andreas Gampec200a4a2014-06-16 18:39:09 -07001495 // Release part of the alloca.
1496 mov sp, x1
Stuart Monteithb95a5342014-03-12 13:32:32 +00001497
Andreas Gampec200a4a2014-06-16 18:39:09 -07001498 // Save the code pointer
1499 mov xIP0, x0
Stuart Monteithb95a5342014-03-12 13:32:32 +00001500
1501 // Load parameters from frame into registers.
1502 // TODO Check with artQuickGenericJniTrampoline.
1503 // Also, check again APPCS64 - the stack arguments are interleaved.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001504 ldp x0, x1, [sp]
1505 ldp x2, x3, [sp, #16]
1506 ldp x4, x5, [sp, #32]
1507 ldp x6, x7, [sp, #48]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001508
Andreas Gampec200a4a2014-06-16 18:39:09 -07001509 ldp d0, d1, [sp, #64]
1510 ldp d2, d3, [sp, #80]
1511 ldp d4, d5, [sp, #96]
1512 ldp d6, d7, [sp, #112]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001513
Andreas Gampec200a4a2014-06-16 18:39:09 -07001514 add sp, sp, #128
Stuart Monteithb95a5342014-03-12 13:32:32 +00001515
Zheng Xub551fdc2014-07-25 11:49:42 +08001516 blr xIP0 // native call.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001517
1518 // result sign extension is handled in C code
1519 // prepare for artQuickGenericJniEndTrampoline call
Andreas Gampec200a4a2014-06-16 18:39:09 -07001520 // (Thread*, result, result_f)
1521 // x0 x1 x2 <= C calling convention
1522 mov x1, x0 // Result (from saved)
Zheng Xub551fdc2014-07-25 11:49:42 +08001523 mov x0, xETR // Thread register, original xSELF might be scratched by native code.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001524 fmov x2, d0 // d0 will contain floating point result, but needs to go into x2
Stuart Monteithb95a5342014-03-12 13:32:32 +00001525
1526 bl artQuickGenericJniEndTrampoline
1527
1528 // Tear down the alloca.
1529 mov sp, x28
1530 .cfi_def_cfa_register sp
1531
Stuart Monteithb95a5342014-03-12 13:32:32 +00001532 // Pending exceptions possible.
Zheng Xub551fdc2014-07-25 11:49:42 +08001533 // Use xETR as xSELF might be scratched by native code
1534 ldr x1, [xETR, THREAD_EXCEPTION_OFFSET]
Stuart Monteithb95a5342014-03-12 13:32:32 +00001535 cbnz x1, .Lexception_in_native
1536
1537 // Tear down the callee-save frame.
1538 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1539
1540 // store into fpr, for when it's a fpr return...
1541 fmov d0, x0
1542 ret
1543
1544.Lentry_error:
1545 mov sp, x28
1546 .cfi_def_cfa_register sp
Stuart Monteithb95a5342014-03-12 13:32:32 +00001547.Lexception_in_native:
1548 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1549 DELIVER_PENDING_EXCEPTION
1550
1551END art_quick_generic_jni_trampoline
1552
1553/*
1554 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1555 * of a quick call:
1556 * x0 = method being called/to bridge to.
1557 * x1..x7, d0..d7 = arguments to that method.
1558 */
1559ENTRY art_quick_to_interpreter_bridge
1560 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
1561
1562 // x0 will contain mirror::ArtMethod* method.
1563 mov x1, xSELF // How to get Thread::Current() ???
1564 mov x2, sp
1565
1566 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1567 // mirror::ArtMethod** sp)
1568 bl artQuickToInterpreterBridge
1569
1570 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
1571
1572 fmov d0, x0
1573
1574 RETURN_OR_DELIVER_PENDING_EXCEPTION
1575END art_quick_to_interpreter_bridge
1576
Andreas Gamped58342c2014-06-05 14:18:08 -07001577
1578//
1579// Instrumentation-related stubs
1580//
1581 .extern artInstrumentationMethodEntryFromCode
1582ENTRY art_quick_instrumentation_entry
1583 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1584
Zheng Xub551fdc2014-07-25 11:49:42 +08001585 mov x20, x0 // Preserve method reference in a callee-save.
Andreas Gamped58342c2014-06-05 14:18:08 -07001586
1587 mov x2, xSELF
1588 mov x3, sp
1589 mov x4, xLR
1590 bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, SP, LR)
1591
Zheng Xub551fdc2014-07-25 11:49:42 +08001592 mov xIP0, x0 // x0 = result of call.
1593 mov x0, x20 // Reload method reference.
Andreas Gamped58342c2014-06-05 14:18:08 -07001594
1595 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // Note: will restore xSELF
1596 adr xLR, art_quick_instrumentation_exit
Zheng Xub551fdc2014-07-25 11:49:42 +08001597 br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit.
Andreas Gamped58342c2014-06-05 14:18:08 -07001598END art_quick_instrumentation_entry
1599
1600 .extern artInstrumentationMethodExitFromCode
1601ENTRY art_quick_instrumentation_exit
1602 mov xLR, #0 // Clobber LR for later checks.
1603
1604 SETUP_REF_ONLY_CALLEE_SAVE_FRAME
1605
1606 // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then
1607 // we would need to fully restore it. As there are a lot of callee-save registers, it seems
1608 // easier to have an extra small stack area.
1609
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001610 str x0, [sp, #-16]! // Save integer result.
Andreas Gamped58342c2014-06-05 14:18:08 -07001611 .cfi_adjust_cfa_offset 16
1612 str d0, [sp, #8] // Save floating-point result.
1613
Andreas Gamped58342c2014-06-05 14:18:08 -07001614 add x1, sp, #16 // Pass SP.
1615 mov x2, x0 // Pass integer result.
1616 fmov x3, d0 // Pass floating-point result.
Sebastien Hertz70f8d4b2014-06-19 11:51:41 +02001617 mov x0, xSELF // Pass Thread.
Andreas Gamped58342c2014-06-05 14:18:08 -07001618 bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res)
1619
Zheng Xub551fdc2014-07-25 11:49:42 +08001620 mov xIP0, x0 // Return address from instrumentation call.
Andreas Gamped58342c2014-06-05 14:18:08 -07001621 mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize
1622
1623 ldr d0, [sp, #8] // Restore floating-point result.
1624 ldr x0, [sp], 16 // Restore integer result, and drop stack area.
1625 .cfi_adjust_cfa_offset 16
1626
1627 POP_REF_ONLY_CALLEE_SAVE_FRAME
1628
Zheng Xub551fdc2014-07-25 11:49:42 +08001629 br xIP0 // Tail-call out.
Andreas Gamped58342c2014-06-05 14:18:08 -07001630END art_quick_instrumentation_exit
1631
1632 /*
1633 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1634 * will long jump to the upcall with a special exception of -1.
1635 */
1636 .extern artDeoptimize
1637ENTRY art_quick_deoptimize
1638 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1639 mov x0, xSELF // Pass thread.
1640 mov x1, sp // Pass SP.
1641 bl artDeoptimize // artDeoptimize(Thread*, SP)
Serban Constantinescu86797a72014-06-19 16:17:56 +01001642 brk 0
Andreas Gamped58342c2014-06-05 14:18:08 -07001643END art_quick_deoptimize
1644
1645
Serban Constantinescu169489b2014-06-11 16:43:35 +01001646 /*
1647 * String's indexOf.
1648 *
1649 * TODO: Not very optimized.
1650 * On entry:
1651 * x0: string object (known non-null)
1652 * w1: char to match (known <= 0xFFFF)
1653 * w2: Starting offset in string data
1654 */
1655ENTRY art_quick_indexof
1656 ldr w3, [x0, #STRING_COUNT_OFFSET]
1657 ldr w4, [x0, #STRING_OFFSET_OFFSET]
1658 ldr w0, [x0, #STRING_VALUE_OFFSET] // x0 ?
1659
1660 /* Clamp start to [0..count] */
1661 cmp w2, #0
1662 csel w2, wzr, w2, lt
1663 cmp w2, w3
1664 csel w2, w3, w2, gt
1665
1666 /* Build a pointer to the start of the string data */
1667 add x0, x0, #STRING_DATA_OFFSET
1668 add x0, x0, x4, lsl #1
1669
1670 /* Save a copy to compute result */
1671 mov x5, x0
1672
1673 /* Build pointer to start of data to compare and pre-bias */
1674 add x0, x0, x2, lsl #1
1675 sub x0, x0, #2
1676
1677 /* Compute iteration count */
1678 sub w2, w3, w2
1679
1680 /*
1681 * At this point we have:
1682 * x0: start of the data to test
1683 * w1: char to compare
1684 * w2: iteration count
1685 * x5: original start of string data
1686 */
1687
1688 subs w2, w2, #4
1689 b.lt .Lindexof_remainder
1690
1691.Lindexof_loop4:
1692 ldrh w6, [x0, #2]!
1693 ldrh w7, [x0, #2]!
Zheng Xub551fdc2014-07-25 11:49:42 +08001694 ldrh wIP0, [x0, #2]!
1695 ldrh wIP1, [x0, #2]!
Serban Constantinescu169489b2014-06-11 16:43:35 +01001696 cmp w6, w1
1697 b.eq .Lmatch_0
1698 cmp w7, w1
1699 b.eq .Lmatch_1
Zheng Xub551fdc2014-07-25 11:49:42 +08001700 cmp wIP0, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001701 b.eq .Lmatch_2
Zheng Xub551fdc2014-07-25 11:49:42 +08001702 cmp wIP1, w1
Serban Constantinescu169489b2014-06-11 16:43:35 +01001703 b.eq .Lmatch_3
1704 subs w2, w2, #4
1705 b.ge .Lindexof_loop4
1706
1707.Lindexof_remainder:
1708 adds w2, w2, #4
1709 b.eq .Lindexof_nomatch
1710
1711.Lindexof_loop1:
1712 ldrh w6, [x0, #2]!
1713 cmp w6, w1
1714 b.eq .Lmatch_3
1715 subs w2, w2, #1
1716 b.ne .Lindexof_loop1
1717
1718.Lindexof_nomatch:
1719 mov x0, #-1
1720 ret
1721
1722.Lmatch_0:
1723 sub x0, x0, #6
1724 sub x0, x0, x5
1725 asr x0, x0, #1
1726 ret
1727.Lmatch_1:
1728 sub x0, x0, #4
1729 sub x0, x0, x5
1730 asr x0, x0, #1
1731 ret
1732.Lmatch_2:
1733 sub x0, x0, #2
1734 sub x0, x0, x5
1735 asr x0, x0, #1
1736 ret
1737.Lmatch_3:
1738 sub x0, x0, x5
1739 asr x0, x0, #1
1740 ret
1741END art_quick_indexof
Andreas Gampe266340d2014-05-02 07:55:24 -07001742
1743 /*
1744 * String's compareTo.
1745 *
1746 * TODO: Not very optimized.
1747 *
1748 * On entry:
1749 * x0: this object pointer
1750 * x1: comp object pointer
1751 *
1752 */
Serban Constantinescu86797a72014-06-19 16:17:56 +01001753 .extern __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001754ENTRY art_quick_string_compareto
1755 mov x2, x0 // x0 is return, use x2 for first input.
1756 sub x0, x2, x1 // Same string object?
1757 cbnz x0,1f
1758 ret
17591: // Different string objects.
1760
1761 ldr w6, [x2, #STRING_OFFSET_OFFSET]
1762 ldr w5, [x1, #STRING_OFFSET_OFFSET]
1763 ldr w4, [x2, #STRING_COUNT_OFFSET]
1764 ldr w3, [x1, #STRING_COUNT_OFFSET]
1765 ldr w2, [x2, #STRING_VALUE_OFFSET]
1766 ldr w1, [x1, #STRING_VALUE_OFFSET]
1767
1768 /*
1769 * Now: CharArray* Offset Count
1770 * first arg x2 w6 w4
1771 * second arg x1 w5 w3
1772 */
1773
1774 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4.
1775 subs x0, x4, x3
1776 // Min(count1, count2) into w3.
1777 csel x3, x3, x4, ge
1778
1779 // Build pointer into string data.
1780
1781 // Add offset in array (substr etc.) (sign extend and << 1).
1782 add x2, x2, w6, sxtw #1
1783 add x1, x1, w5, sxtw #1
1784
1785 // Add offset in CharArray to array.
1786 add x2, x2, #STRING_DATA_OFFSET
1787 add x1, x1, #STRING_DATA_OFFSET
1788
Serban Constantinescu169489b2014-06-11 16:43:35 +01001789 // TODO: Tune this value.
Andreas Gampe266340d2014-05-02 07:55:24 -07001790 // Check for long string, do memcmp16 for them.
1791 cmp w3, #28 // Constant from arm32.
1792 bgt .Ldo_memcmp16
1793
1794 /*
1795 * Now:
1796 * x2: *first string data
1797 * x1: *second string data
1798 * w3: iteration count
1799 * x0: return value if comparison equal
1800 * x4, x5, x6, x7: free
1801 */
1802
1803 // Do a simple unrolled loop.
1804.Lloop:
1805 // At least two more elements?
1806 subs w3, w3, #2
1807 b.lt .Lremainder_or_done
1808
1809 ldrh w4, [x2], #2
1810 ldrh w5, [x1], #2
1811
1812 ldrh w6, [x2], #2
1813 ldrh w7, [x1], #2
1814
1815 subs w4, w4, w5
1816 b.ne .Lw4_result
1817
1818 subs w6, w6, w7
1819 b.ne .Lw6_result
1820
1821 b .Lloop
1822
1823.Lremainder_or_done:
1824 adds w3, w3, #1
1825 b.eq .Lremainder
1826 ret
1827
1828.Lremainder:
1829 ldrh w4, [x2], #2
1830 ldrh w5, [x1], #2
1831 subs w4, w4, w5
1832 b.ne .Lw4_result
1833 ret
1834
1835// Result is in w4
1836.Lw4_result:
1837 sxtw x0, w4
1838 ret
1839
1840// Result is in w6
1841.Lw6_result:
1842 sxtw x0, w6
1843 ret
1844
1845.Ldo_memcmp16:
Zheng Xu62ddb322014-08-12 17:19:12 +08001846 mov x14, x0 // Save x0 and LR. __memcmp16 does not use these temps.
1847 mov x15, xLR // TODO: Codify and check that?
Andreas Gampe266340d2014-05-02 07:55:24 -07001848
1849 mov x0, x2
1850 uxtw x2, w3
Serban Constantinescu86797a72014-06-19 16:17:56 +01001851 bl __memcmp16
Andreas Gampe266340d2014-05-02 07:55:24 -07001852
Zheng Xu62ddb322014-08-12 17:19:12 +08001853 mov xLR, x15 // Restore LR.
Andreas Gampe266340d2014-05-02 07:55:24 -07001854
Serban Constantinescu86797a72014-06-19 16:17:56 +01001855 cmp x0, #0 // Check the memcmp difference.
Zheng Xu62ddb322014-08-12 17:19:12 +08001856 csel x0, x0, x14, ne // x0 := x0 != 0 ? x14(prev x0=length diff) : x1.
Andreas Gampe266340d2014-05-02 07:55:24 -07001857 ret
1858END art_quick_string_compareto
Zheng Xu0210d112014-06-17 12:25:48 +08001859
1860// Macro to facilitate adding new entrypoints which call to native function directly.
1861// Currently, xSELF is the only thing we need to take care of between managed code and AAPCS.
1862// But we might introduce more differences.
1863.macro NATIVE_DOWNCALL name, entrypoint
1864 .extern \entrypoint
1865ENTRY \name
Serban Constantinescu86797a72014-06-19 16:17:56 +01001866 stp xSELF, xLR, [sp, #-16]!
Zheng Xu0210d112014-06-17 12:25:48 +08001867 bl \entrypoint
Serban Constantinescu86797a72014-06-19 16:17:56 +01001868 ldp xSELF, xLR, [sp], #16
Zheng Xu0210d112014-06-17 12:25:48 +08001869 ret
1870END \name
1871.endm
1872
1873NATIVE_DOWNCALL art_quick_fmod fmod
1874NATIVE_DOWNCALL art_quick_fmodf fmodf
1875NATIVE_DOWNCALL art_quick_memcpy memcpy
Serban Constantinescu86797a72014-06-19 16:17:56 +01001876NATIVE_DOWNCALL art_quick_assignable_from_code artIsAssignableFromCode