blob: 20830516d1aac219a2408c6c0f95b79ff486d5f7 [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
27 adrp x9, :got:_ZN3art7Runtime9instance_E
28 ldr x9, [x9, #:got_lo12:_ZN3art7Runtime9instance_E]
29
30 // Our registers aren't intermixed - just spill in order.
31 ldr x9,[x9] // x9 = & (art::Runtime * art::Runtime.instance_) .
32
33 // x9 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
34 ldr x9, [x9, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET ]
35
36 sub sp, sp, #368
37 .cfi_adjust_cfa_offset 368
38
Andreas Gampe5c1e4352014-04-21 19:28:24 -070039 // Ugly compile-time check, but we only have the preprocessor.
40#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 368)
41#error "SAVE_ALL_CALLEE_SAVE_FRAME(ARM64) size not as expected."
42#endif
43
Stuart Monteithb95a5342014-03-12 13:32:32 +000044 // FP args
45 stp d1, d2, [sp, #8]
46 stp d2, d3, [sp, #24]
47 stp d4, d5, [sp, #40]
48 stp d6, d7, [sp, #56]
49
50 // FP callee-saves
51 stp d8, d9, [sp, #72]
52 stp d10, d11, [sp, #88]
53 stp d12, d13, [sp, #104]
54 stp d14, d15, [sp, #120]
55
56 stp d16, d17, [sp, #136]
57 stp d18, d19, [sp, #152]
58 stp d20, d21, [sp, #168]
59 stp d22, d23, [sp, #184]
60 stp d24, d25, [sp, #200]
61 stp d26, d27, [sp, #216]
62 stp d28, d29, [sp, #232]
63 stp d30, d31, [sp, #248]
64
65
66 // Callee saved.
67 stp xSELF, x19, [sp, #264]
Andreas Gampe03906cf2014-04-07 12:08:28 -070068 .cfi_rel_offset x18, 264
69 .cfi_rel_offset x19, 272
Stuart Monteithb95a5342014-03-12 13:32:32 +000070
Andreas Gampe03906cf2014-04-07 12:08:28 -070071 stp x20, x21, [sp, #280]
72 .cfi_rel_offset x20, 280
73 .cfi_rel_offset x21, 288
74
75 stp x22, x23, [sp, #296]
76 .cfi_rel_offset x22, 296
77 .cfi_rel_offset x23, 304
78
79 stp x24, x25, [sp, #312]
80 .cfi_rel_offset x24, 312
81 .cfi_rel_offset x25, 320
82
83 stp x26, x27, [sp, #328]
84 .cfi_rel_offset x26, 328
85 .cfi_rel_offset x27, 336
86
87 stp x28, xFP, [sp, #344] // Save FP.
88 .cfi_rel_offset x28, 344
89 .cfi_rel_offset x29, 352
90
91 str xLR, [sp, #360]
92 .cfi_rel_offset x30, 360
Stuart Monteithb95a5342014-03-12 13:32:32 +000093
94 // Loads appropriate callee-save-method
95 str x9, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
96
97.endm
98
99 /*
100 * Macro that sets up the callee save frame to conform with
101 * Runtime::CreateCalleeSaveMethod(kRefsOnly).
102 */
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700103// WIP.
Stuart Monteithb95a5342014-03-12 13:32:32 +0000104.macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700105 adrp x9, :got:_ZN3art7Runtime9instance_E
106 ldr x9, [x9, #:got_lo12:_ZN3art7Runtime9instance_E]
107
108 // Our registers aren't intermixed - just spill in order.
109 ldr x9,[x9] // x9 = & (art::Runtime * art::Runtime.instance_) .
110
111 // x9 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
112 ldr x9, [x9, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET ]
113
114 sub sp, sp, #176
115 .cfi_adjust_cfa_offset 176
116
117 // Ugly compile-time check, but we only have the preprocessor.
118#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 176)
119#error "REFS_ONLY_CALLEE_SAVE_FRAME(ARM64) size not as expected."
120#endif
121
122 // FP callee-saves
123 stp d8, d9, [sp, #8]
124 stp d10, d11, [sp, #24]
125 stp d12, d13, [sp, #40]
126 stp d14, d15, [sp, #56]
127
128 // Callee saved.
129 stp xSELF, x19, [sp, #72]
130 .cfi_rel_offset x18, 72
131 .cfi_rel_offset x19, 80
132
133 stp x20, x21, [sp, #88]
134 .cfi_rel_offset x20, 88
135 .cfi_rel_offset x21, 96
136
137 stp x22, x23, [sp, #104]
138 .cfi_rel_offset x22, 104
139 .cfi_rel_offset x23, 112
140
141 stp x24, x25, [sp, #120]
142 .cfi_rel_offset x24, 120
143 .cfi_rel_offset x25, 128
144
145 stp x26, x27, [sp, #136]
146 .cfi_rel_offset x26, 136
147 .cfi_rel_offset x27, 144
148
149 stp x28, xFP, [sp, #152] // Save FP.
150 .cfi_rel_offset x28, 152
151 .cfi_rel_offset x29, 160
152
153 str xLR, [sp, #168]
154 .cfi_rel_offset x30, 168
155
156 // Loads appropriate callee-save-method
157 str x9, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
Stuart Monteithb95a5342014-03-12 13:32:32 +0000158.endm
159
160.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700161 // FP callee saves
162 ldp d8, d9, [sp, #8]
163 ldp d10, d11, [sp, #24]
164 ldp d12, d13, [sp, #40]
165 ldp d14, d15, [sp, #56]
166
167 // Callee saved.
168 ldp xSELF, x19, [sp, #72]
169 .cfi_restore x18
170 .cfi_restore x19
171
172 ldp x20, x21, [sp, #88]
173 .cfi_restore x20
174 .cfi_restore x21
175
176 ldp x22, x23, [sp, #104]
177 .cfi_restore x22
178 .cfi_restore x23
179
180 ldp x24, x25, [sp, #120]
181 .cfi_restore x24
182 .cfi_restore x25
183
184 ldp x26, x27, [sp, #136]
185 .cfi_restore x26
186 .cfi_restore x27
187
188 ldp x28, xFP, [sp, #152] // Save FP.
189 .cfi_restore x28
190 .cfi_restore x29
191
192 ldr xLR, [sp, #168]
193 .cfi_restore x30
194
195 add sp, sp, #176
196 .cfi_adjust_cfa_offset -176
Stuart Monteithb95a5342014-03-12 13:32:32 +0000197.endm
198
199.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
200 brk 0
201.endm
202
203
204.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
205 sub sp, sp, #304
206 .cfi_adjust_cfa_offset 304
207
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700208 // Ugly compile-time check, but we only have the preprocessor.
209#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 304)
210#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected."
211#endif
212
Stuart Monteithb95a5342014-03-12 13:32:32 +0000213 stp d0, d1, [sp, #16]
214 stp d2, d3, [sp, #32]
215 stp d4, d5, [sp, #48]
216 stp d6, d7, [sp, #64]
217 stp d8, d9, [sp, #80]
218 stp d10, d11, [sp, #96]
219 stp d12, d13, [sp, #112]
220 stp d14, d15, [sp, #128]
221
222 stp x1, x2, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700223 .cfi_rel_offset x1, 144
224 .cfi_rel_offset x2, 152
Stuart Monteithb95a5342014-03-12 13:32:32 +0000225
Andreas Gampe03906cf2014-04-07 12:08:28 -0700226 stp x3, x4, [sp, #160]
227 .cfi_rel_offset x3, 160
228 .cfi_rel_offset x4, 168
229
230 stp x5, x6, [sp, #176]
231 .cfi_rel_offset x5, 176
232 .cfi_rel_offset x6, 184
233
234 stp x7, xSELF, [sp, #192]
235 .cfi_rel_offset x7, 192
236 .cfi_rel_offset x18, 200
237
238 stp x19, x20, [sp, #208]
239 .cfi_rel_offset x19, 208
240 .cfi_rel_offset x20, 216
241
242 stp x21, x22, [sp, #224]
243 .cfi_rel_offset x21, 224
244 .cfi_rel_offset x22, 232
245
246 stp x23, x24, [sp, #240]
247 .cfi_rel_offset x23, 240
248 .cfi_rel_offset x24, 248
249
250 stp x25, x26, [sp, #256]
251 .cfi_rel_offset x25, 256
252 .cfi_rel_offset x26, 264
253
254 stp x27, x28, [sp, #272]
255 .cfi_rel_offset x27, 272
256 .cfi_rel_offset x28, 280
257
258 stp xFP, xLR, [sp, #288]
259 .cfi_rel_offset x29, 288
260 .cfi_rel_offset x30, 296
Stuart Monteithb95a5342014-03-12 13:32:32 +0000261.endm
262
263 /*
264 * Macro that sets up the callee save frame to conform with
265 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
266 *
267 * TODO This is probably too conservative - saving FP & LR.
268 */
269.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
270 adrp x9, :got:_ZN3art7Runtime9instance_E
271 ldr x9, [x9, #:got_lo12:_ZN3art7Runtime9instance_E]
272
273 // Our registers aren't intermixed - just spill in order.
274 ldr x9,[x9] // x9 = & (art::Runtime * art::Runtime.instance_) .
275
276 // x9 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] .
277 ldr x9, [x9, RUNTIME_REF_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ]
278
279 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
280
281 str x9, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs]
282.endm
283
284.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
285
286 ldp d0, d1, [sp, #16]
287 ldp d2, d3, [sp, #32]
288 ldp d4, d5, [sp, #48]
289 ldp d6, d7, [sp, #64]
290 ldp d8, d9, [sp, #80]
291 ldp d10, d11, [sp, #96]
292 ldp d12, d13, [sp, #112]
293 ldp d14, d15, [sp, #128]
294
295 // args.
296 ldp x1, x2, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700297 .cfi_restore x1
298 .cfi_restore x2
299
Stuart Monteithb95a5342014-03-12 13:32:32 +0000300 ldp x3, x4, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700301 .cfi_restore x3
302 .cfi_restore x4
303
Stuart Monteithb95a5342014-03-12 13:32:32 +0000304 ldp x5, x6, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700305 .cfi_restore x5
306 .cfi_restore x6
307
Stuart Monteithb95a5342014-03-12 13:32:32 +0000308 ldp x7, xSELF, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700309 .cfi_restore x7
310 .cfi_restore x18
311
Stuart Monteithb95a5342014-03-12 13:32:32 +0000312 ldp x19, x20, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700313 .cfi_restore x19
314 .cfi_restore x20
315
Stuart Monteithb95a5342014-03-12 13:32:32 +0000316 ldp x21, x22, [sp, #224]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700317 .cfi_restore x21
318 .cfi_restore x22
319
Stuart Monteithb95a5342014-03-12 13:32:32 +0000320 ldp x23, x24, [sp, #240]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700321 .cfi_restore x23
322 .cfi_restore x24
323
Stuart Monteithb95a5342014-03-12 13:32:32 +0000324 ldp x25, x26, [sp, #256]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700325 .cfi_restore x25
326 .cfi_restore x26
327
Stuart Monteithb95a5342014-03-12 13:32:32 +0000328 ldp x27, x28, [sp, #272]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700329 .cfi_restore x27
330 .cfi_restore x28
331
Stuart Monteithb95a5342014-03-12 13:32:32 +0000332 ldp xFP, xLR, [sp, #288]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700333 .cfi_restore x29
334 .cfi_restore x30
Stuart Monteithb95a5342014-03-12 13:32:32 +0000335
336 add sp, sp, #304
337 .cfi_adjust_cfa_offset -304
338.endm
339
Andreas Gampee62a07e2014-03-26 14:53:21 -0700340.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME_NO_D0
341
342 ldr d1, [sp, #24]
343 ldp d2, d3, [sp, #32]
344 ldp d4, d5, [sp, #48]
345 ldp d6, d7, [sp, #64]
346 ldp d8, d9, [sp, #80]
347 ldp d10, d11, [sp, #96]
348 ldp d12, d13, [sp, #112]
349 ldp d14, d15, [sp, #128]
350
351 // args.
352 ldp x1, x2, [sp, #144]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700353 .cfi_restore x1
354 .cfi_restore x2
355
Andreas Gampee62a07e2014-03-26 14:53:21 -0700356 ldp x3, x4, [sp, #160]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700357 .cfi_restore x3
358 .cfi_restore x4
359
Andreas Gampee62a07e2014-03-26 14:53:21 -0700360 ldp x5, x6, [sp, #176]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700361 .cfi_restore x5
362 .cfi_restore x6
363
Andreas Gampee62a07e2014-03-26 14:53:21 -0700364 ldp x7, xSELF, [sp, #192]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700365 .cfi_restore x7
366 .cfi_restore x18
367
Andreas Gampee62a07e2014-03-26 14:53:21 -0700368 ldp x19, x20, [sp, #208]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700369 .cfi_restore x19
370 .cfi_restore x20
371
Andreas Gampee62a07e2014-03-26 14:53:21 -0700372 ldp x21, x22, [sp, #224]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700373 .cfi_restore x21
374 .cfi_restore x22
375
Andreas Gampee62a07e2014-03-26 14:53:21 -0700376 ldp x23, x24, [sp, #240]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700377 .cfi_restore x23
378 .cfi_restore x24
379
Andreas Gampee62a07e2014-03-26 14:53:21 -0700380 ldp x25, x26, [sp, #256]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700381 .cfi_restore x25
382 .cfi_restore x26
383
Andreas Gampee62a07e2014-03-26 14:53:21 -0700384 ldp x27, x28, [sp, #272]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700385 .cfi_restore x27
386 .cfi_restore x28
387
Andreas Gampee62a07e2014-03-26 14:53:21 -0700388 ldp xFP, xLR, [sp, #288]
Andreas Gampe03906cf2014-04-07 12:08:28 -0700389 .cfi_restore x29
390 .cfi_restore x30
Andreas Gampee62a07e2014-03-26 14:53:21 -0700391
392 add sp, sp, #304
393 .cfi_adjust_cfa_offset -304
394.endm
395
Stuart Monteithb95a5342014-03-12 13:32:32 +0000396.macro RETURN_IF_RESULT_IS_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700397 cbnz x0, 1f // result non-zero branch over
398 ret // return
3991:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000400.endm
401
402.macro RETURN_IF_RESULT_IS_NON_ZERO
Andreas Gampe00c1e6d2014-04-25 15:47:13 -0700403 cbz x0, 1f // result zero branch over
404 ret // return
4051:
Stuart Monteithb95a5342014-03-12 13:32:32 +0000406.endm
407
408 /*
409 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
410 * exception is Thread::Current()->exception_
411 */
412.macro DELIVER_PENDING_EXCEPTION
413 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
414 mov x0, xSELF
415 mov x1, sp
416
417 // Point of no return.
418 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*, SP)
419 brk 0 // Unreached
420.endm
421
422.macro RETURN_OR_DELIVER_PENDING_EXCEPTION
423 ldr x9, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field.
424 cbnz x9, 1f
425 ret
4261:
427 DELIVER_PENDING_EXCEPTION
428.endm
429
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700430// FIXME: Temporary fix for TR(XSELF).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000431.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
432 .extern \cxx_name
433ENTRY \c_name
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700434 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
435 mov x0, x19 // pass Thread::Current
436 mov x1, sp // pass SP
437 b \cxx_name // \cxx_name(Thread*, SP)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000438END \c_name
439.endm
440
Serban Constantinescu75b91132014-04-09 18:39:10 +0100441// FIXME: Temporary fix for TR(XSELF).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000442.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name
443 .extern \cxx_name
444ENTRY \c_name
Serban Constantinescu75b91132014-04-09 18:39:10 +0100445 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context.
446 mov x1, x19 // pass Thread::Current.
447 mov x2, sp // pass SP.
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700448 b \cxx_name // \cxx_name(arg, Thread*, SP).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000449 brk 0
450END \c_name
451.endm
452
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700453// FIXME: Temporary fix for TR(XSELF).
Stuart Monteithb95a5342014-03-12 13:32:32 +0000454.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name
455 .extern \cxx_name
456ENTRY \c_name
457 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700458 mov x2, x19 // pass Thread::Current
459 mov x3, sp // pass SP
460 b \cxx_name // \cxx_name(arg1, arg2, Thread*, SP)
Stuart Monteithb95a5342014-03-12 13:32:32 +0000461 brk 0
462END \c_name
463.endm
464
465 /*
466 * Called by managed code, saves callee saves and then calls artThrowException
467 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception.
468 */
469ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode
470
471 /*
472 * Called by managed code to create and deliver a NullPointerException.
473 */
474NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode
475
476 /*
477 * Called by managed code to create and deliver an ArithmeticException.
478 */
479NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode
480
481 /*
482 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds
483 * index, arg2 holds limit.
484 */
485TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode
486
487 /*
488 * Called by managed code to create and deliver a StackOverflowError.
489 */
490NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode
491
492 /*
493 * Called by managed code to create and deliver a NoSuchMethodError.
494 */
495ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode
496
497 /*
498 * TODO arm64 specifics need to be fleshed out.
499 * All generated callsites for interface invokes and invocation slow paths will load arguments
500 * as usual - except instead of loading x0 with the target Method*, x0 will contain
501 * the method_idx. This wrapper will save x1-x3, load the caller's Method*, align the
502 * stack and call the appropriate C helper.
503 * NOTE: "this" is first visible argument of the target, and so can be found in x1.
504 *
505 * The helper will attempt to locate the target and return a result in x0 consisting
506 * of the target Method* in x0 and method->code_ in x1.
507 *
508 * If unsuccessful, the helper will return NULL/NULL. There will be a pending exception in the
509 * thread and we branch to another stub to deliver it.
510 *
511 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
512 * pointing back to the original caller.
513 */
514.macro INVOKE_TRAMPOLINE c_name, cxx_name
515 .extern \cxx_name
516ENTRY \c_name
517 brk 0
518END \c_name
519.endm
520
521INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline
522INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
523
524INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
525INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
526INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
527INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
528
Andreas Gampe03906cf2014-04-07 12:08:28 -0700529
530.macro INVOKE_STUB_CREATE_FRAME
531
532SAVE_SIZE=5*8 // x4, x5, SP, LR & FP saved.
533SAVE_SIZE_AND_METHOD=SAVE_SIZE+8
534
535 mov x9, sp // Save stack pointer.
536 .cfi_register sp,x9
537
538 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame.
539 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args
540 and x10, x10, # ~0xf // Enforce 16 byte stack alignment.
541 mov sp, x10 // Set new SP.
542
543 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP
544 .cfi_def_cfa_register x10 // before this.
545 .cfi_adjust_cfa_offset SAVE_SIZE
546
547 str x9, [x10, #32] // Save old stack pointer.
548 .cfi_rel_offset sp, 32
549
550 stp x4, x5, [x10, #16] // Save result and shorty addresses.
551 .cfi_rel_offset x4, 16
552 .cfi_rel_offset x5, 24
553
554 stp xFP, xLR, [x10] // Store LR & FP.
555 .cfi_rel_offset x29, 0
556 .cfi_rel_offset x30, 8
557
558 mov xFP, x10 // Use xFP now, as it's callee-saved.
559 .cfi_def_cfa_register x29
560 mov xSELF, x3 // Move thread pointer into SELF register.
561
562 // Copy arguments into stack frame.
563 // Use simple copy routine for now.
564 // 4 bytes per slot.
565 // X1 - source address
566 // W2 - args length
567 // X9 - destination address.
568 // W10 - temporary
569 add x9, sp, #8 // Destination address is bottom of stack + NULL.
570
571 // Use \@ to differentiate between macro invocations.
572.LcopyParams\@:
573 cmp w2, #0
574 beq .LendCopyParams\@
575 sub w2, w2, #4 // Need 65536 bytes of range.
576 ldr w10, [x1, x2]
577 str w10, [x9, x2]
578
579 b .LcopyParams\@
580
581.LendCopyParams\@:
582
583 // Store NULL into Method* at bottom of frame.
584 str xzr, [sp]
585
586.endm
587
588.macro INVOKE_STUB_CALL_AND_RETURN
589
590 // load method-> METHOD_QUICK_CODE_OFFSET
591 ldr x9, [x0 , #METHOD_QUICK_CODE_OFFSET]
592 // 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
600 // Store result (w0/x0/s0/d0) appropriately, depending on resultType.
601 ldrb w10, [x5]
602
603 // Don't set anything for a void type.
604 cmp w10, #'V'
605 beq .Lexit_art_quick_invoke_stub\@
606
607 cmp w10, #'D'
608 bne .Lreturn_is_float\@
609 str d0, [x4]
610 b .Lexit_art_quick_invoke_stub\@
611
612.Lreturn_is_float\@:
613 cmp w10, #'F'
614 bne .Lreturn_is_int\@
615 str s0, [x4]
616 b .Lexit_art_quick_invoke_stub\@
617
618 // Just store x0. Doesn't matter if it is 64 or 32 bits.
619.Lreturn_is_int\@:
620 str x0, [x4]
621
622.Lexit_art_quick_invoke_stub\@:
623 ldr x2, [x29, #32] // Restore stack pointer.
624 mov sp, x2
625 .cfi_restore sp
626
627 ldp x29, x30, [x29] // Restore old frame pointer and link register.
628 .cfi_restore x29
629 .cfi_restore x30
630
631 ret
632
633.endm
634
635
Stuart Monteithb95a5342014-03-12 13:32:32 +0000636/*
637 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0
638 * uint32_t *args, x1
639 * uint32_t argsize, w2
640 * Thread *self, x3
641 * JValue *result, x4
642 * char *shorty); x5
643 * +----------------------+
644 * | |
645 * | C/C++ frame |
646 * | LR'' |
647 * | FP'' | <- SP'
648 * +----------------------+
649 * +----------------------+
650 * | SP' |
651 * | X5 |
652 * | X4 | Saved registers
653 * | LR' |
654 * | FP' | <- FP
655 * +----------------------+
656 * | uint32_t out[n-1] |
657 * | : : | Outs
658 * | uint32_t out[0] |
659 * | ArtMethod* NULL | <- SP
660 * +----------------------+
661 *
662 * Outgoing registers:
663 * x0 - Method*
664 * x1-x7 - integer parameters.
665 * d0-d7 - Floating point parameters.
666 * xSELF = self
667 * SP = & of ArtMethod*
668 * x1 = "this" pointer.
669 *
670 */
671ENTRY art_quick_invoke_stub
672 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700673 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000674
675 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
676 // Parse the passed shorty to determine which register to load.
677 // Load addresses for routines that load WXSD registers.
678 adr x11, .LstoreW2
679 adr x12, .LstoreX2
680 adr x13, .LstoreS0
681 adr x14, .LstoreD0
682
683 // Initialize routine offsets to 0 for integers and floats.
684 // x8 for integers, x15 for floating point.
685 mov x8, #0
686 mov x15, #0
687
688 add x10, x5, #1 // Load shorty address, plus one to skip return value.
689 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer.
690
691 // Loop to fill registers.
692.LfillRegisters:
693 ldrb w17, [x10], #1 // Load next character in signature, and increment.
694 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated.
695
696 cmp w17, #'F' // is this a float?
697 bne .LisDouble
698
699 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700700 beq .Ladvance4
Stuart Monteithb95a5342014-03-12 13:32:32 +0000701
702 add x17, x13, x15 // Calculate subroutine to jump to.
703 br x17
704
705.LisDouble:
706 cmp w17, #'D' // is this a double?
707 bne .LisLong
708
709 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700710 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000711
712 add x17, x14, x15 // Calculate subroutine to jump to.
713 br x17
714
715.LisLong:
716 cmp w17, #'J' // is this a long?
717 bne .LisOther
718
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700719 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700720 beq .Ladvance8
Stuart Monteithb95a5342014-03-12 13:32:32 +0000721
722 add x17, x12, x8 // Calculate subroutine to jump to.
723 br x17
724
Stuart Monteithb95a5342014-03-12 13:32:32 +0000725.LisOther: // Everything else takes one vReg.
Andreas Gampe9de65ff2014-03-21 17:25:57 -0700726 cmp x8, # 6*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700727 beq .Ladvance4
728
Stuart Monteithb95a5342014-03-12 13:32:32 +0000729 add x17, x11, x8 // Calculate subroutine to jump to.
730 br x17
731
Andreas Gampe03906cf2014-04-07 12:08:28 -0700732.Ladvance4:
733 add x9, x9, #4
734 b .LfillRegisters
735
736.Ladvance8:
737 add x9, x9, #8
738 b .LfillRegisters
739
Stuart Monteithb95a5342014-03-12 13:32:32 +0000740// Macro for loading a parameter into a register.
741// counter - the register with offset into these tables
742// size - the size of the register - 4 or 8 bytes.
743// register - the name of the register to be loaded.
744.macro LOADREG counter size register return
745 ldr \register , [x9], #\size
746 add \counter, \counter, 12
747 b \return
748.endm
749
750// Store ints.
751.LstoreW2:
752 LOADREG x8 4 w2 .LfillRegisters
753 LOADREG x8 4 w3 .LfillRegisters
754 LOADREG x8 4 w4 .LfillRegisters
755 LOADREG x8 4 w5 .LfillRegisters
756 LOADREG x8 4 w6 .LfillRegisters
757 LOADREG x8 4 w7 .LfillRegisters
758
759// Store longs.
760.LstoreX2:
761 LOADREG x8 8 x2 .LfillRegisters
762 LOADREG x8 8 x3 .LfillRegisters
763 LOADREG x8 8 x4 .LfillRegisters
764 LOADREG x8 8 x5 .LfillRegisters
765 LOADREG x8 8 x6 .LfillRegisters
766 LOADREG x8 8 x7 .LfillRegisters
767
768// Store singles.
769.LstoreS0:
770 LOADREG x15 4 s0 .LfillRegisters
771 LOADREG x15 4 s1 .LfillRegisters
772 LOADREG x15 4 s2 .LfillRegisters
773 LOADREG x15 4 s3 .LfillRegisters
774 LOADREG x15 4 s4 .LfillRegisters
775 LOADREG x15 4 s5 .LfillRegisters
776 LOADREG x15 4 s6 .LfillRegisters
777 LOADREG x15 4 s7 .LfillRegisters
778
779// Store doubles.
780.LstoreD0:
781 LOADREG x15 8 d0 .LfillRegisters
782 LOADREG x15 8 d1 .LfillRegisters
783 LOADREG x15 8 d2 .LfillRegisters
784 LOADREG x15 8 d3 .LfillRegisters
785 LOADREG x15 8 d4 .LfillRegisters
786 LOADREG x15 8 d5 .LfillRegisters
787 LOADREG x15 8 d6 .LfillRegisters
788 LOADREG x15 8 d7 .LfillRegisters
789
790
791.LcallFunction:
792
Andreas Gampe03906cf2014-04-07 12:08:28 -0700793 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000794
Stuart Monteithb95a5342014-03-12 13:32:32 +0000795END art_quick_invoke_stub
796
797/* extern"C"
798 * void art_quick_invoke_static_stub(ArtMethod *method, x0
799 * uint32_t *args, x1
800 * uint32_t argsize, w2
801 * Thread *self, x3
802 * JValue *result, x4
803 * char *shorty); x5
804 */
805ENTRY art_quick_invoke_static_stub
806 // Spill registers as per AACPS64 calling convention.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700807 INVOKE_STUB_CREATE_FRAME
Stuart Monteithb95a5342014-03-12 13:32:32 +0000808
809 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters.
810 // Parse the passed shorty to determine which register to load.
811 // Load addresses for routines that load WXSD registers.
812 adr x11, .LstoreW1_2
813 adr x12, .LstoreX1_2
814 adr x13, .LstoreS0_2
815 adr x14, .LstoreD0_2
816
817 // Initialize routine offsets to 0 for integers and floats.
818 // x8 for integers, x15 for floating point.
819 mov x8, #0
820 mov x15, #0
821
822 add x10, x5, #1 // Load shorty address, plus one to skip return value.
823
824 // Loop to fill registers.
825.LfillRegisters2:
826 ldrb w17, [x10], #1 // Load next character in signature, and increment.
827 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated.
828
829 cmp w17, #'F' // is this a float?
830 bne .LisDouble2
831
832 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700833 beq .Ladvance4_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000834
835 add x17, x13, x15 // Calculate subroutine to jump to.
836 br x17
837
838.LisDouble2:
839 cmp w17, #'D' // is this a double?
840 bne .LisLong2
841
842 cmp x15, # 8*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700843 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000844
845 add x17, x14, x15 // Calculate subroutine to jump to.
846 br x17
847
848.LisLong2:
849 cmp w17, #'J' // is this a long?
850 bne .LisOther2
851
852 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700853 beq .Ladvance8_2
Stuart Monteithb95a5342014-03-12 13:32:32 +0000854
855 add x17, x12, x8 // Calculate subroutine to jump to.
856 br x17
857
Stuart Monteithb95a5342014-03-12 13:32:32 +0000858.LisOther2: // Everything else takes one vReg.
859 cmp x8, # 7*12 // Skip this load if all registers full.
Andreas Gampe03906cf2014-04-07 12:08:28 -0700860 beq .Ladvance4_2
861
Stuart Monteithb95a5342014-03-12 13:32:32 +0000862 add x17, x11, x8 // Calculate subroutine to jump to.
863 br x17
864
Andreas Gampe03906cf2014-04-07 12:08:28 -0700865.Ladvance4_2:
866 add x9, x9, #4
867 b .LfillRegisters2
868
869.Ladvance8_2:
870 add x9, x9, #8
871 b .LfillRegisters2
872
Stuart Monteithb95a5342014-03-12 13:32:32 +0000873// Store ints.
874.LstoreW1_2:
875 LOADREG x8 4 w1 .LfillRegisters2
876 LOADREG x8 4 w2 .LfillRegisters2
877 LOADREG x8 4 w3 .LfillRegisters2
878 LOADREG x8 4 w4 .LfillRegisters2
879 LOADREG x8 4 w5 .LfillRegisters2
880 LOADREG x8 4 w6 .LfillRegisters2
881 LOADREG x8 4 w7 .LfillRegisters2
882
883// Store longs.
884.LstoreX1_2:
885 LOADREG x8 8 x1 .LfillRegisters2
886 LOADREG x8 8 x2 .LfillRegisters2
887 LOADREG x8 8 x3 .LfillRegisters2
888 LOADREG x8 8 x4 .LfillRegisters2
889 LOADREG x8 8 x5 .LfillRegisters2
890 LOADREG x8 8 x6 .LfillRegisters2
891 LOADREG x8 8 x7 .LfillRegisters2
892
893// Store singles.
894.LstoreS0_2:
895 LOADREG x15 4 s0 .LfillRegisters2
896 LOADREG x15 4 s1 .LfillRegisters2
897 LOADREG x15 4 s2 .LfillRegisters2
898 LOADREG x15 4 s3 .LfillRegisters2
899 LOADREG x15 4 s4 .LfillRegisters2
900 LOADREG x15 4 s5 .LfillRegisters2
901 LOADREG x15 4 s6 .LfillRegisters2
902 LOADREG x15 4 s7 .LfillRegisters2
903
904// Store doubles.
905.LstoreD0_2:
906 LOADREG x15 8 d0 .LfillRegisters2
907 LOADREG x15 8 d1 .LfillRegisters2
908 LOADREG x15 8 d2 .LfillRegisters2
909 LOADREG x15 8 d3 .LfillRegisters2
910 LOADREG x15 8 d4 .LfillRegisters2
911 LOADREG x15 8 d5 .LfillRegisters2
912 LOADREG x15 8 d6 .LfillRegisters2
913 LOADREG x15 8 d7 .LfillRegisters2
914
915
916.LcallFunction2:
917
Andreas Gampe03906cf2014-04-07 12:08:28 -0700918 INVOKE_STUB_CALL_AND_RETURN
Stuart Monteithb95a5342014-03-12 13:32:32 +0000919
Stuart Monteithb95a5342014-03-12 13:32:32 +0000920END art_quick_invoke_static_stub
921
Andreas Gampe03906cf2014-04-07 12:08:28 -0700922
Stuart Monteithb95a5342014-03-12 13:32:32 +0000923
924 /*
925 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_
926 */
927
928ENTRY art_quick_do_long_jump
929 // Load FPRs
930 ldp d0, d1, [x1], #16
931 ldp d2, d3, [x1], #16
932 ldp d4, d5, [x1], #16
933 ldp d6, d7, [x1], #16
934 ldp d8, d9, [x1], #16
935 ldp d10, d11, [x1], #16
936 ldp d12, d13, [x1], #16
937 ldp d14, d15, [x1], #16
938 ldp d16, d17, [x1], #16
939 ldp d18, d19, [x1], #16
940 ldp d20, d21, [x1], #16
941 ldp d22, d23, [x1], #16
942 ldp d24, d25, [x1], #16
943 ldp d26, d27, [x1], #16
944 ldp d28, d29, [x1], #16
945 ldp d30, d31, [x1]
946
947 // Load GPRs
948 // TODO: lots of those are smashed, could optimize.
949 add x0, x0, #30*8
950 ldp x30, x1, [x0], #-16
951 ldp x28, x29, [x0], #-16
952 ldp x26, x27, [x0], #-16
953 ldp x24, x25, [x0], #-16
954 ldp x22, x23, [x0], #-16
955 ldp x20, x21, [x0], #-16
956 ldp x18, x19, [x0], #-16
957 ldp x16, x17, [x0], #-16
958 ldp x14, x15, [x0], #-16
959 ldp x12, x13, [x0], #-16
960 ldp x10, x11, [x0], #-16
961 ldp x8, x9, [x0], #-16
962 ldp x6, x7, [x0], #-16
963 ldp x4, x5, [x0], #-16
964 ldp x2, x3, [x0], #-16
965 mov sp, x1
966
967 // TODO: Is it really OK to use LR for the target PC?
968 mov x0, #0
969 mov x1, #0
970 br xLR
971END art_quick_do_long_jump
972
973UNIMPLEMENTED art_quick_handle_fill_data
974
975UNIMPLEMENTED art_quick_lock_object
976UNIMPLEMENTED art_quick_unlock_object
Andreas Gampe525cde22014-04-22 15:44:50 -0700977
978 /*
979 * Entry from managed code that calls artIsAssignableFromCode and on failure calls
980 * artThrowClassCastException.
981 */
982 .extern artThrowClassCastException
983ENTRY art_quick_check_cast
984 // Store arguments and link register
985 sub sp, sp, #32 // Stack needs to be 16b aligned on calls
986 .cfi_adjust_cfa_offset 32
987 stp x0, x1, [sp]
988 .cfi_rel_offset x0, 0
989 .cfi_rel_offset x1, 8
990 stp xSELF, xLR, [sp, #16]
991 .cfi_rel_offset x18, 16
992 .cfi_rel_offset x30, 24
993
994 // Call runtime code
995 bl artIsAssignableFromCode
996
997 // Check for exception
998 cbz x0, .Lthrow_class_cast_exception
999
1000 // Restore and return
1001 ldp x0, x1, [sp]
1002 .cfi_restore x0
1003 .cfi_restore x1
1004 ldp xSELF, xLR, [sp, #16]
1005 .cfi_restore x18
1006 .cfi_restore x30
1007 add sp, sp, #32
1008 .cfi_adjust_cfa_offset -32
1009 ret
1010
1011.Lthrow_class_cast_exception:
1012 // Restore
1013 ldp x0, x1, [sp]
1014 .cfi_restore x0
1015 .cfi_restore x1
1016 ldp xSELF, xLR, [sp, #16]
1017 .cfi_restore x18
1018 .cfi_restore x30
1019 add sp, sp, #32
1020 .cfi_adjust_cfa_offset -32
1021
1022 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context
1023 mov x2, xSELF // pass Thread::Current
1024 mov x3, sp // pass SP
1025 b artThrowClassCastException // (Class*, Class*, Thread*, SP)
1026 brk 0 // We should not return here...
1027END art_quick_check_cast
1028
Stuart Monteithb95a5342014-03-12 13:32:32 +00001029UNIMPLEMENTED art_quick_aput_obj_with_null_and_bound_check
1030UNIMPLEMENTED art_quick_aput_obj_with_bound_check
1031UNIMPLEMENTED art_quick_aput_obj
1032UNIMPLEMENTED art_quick_initialize_static_storage
1033UNIMPLEMENTED art_quick_initialize_type
1034UNIMPLEMENTED art_quick_initialize_type_and_verify_access
1035UNIMPLEMENTED art_quick_get32_static
1036UNIMPLEMENTED art_quick_get64_static
1037UNIMPLEMENTED art_quick_get_obj_static
1038UNIMPLEMENTED art_quick_get32_instance
1039UNIMPLEMENTED art_quick_get64_instance
1040UNIMPLEMENTED art_quick_get_obj_instance
1041UNIMPLEMENTED art_quick_set32_static
1042UNIMPLEMENTED art_quick_set64_static
1043UNIMPLEMENTED art_quick_set_obj_static
1044UNIMPLEMENTED art_quick_set32_instance
1045UNIMPLEMENTED art_quick_set64_instance
1046UNIMPLEMENTED art_quick_set_obj_instance
1047UNIMPLEMENTED art_quick_resolve_string
1048
1049// Macro to facilitate adding new allocation entrypoints.
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001050// TODO: xSELF -> x19. Temporarily rely on xSELF being saved in REF_ONLY
Stuart Monteithb95a5342014-03-12 13:32:32 +00001051.macro TWO_ARG_DOWNCALL name, entrypoint, return
1052 .extern \entrypoint
1053ENTRY \name
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001054 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1055 mov x2, xSELF // pass Thread::Current
1056 mov x3, sp // pass SP
1057 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP)
1058 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1059 \return
1060 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001061END \name
1062.endm
1063
1064// Macro to facilitate adding new array allocation entrypoints.
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001065// TODO: xSELF -> x19. Temporarily rely on xSELF being saved in REF_ONLY
Stuart Monteithb95a5342014-03-12 13:32:32 +00001066.macro THREE_ARG_DOWNCALL name, entrypoint, return
1067 .extern \entrypoint
1068ENTRY \name
Andreas Gampe00c1e6d2014-04-25 15:47:13 -07001069 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC
1070 mov x3, xSELF // pass Thread::Current
1071 mov x4, sp // pass SP
1072 bl \entrypoint
1073 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
1074 \return
1075 DELIVER_PENDING_EXCEPTION
Stuart Monteithb95a5342014-03-12 13:32:32 +00001076END \name
1077.endm
1078
1079// Generate the allocation entrypoints for each allocator.
1080GENERATE_ALL_ALLOC_ENTRYPOINTS
1081
1082UNIMPLEMENTED art_quick_test_suspend
1083
Andreas Gampee62a07e2014-03-26 14:53:21 -07001084 /*
1085 * Called by managed code that is attempting to call a method on a proxy class. On entry
1086 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy
1087 * method agrees with a ref and args callee save frame.
1088 */
1089 .extern artQuickProxyInvokeHandler
1090ENTRY art_quick_proxy_invoke_handler
1091 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
1092 str x0, [sp, #0] // place proxy method at bottom of frame
1093 mov x2, xSELF // pass Thread::Current
1094 mov x3, sp // pass SP
1095 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP)
1096 ldr xSELF, [sp, #200] // Restore self pointer.
1097 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET]
1098 cbnz x2, .Lexception_in_proxy // success if no exception is pending
1099 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME_NO_D0 // keep d0
1100 ret // return on success
1101.Lexception_in_proxy:
1102 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1103 DELIVER_PENDING_EXCEPTION
1104END art_quick_proxy_invoke_handler
Stuart Monteithb95a5342014-03-12 13:32:32 +00001105
1106UNIMPLEMENTED art_quick_imt_conflict_trampoline
1107
1108
1109ENTRY art_quick_resolution_trampoline
1110 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME
Andreas Gampec6ee54e2014-03-24 16:45:44 -07001111 mov x19, x0 // save the called method
Stuart Monteithb95a5342014-03-12 13:32:32 +00001112 mov x2, xSELF
1113 mov x3, sp
1114 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP)
Andreas Gampec6ee54e2014-03-24 16:45:44 -07001115 mov x9, x0 // Remember returned code pointer in x9.
1116 mov x0, x19 // Restore the method, before x19 is restored to on-call value
Stuart Monteithb95a5342014-03-12 13:32:32 +00001117 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1118 cbz x9, 1f
Andreas Gampec6ee54e2014-03-24 16:45:44 -07001119 br x9
Stuart Monteithb95a5342014-03-12 13:32:32 +000011201:
1121 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1122 DELIVER_PENDING_EXCEPTION
1123END art_quick_resolution_trampoline
1124
1125/*
1126 * Generic JNI frame layout:
1127 *
1128 * #-------------------#
1129 * | |
1130 * | caller method... |
1131 * #-------------------# <--- SP on entry
1132 * | Return X30/LR |
1133 * | X29/FP | callee save
1134 * | X28 | callee save
1135 * | X27 | callee save
1136 * | X26 | callee save
1137 * | X25 | callee save
1138 * | X24 | callee save
1139 * | X23 | callee save
1140 * | X22 | callee save
1141 * | X21 | callee save
1142 * | X20 | callee save
1143 * | X19 | callee save
1144 * | X7 | arg7
1145 * | X6 | arg6
1146 * | X5 | arg5
1147 * | X4 | arg4
1148 * | X3 | arg3
1149 * | X2 | arg2
1150 * | X1 | arg1
1151 * | D15 | float arg 8
1152 * | D14 | float arg 8
1153 * | D13 | float arg 8
1154 * | D12 | callee save
1155 * | D11 | callee save
1156 * | D10 | callee save
1157 * | D9 | callee save
1158 * | D8 | callee save
1159 * | D7 | float arg 8
1160 * | D6 | float arg 7
1161 * | D5 | float arg 6
1162 * | D4 | float arg 5
1163 * | D3 | float arg 4
1164 * | D2 | float arg 3
1165 * | D1 | float arg 2
1166 * | D0 | float arg 1
1167 * | RDI/Method* | <- X0
1168 * #-------------------#
1169 * | local ref cookie | // 4B
1170 * | SIRT size | // 4B
1171 * #-------------------#
1172 * | JNI Call Stack |
1173 * #-------------------# <--- SP on native call
1174 * | |
1175 * | Stack for Regs | The trampoline assembly will pop these values
1176 * | | into registers for native call
1177 * #-------------------#
1178 * | Native code ptr |
1179 * #-------------------#
1180 * | Free scratch |
1181 * #-------------------#
1182 * | Ptr to (1) | <--- SP
1183 * #-------------------#
1184 */
1185 /*
1186 * Called to do a generic JNI down-call
1187 */
1188ENTRY art_quick_generic_jni_trampoline
1189 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
1190 str x0, [sp, #0] // Store native ArtMethod* to bottom of stack.
1191
1192 // Save SP , so we can have static CFI info.
1193 mov x28, sp
1194 .cfi_def_cfa_register x28
1195
1196 // This looks the same, but is different: this will be updated to point to the bottom
1197 // of the frame when the SIRT is inserted.
1198 mov xFP, sp
1199
1200 mov x8, #5120
1201 sub sp, sp, x8
1202
1203 // prepare for artQuickGenericJniTrampoline call
1204 // (Thread*, SP)
1205 // x0 x1 <= C calling convention
1206 // xSELF xFP <= where they are
1207
1208 mov x0, xSELF // Thread*
1209 mov x1, xFP
1210 bl artQuickGenericJniTrampoline // (Thread*, sp)
1211
1212 // Get the updated pointer. This is the bottom of the frame _with_ SIRT.
1213 ldr xFP, [sp]
1214 add x9, sp, #8
1215
1216 cmp x0, #0
1217 b.mi .Lentry_error // Check for error, negative value.
1218
1219 // release part of the alloca.
1220 add x9, x9, x0
1221
1222 // Get the code pointer
1223 ldr xIP0, [x9, #0]
1224
1225 // Load parameters from frame into registers.
1226 // TODO Check with artQuickGenericJniTrampoline.
1227 // Also, check again APPCS64 - the stack arguments are interleaved.
1228 ldp x0, x1, [x9, #8]
1229 ldp x2, x3, [x9, #24]
1230 ldp x4, x5, [x9, #40]
1231 ldp x6, x7, [x9, #56]
1232
1233 ldp d0, d1, [x9, #72]
1234 ldp d2, d3, [x9, #88]
1235 ldp d4, d5, [x9, #104]
1236 ldp d6, d7, [x9, #120]
1237
1238 add sp, x9, #136
1239
1240 blr xIP0 // native call.
1241
1242 // Restore self pointer.
1243 ldr xSELF, [x28, #200]
1244
1245 // result sign extension is handled in C code
1246 // prepare for artQuickGenericJniEndTrampoline call
1247 // (Thread*, SP, result, result_f)
1248 // x0 x1 x2 x3 <= C calling convention
1249 mov x5, x0 // Save return value
1250 mov x0, xSELF // Thread register
1251 mov x1, xFP // Stack pointer
1252 mov x2, x5 // Result (from saved)
1253 fmov x3, d0 // d0 will contain floating point result, but needs to go into x3
1254
1255 bl artQuickGenericJniEndTrampoline
1256
1257 // Tear down the alloca.
1258 mov sp, x28
1259 .cfi_def_cfa_register sp
1260
1261 // Restore self pointer.
1262 ldr xSELF, [x28, #200]
1263
1264 // Pending exceptions possible.
1265 ldr x1, [xSELF, THREAD_EXCEPTION_OFFSET]
1266 cbnz x1, .Lexception_in_native
1267
1268 // Tear down the callee-save frame.
1269 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1270
1271 // store into fpr, for when it's a fpr return...
1272 fmov d0, x0
1273 ret
1274
1275.Lentry_error:
1276 mov sp, x28
1277 .cfi_def_cfa_register sp
1278 ldr xSELF, [x28, #200]
1279.Lexception_in_native:
1280 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME
1281 DELIVER_PENDING_EXCEPTION
1282
1283END art_quick_generic_jni_trampoline
1284
1285/*
1286 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those
1287 * of a quick call:
1288 * x0 = method being called/to bridge to.
1289 * x1..x7, d0..d7 = arguments to that method.
1290 */
1291ENTRY art_quick_to_interpreter_bridge
1292 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments.
1293
1294 // x0 will contain mirror::ArtMethod* method.
1295 mov x1, xSELF // How to get Thread::Current() ???
1296 mov x2, sp
1297
1298 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self,
1299 // mirror::ArtMethod** sp)
1300 bl artQuickToInterpreterBridge
1301
1302 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case.
1303
1304 fmov d0, x0
1305
1306 RETURN_OR_DELIVER_PENDING_EXCEPTION
1307END art_quick_to_interpreter_bridge
1308
1309UNIMPLEMENTED art_quick_instrumentation_entry
1310UNIMPLEMENTED art_quick_instrumentation_exit
1311UNIMPLEMENTED art_quick_deoptimize
1312UNIMPLEMENTED art_quick_mul_long
1313UNIMPLEMENTED art_quick_shl_long
1314UNIMPLEMENTED art_quick_shr_long
1315UNIMPLEMENTED art_quick_ushr_long
1316UNIMPLEMENTED art_quick_indexof
1317UNIMPLEMENTED art_quick_string_compareto