quick_entrypoints_arm64.S revision 48241e786121e1c4c050d9cfad3d22de270a3e75
1/* 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 39 // 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 44 // FP args 45 stp d0, d1, [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] 68 .cfi_rel_offset x18, 264 69 .cfi_rel_offset x19, 272 70 71 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 93 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 */ 103// WIP. 104.macro SETUP_REF_ONLY_CALLEE_SAVE_FRAME 105 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] 158.endm 159 160.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 161 // 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 197.endm 198 199.macro RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 200 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 201 ret 202.endm 203 204 205.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 206 sub sp, sp, #304 207 .cfi_adjust_cfa_offset 304 208 209 // Ugly compile-time check, but we only have the preprocessor. 210#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 304) 211#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(ARM64) size not as expected." 212#endif 213 214 stp d0, d1, [sp, #16] 215 stp d2, d3, [sp, #32] 216 stp d4, d5, [sp, #48] 217 stp d6, d7, [sp, #64] 218 stp d8, d9, [sp, #80] 219 stp d10, d11, [sp, #96] 220 stp d12, d13, [sp, #112] 221 stp d14, d15, [sp, #128] 222 223 stp x1, x2, [sp, #144] 224 .cfi_rel_offset x1, 144 225 .cfi_rel_offset x2, 152 226 227 stp x3, x4, [sp, #160] 228 .cfi_rel_offset x3, 160 229 .cfi_rel_offset x4, 168 230 231 stp x5, x6, [sp, #176] 232 .cfi_rel_offset x5, 176 233 .cfi_rel_offset x6, 184 234 235 stp x7, xSELF, [sp, #192] 236 .cfi_rel_offset x7, 192 237 .cfi_rel_offset x18, 200 238 239 stp x19, x20, [sp, #208] 240 .cfi_rel_offset x19, 208 241 .cfi_rel_offset x20, 216 242 243 stp x21, x22, [sp, #224] 244 .cfi_rel_offset x21, 224 245 .cfi_rel_offset x22, 232 246 247 stp x23, x24, [sp, #240] 248 .cfi_rel_offset x23, 240 249 .cfi_rel_offset x24, 248 250 251 stp x25, x26, [sp, #256] 252 .cfi_rel_offset x25, 256 253 .cfi_rel_offset x26, 264 254 255 stp x27, x28, [sp, #272] 256 .cfi_rel_offset x27, 272 257 .cfi_rel_offset x28, 280 258 259 stp xFP, xLR, [sp, #288] 260 .cfi_rel_offset x29, 288 261 .cfi_rel_offset x30, 296 262.endm 263 264 /* 265 * Macro that sets up the callee save frame to conform with 266 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). 267 * 268 * TODO This is probably too conservative - saving FP & LR. 269 */ 270.macro SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME 271 adrp x9, :got:_ZN3art7Runtime9instance_E 272 ldr x9, [x9, #:got_lo12:_ZN3art7Runtime9instance_E] 273 274 // Our registers aren't intermixed - just spill in order. 275 ldr x9,[x9] // x9 = & (art::Runtime * art::Runtime.instance_) . 276 277 // x9 = (ArtMethod*) Runtime.instance_.callee_save_methods[kRefAndArgs] . 278 ldr x9, [x9, RUNTIME_REF_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET ] 279 280 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 281 282 str x9, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kRefsAndArgs] 283.endm 284 285.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 286 287 ldp d0, d1, [sp, #16] 288 ldp d2, d3, [sp, #32] 289 ldp d4, d5, [sp, #48] 290 ldp d6, d7, [sp, #64] 291 ldp d8, d9, [sp, #80] 292 ldp d10, d11, [sp, #96] 293 ldp d12, d13, [sp, #112] 294 ldp d14, d15, [sp, #128] 295 296 // args. 297 ldp x1, x2, [sp, #144] 298 .cfi_restore x1 299 .cfi_restore x2 300 301 ldp x3, x4, [sp, #160] 302 .cfi_restore x3 303 .cfi_restore x4 304 305 ldp x5, x6, [sp, #176] 306 .cfi_restore x5 307 .cfi_restore x6 308 309 ldp x7, xSELF, [sp, #192] 310 .cfi_restore x7 311 .cfi_restore x18 312 313 ldp x19, x20, [sp, #208] 314 .cfi_restore x19 315 .cfi_restore x20 316 317 ldp x21, x22, [sp, #224] 318 .cfi_restore x21 319 .cfi_restore x22 320 321 ldp x23, x24, [sp, #240] 322 .cfi_restore x23 323 .cfi_restore x24 324 325 ldp x25, x26, [sp, #256] 326 .cfi_restore x25 327 .cfi_restore x26 328 329 ldp x27, x28, [sp, #272] 330 .cfi_restore x27 331 .cfi_restore x28 332 333 ldp xFP, xLR, [sp, #288] 334 .cfi_restore x29 335 .cfi_restore x30 336 337 add sp, sp, #304 338 .cfi_adjust_cfa_offset -304 339.endm 340 341.macro RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME_NO_D0 342 343 ldr d1, [sp, #24] 344 ldp d2, d3, [sp, #32] 345 ldp d4, d5, [sp, #48] 346 ldp d6, d7, [sp, #64] 347 ldp d8, d9, [sp, #80] 348 ldp d10, d11, [sp, #96] 349 ldp d12, d13, [sp, #112] 350 ldp d14, d15, [sp, #128] 351 352 // args. 353 ldp x1, x2, [sp, #144] 354 .cfi_restore x1 355 .cfi_restore x2 356 357 ldp x3, x4, [sp, #160] 358 .cfi_restore x3 359 .cfi_restore x4 360 361 ldp x5, x6, [sp, #176] 362 .cfi_restore x5 363 .cfi_restore x6 364 365 ldp x7, xSELF, [sp, #192] 366 .cfi_restore x7 367 .cfi_restore x18 368 369 ldp x19, x20, [sp, #208] 370 .cfi_restore x19 371 .cfi_restore x20 372 373 ldp x21, x22, [sp, #224] 374 .cfi_restore x21 375 .cfi_restore x22 376 377 ldp x23, x24, [sp, #240] 378 .cfi_restore x23 379 .cfi_restore x24 380 381 ldp x25, x26, [sp, #256] 382 .cfi_restore x25 383 .cfi_restore x26 384 385 ldp x27, x28, [sp, #272] 386 .cfi_restore x27 387 .cfi_restore x28 388 389 ldp xFP, xLR, [sp, #288] 390 .cfi_restore x29 391 .cfi_restore x30 392 393 add sp, sp, #304 394 .cfi_adjust_cfa_offset -304 395.endm 396 397.macro RETURN_IF_RESULT_IS_ZERO 398 cbnz x0, 1f // result non-zero branch over 399 ret // return 4001: 401.endm 402 403.macro RETURN_IF_RESULT_IS_NON_ZERO 404 cbz x0, 1f // result zero branch over 405 ret // return 4061: 407.endm 408 409 /* 410 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending 411 * exception is Thread::Current()->exception_ 412 */ 413.macro DELIVER_PENDING_EXCEPTION 414 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 415 mov x0, xSELF 416 mov x1, sp 417 418 // Point of no return. 419 b artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*, SP) 420 brk 0 // Unreached 421.endm 422 423.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg 424 ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field. 425 cbnz \reg, 1f 426 ret 4271: 428 DELIVER_PENDING_EXCEPTION 429.endm 430 431.macro RETURN_OR_DELIVER_PENDING_EXCEPTION 432 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x9 433.endm 434 435// Same as above with x1. This is helpful in stubs that want to avoid clobbering another register. 436.macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 437 RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1 438.endm 439 440.macro RETURN_IF_W0_IS_ZERO_OR_DELIVER 441 cbnz w0, 1f // result non-zero branch over 442 ret // return 4431: 444 DELIVER_PENDING_EXCEPTION 445.endm 446 447.macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 448 .extern \cxx_name 449ENTRY \c_name 450 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 451 mov x0, xSELF // pass Thread::Current 452 mov x1, sp // pass SP 453 b \cxx_name // \cxx_name(Thread*, SP) 454END \c_name 455.endm 456 457.macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name 458 .extern \cxx_name 459ENTRY \c_name 460 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context. 461 mov x1, xSELF // pass Thread::Current. 462 mov x2, sp // pass SP. 463 b \cxx_name // \cxx_name(arg, Thread*, SP). 464 brk 0 465END \c_name 466.endm 467 468.macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name 469 .extern \cxx_name 470ENTRY \c_name 471 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 472 mov x2, xSELF // pass Thread::Current 473 mov x3, sp // pass SP 474 b \cxx_name // \cxx_name(arg1, arg2, Thread*, SP) 475 brk 0 476END \c_name 477.endm 478 479 /* 480 * Called by managed code, saves callee saves and then calls artThrowException 481 * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. 482 */ 483ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode 484 485 /* 486 * Called by managed code to create and deliver a NullPointerException. 487 */ 488NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode 489 490 /* 491 * Called by managed code to create and deliver an ArithmeticException. 492 */ 493NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode 494 495 /* 496 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds 497 * index, arg2 holds limit. 498 */ 499TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode 500 501 /* 502 * Called by managed code to create and deliver a StackOverflowError. 503 */ 504NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode 505 506 /* 507 * Called by managed code to create and deliver a NoSuchMethodError. 508 */ 509ONE_ARG_RUNTIME_EXCEPTION art_quick_throw_no_such_method, artThrowNoSuchMethodFromCode 510 511 /* 512 * All generated callsites for interface invokes and invocation slow paths will load arguments 513 * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain 514 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the 515 * stack and call the appropriate C helper. 516 * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1. 517 * 518 * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting 519 * of the target Method* in x0 and method->code_ in x1. 520 * 521 * If unsuccessful, the helper will return NULL/????. There will be a pending exception in the 522 * thread and we branch to another stub to deliver it. 523 * 524 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr 525 * pointing back to the original caller. 526 * 527 * Adapted from ARM32 code. 528 * 529 * Clobbers x12. 530 */ 531.macro INVOKE_TRAMPOLINE c_name, cxx_name 532 .extern \cxx_name 533ENTRY \c_name 534 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // save callee saves in case allocation triggers GC 535 // Helper signature is always 536 // (method_idx, *this_object, *caller_method, *self, sp) 537 538 ldr x2, [sp, #FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE] // pass caller Method* 539 mov x3, xSELF // pass Thread::Current 540 mov x4, sp 541 bl \cxx_name // (method_idx, this, caller, Thread*, SP) 542 mov x12, x1 // save Method*->code_ 543 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 544 cbz x0, 1f // did we find the target? if not go to exception delivery 545 br x12 // tail call to target 5461: 547 DELIVER_PENDING_EXCEPTION 548END \c_name 549.endm 550 551INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline 552INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck 553 554INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck 555INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck 556INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck 557INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck 558 559 560.macro INVOKE_STUB_CREATE_FRAME 561 562SAVE_SIZE=5*8 // x4, x5, SP, LR & FP saved. 563SAVE_SIZE_AND_METHOD=SAVE_SIZE+8 564 565 mov x9, sp // Save stack pointer. 566 .cfi_register sp,x9 567 568 add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame. 569 sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args 570 and x10, x10, # ~0xf // Enforce 16 byte stack alignment. 571 mov sp, x10 // Set new SP. 572 573 sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP 574 .cfi_def_cfa_register x10 // before this. 575 .cfi_adjust_cfa_offset SAVE_SIZE 576 577 str x9, [x10, #32] // Save old stack pointer. 578 .cfi_rel_offset sp, 32 579 580 stp x4, x5, [x10, #16] // Save result and shorty addresses. 581 .cfi_rel_offset x4, 16 582 .cfi_rel_offset x5, 24 583 584 stp xFP, xLR, [x10] // Store LR & FP. 585 .cfi_rel_offset x29, 0 586 .cfi_rel_offset x30, 8 587 588 mov xFP, x10 // Use xFP now, as it's callee-saved. 589 .cfi_def_cfa_register x29 590 mov xSELF, x3 // Move thread pointer into SELF register. 591 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to suspend check interval 592 593 // Copy arguments into stack frame. 594 // Use simple copy routine for now. 595 // 4 bytes per slot. 596 // X1 - source address 597 // W2 - args length 598 // X9 - destination address. 599 // W10 - temporary 600 add x9, sp, #8 // Destination address is bottom of stack + NULL. 601 602 // Use \@ to differentiate between macro invocations. 603.LcopyParams\@: 604 cmp w2, #0 605 beq .LendCopyParams\@ 606 sub w2, w2, #4 // Need 65536 bytes of range. 607 ldr w10, [x1, x2] 608 str w10, [x9, x2] 609 610 b .LcopyParams\@ 611 612.LendCopyParams\@: 613 614 // Store NULL into Method* at bottom of frame. 615 str xzr, [sp] 616 617.endm 618 619.macro INVOKE_STUB_CALL_AND_RETURN 620 621 // load method-> METHOD_QUICK_CODE_OFFSET 622 ldr x9, [x0 , #METHOD_QUICK_CODE_OFFSET] 623 // Branch to method. 624 blr x9 625 626 // Restore return value address and shorty address. 627 ldp x4,x5, [xFP, #16] 628 .cfi_restore x4 629 .cfi_restore x5 630 631 // Store result (w0/x0/s0/d0) appropriately, depending on resultType. 632 ldrb w10, [x5] 633 634 // Don't set anything for a void type. 635 cmp w10, #'V' 636 beq .Lexit_art_quick_invoke_stub\@ 637 638 cmp w10, #'D' 639 bne .Lreturn_is_float\@ 640 str d0, [x4] 641 b .Lexit_art_quick_invoke_stub\@ 642 643.Lreturn_is_float\@: 644 cmp w10, #'F' 645 bne .Lreturn_is_int\@ 646 str s0, [x4] 647 b .Lexit_art_quick_invoke_stub\@ 648 649 // Just store x0. Doesn't matter if it is 64 or 32 bits. 650.Lreturn_is_int\@: 651 str x0, [x4] 652 653.Lexit_art_quick_invoke_stub\@: 654 ldr x2, [x29, #32] // Restore stack pointer. 655 mov sp, x2 656 .cfi_restore sp 657 658 ldp x29, x30, [x29] // Restore old frame pointer and link register. 659 .cfi_restore x29 660 .cfi_restore x30 661 662 ret 663 664.endm 665 666 667/* 668 * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0 669 * uint32_t *args, x1 670 * uint32_t argsize, w2 671 * Thread *self, x3 672 * JValue *result, x4 673 * char *shorty); x5 674 * +----------------------+ 675 * | | 676 * | C/C++ frame | 677 * | LR'' | 678 * | FP'' | <- SP' 679 * +----------------------+ 680 * +----------------------+ 681 * | SP' | 682 * | X5 | 683 * | X4 | Saved registers 684 * | LR' | 685 * | FP' | <- FP 686 * +----------------------+ 687 * | uint32_t out[n-1] | 688 * | : : | Outs 689 * | uint32_t out[0] | 690 * | ArtMethod* NULL | <- SP 691 * +----------------------+ 692 * 693 * Outgoing registers: 694 * x0 - Method* 695 * x1-x7 - integer parameters. 696 * d0-d7 - Floating point parameters. 697 * xSELF = self 698 * wSUSPEND = suspend count 699 * SP = & of ArtMethod* 700 * x1 = "this" pointer. 701 * 702 */ 703ENTRY art_quick_invoke_stub 704 // Spill registers as per AACPS64 calling convention. 705 INVOKE_STUB_CREATE_FRAME 706 707 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 708 // Parse the passed shorty to determine which register to load. 709 // Load addresses for routines that load WXSD registers. 710 adr x11, .LstoreW2 711 adr x12, .LstoreX2 712 adr x13, .LstoreS0 713 adr x14, .LstoreD0 714 715 // Initialize routine offsets to 0 for integers and floats. 716 // x8 for integers, x15 for floating point. 717 mov x8, #0 718 mov x15, #0 719 720 add x10, x5, #1 // Load shorty address, plus one to skip return value. 721 ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer. 722 723 // Loop to fill registers. 724.LfillRegisters: 725 ldrb w17, [x10], #1 // Load next character in signature, and increment. 726 cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated. 727 728 cmp w17, #'F' // is this a float? 729 bne .LisDouble 730 731 cmp x15, # 8*12 // Skip this load if all registers full. 732 beq .Ladvance4 733 734 add x17, x13, x15 // Calculate subroutine to jump to. 735 br x17 736 737.LisDouble: 738 cmp w17, #'D' // is this a double? 739 bne .LisLong 740 741 cmp x15, # 8*12 // Skip this load if all registers full. 742 beq .Ladvance8 743 744 add x17, x14, x15 // Calculate subroutine to jump to. 745 br x17 746 747.LisLong: 748 cmp w17, #'J' // is this a long? 749 bne .LisOther 750 751 cmp x8, # 6*12 // Skip this load if all registers full. 752 beq .Ladvance8 753 754 add x17, x12, x8 // Calculate subroutine to jump to. 755 br x17 756 757.LisOther: // Everything else takes one vReg. 758 cmp x8, # 6*12 // Skip this load if all registers full. 759 beq .Ladvance4 760 761 add x17, x11, x8 // Calculate subroutine to jump to. 762 br x17 763 764.Ladvance4: 765 add x9, x9, #4 766 b .LfillRegisters 767 768.Ladvance8: 769 add x9, x9, #8 770 b .LfillRegisters 771 772// Macro for loading a parameter into a register. 773// counter - the register with offset into these tables 774// size - the size of the register - 4 or 8 bytes. 775// register - the name of the register to be loaded. 776.macro LOADREG counter size register return 777 ldr \register , [x9], #\size 778 add \counter, \counter, 12 779 b \return 780.endm 781 782// Store ints. 783.LstoreW2: 784 LOADREG x8 4 w2 .LfillRegisters 785 LOADREG x8 4 w3 .LfillRegisters 786 LOADREG x8 4 w4 .LfillRegisters 787 LOADREG x8 4 w5 .LfillRegisters 788 LOADREG x8 4 w6 .LfillRegisters 789 LOADREG x8 4 w7 .LfillRegisters 790 791// Store longs. 792.LstoreX2: 793 LOADREG x8 8 x2 .LfillRegisters 794 LOADREG x8 8 x3 .LfillRegisters 795 LOADREG x8 8 x4 .LfillRegisters 796 LOADREG x8 8 x5 .LfillRegisters 797 LOADREG x8 8 x6 .LfillRegisters 798 LOADREG x8 8 x7 .LfillRegisters 799 800// Store singles. 801.LstoreS0: 802 LOADREG x15 4 s0 .LfillRegisters 803 LOADREG x15 4 s1 .LfillRegisters 804 LOADREG x15 4 s2 .LfillRegisters 805 LOADREG x15 4 s3 .LfillRegisters 806 LOADREG x15 4 s4 .LfillRegisters 807 LOADREG x15 4 s5 .LfillRegisters 808 LOADREG x15 4 s6 .LfillRegisters 809 LOADREG x15 4 s7 .LfillRegisters 810 811// Store doubles. 812.LstoreD0: 813 LOADREG x15 8 d0 .LfillRegisters 814 LOADREG x15 8 d1 .LfillRegisters 815 LOADREG x15 8 d2 .LfillRegisters 816 LOADREG x15 8 d3 .LfillRegisters 817 LOADREG x15 8 d4 .LfillRegisters 818 LOADREG x15 8 d5 .LfillRegisters 819 LOADREG x15 8 d6 .LfillRegisters 820 LOADREG x15 8 d7 .LfillRegisters 821 822 823.LcallFunction: 824 825 INVOKE_STUB_CALL_AND_RETURN 826 827END art_quick_invoke_stub 828 829/* extern"C" 830 * void art_quick_invoke_static_stub(ArtMethod *method, x0 831 * uint32_t *args, x1 832 * uint32_t argsize, w2 833 * Thread *self, x3 834 * JValue *result, x4 835 * char *shorty); x5 836 */ 837ENTRY art_quick_invoke_static_stub 838 // Spill registers as per AACPS64 calling convention. 839 INVOKE_STUB_CREATE_FRAME 840 841 // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. 842 // Parse the passed shorty to determine which register to load. 843 // Load addresses for routines that load WXSD registers. 844 adr x11, .LstoreW1_2 845 adr x12, .LstoreX1_2 846 adr x13, .LstoreS0_2 847 adr x14, .LstoreD0_2 848 849 // Initialize routine offsets to 0 for integers and floats. 850 // x8 for integers, x15 for floating point. 851 mov x8, #0 852 mov x15, #0 853 854 add x10, x5, #1 // Load shorty address, plus one to skip return value. 855 856 // Loop to fill registers. 857.LfillRegisters2: 858 ldrb w17, [x10], #1 // Load next character in signature, and increment. 859 cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated. 860 861 cmp w17, #'F' // is this a float? 862 bne .LisDouble2 863 864 cmp x15, # 8*12 // Skip this load if all registers full. 865 beq .Ladvance4_2 866 867 add x17, x13, x15 // Calculate subroutine to jump to. 868 br x17 869 870.LisDouble2: 871 cmp w17, #'D' // is this a double? 872 bne .LisLong2 873 874 cmp x15, # 8*12 // Skip this load if all registers full. 875 beq .Ladvance8_2 876 877 add x17, x14, x15 // Calculate subroutine to jump to. 878 br x17 879 880.LisLong2: 881 cmp w17, #'J' // is this a long? 882 bne .LisOther2 883 884 cmp x8, # 7*12 // Skip this load if all registers full. 885 beq .Ladvance8_2 886 887 add x17, x12, x8 // Calculate subroutine to jump to. 888 br x17 889 890.LisOther2: // Everything else takes one vReg. 891 cmp x8, # 7*12 // Skip this load if all registers full. 892 beq .Ladvance4_2 893 894 add x17, x11, x8 // Calculate subroutine to jump to. 895 br x17 896 897.Ladvance4_2: 898 add x9, x9, #4 899 b .LfillRegisters2 900 901.Ladvance8_2: 902 add x9, x9, #8 903 b .LfillRegisters2 904 905// Store ints. 906.LstoreW1_2: 907 LOADREG x8 4 w1 .LfillRegisters2 908 LOADREG x8 4 w2 .LfillRegisters2 909 LOADREG x8 4 w3 .LfillRegisters2 910 LOADREG x8 4 w4 .LfillRegisters2 911 LOADREG x8 4 w5 .LfillRegisters2 912 LOADREG x8 4 w6 .LfillRegisters2 913 LOADREG x8 4 w7 .LfillRegisters2 914 915// Store longs. 916.LstoreX1_2: 917 LOADREG x8 8 x1 .LfillRegisters2 918 LOADREG x8 8 x2 .LfillRegisters2 919 LOADREG x8 8 x3 .LfillRegisters2 920 LOADREG x8 8 x4 .LfillRegisters2 921 LOADREG x8 8 x5 .LfillRegisters2 922 LOADREG x8 8 x6 .LfillRegisters2 923 LOADREG x8 8 x7 .LfillRegisters2 924 925// Store singles. 926.LstoreS0_2: 927 LOADREG x15 4 s0 .LfillRegisters2 928 LOADREG x15 4 s1 .LfillRegisters2 929 LOADREG x15 4 s2 .LfillRegisters2 930 LOADREG x15 4 s3 .LfillRegisters2 931 LOADREG x15 4 s4 .LfillRegisters2 932 LOADREG x15 4 s5 .LfillRegisters2 933 LOADREG x15 4 s6 .LfillRegisters2 934 LOADREG x15 4 s7 .LfillRegisters2 935 936// Store doubles. 937.LstoreD0_2: 938 LOADREG x15 8 d0 .LfillRegisters2 939 LOADREG x15 8 d1 .LfillRegisters2 940 LOADREG x15 8 d2 .LfillRegisters2 941 LOADREG x15 8 d3 .LfillRegisters2 942 LOADREG x15 8 d4 .LfillRegisters2 943 LOADREG x15 8 d5 .LfillRegisters2 944 LOADREG x15 8 d6 .LfillRegisters2 945 LOADREG x15 8 d7 .LfillRegisters2 946 947 948.LcallFunction2: 949 950 INVOKE_STUB_CALL_AND_RETURN 951 952END art_quick_invoke_static_stub 953 954 955 956 /* 957 * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_ 958 */ 959 960ENTRY art_quick_do_long_jump 961 // Load FPRs 962 ldp d0, d1, [x1], #16 963 ldp d2, d3, [x1], #16 964 ldp d4, d5, [x1], #16 965 ldp d6, d7, [x1], #16 966 ldp d8, d9, [x1], #16 967 ldp d10, d11, [x1], #16 968 ldp d12, d13, [x1], #16 969 ldp d14, d15, [x1], #16 970 ldp d16, d17, [x1], #16 971 ldp d18, d19, [x1], #16 972 ldp d20, d21, [x1], #16 973 ldp d22, d23, [x1], #16 974 ldp d24, d25, [x1], #16 975 ldp d26, d27, [x1], #16 976 ldp d28, d29, [x1], #16 977 ldp d30, d31, [x1] 978 979 // Load GPRs 980 // TODO: lots of those are smashed, could optimize. 981 add x0, x0, #30*8 982 ldp x30, x1, [x0], #-16 983 ldp x28, x29, [x0], #-16 984 ldp x26, x27, [x0], #-16 985 ldp x24, x25, [x0], #-16 986 ldp x22, x23, [x0], #-16 987 ldp x20, x21, [x0], #-16 988 ldp x18, x19, [x0], #-16 989 ldp x16, x17, [x0], #-16 990 ldp x14, x15, [x0], #-16 991 ldp x12, x13, [x0], #-16 992 ldp x10, x11, [x0], #-16 993 ldp x8, x9, [x0], #-16 994 ldp x6, x7, [x0], #-16 995 ldp x4, x5, [x0], #-16 996 ldp x2, x3, [x0], #-16 997 mov sp, x1 998 999 // TODO: Is it really OK to use LR for the target PC? 1000 mov x0, #0 1001 mov x1, #0 1002 br xLR 1003END art_quick_do_long_jump 1004 1005 /* 1006 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on 1007 * failure. 1008 */ 1009 .extern artHandleFillArrayDataFromCode 1010ENTRY art_quick_handle_fill_data 1011 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // Save callee saves in case exception allocation triggers GC. 1012 mov x2, xSELF // Pass Thread::Current. 1013 mov x3, sp // Pass SP. 1014 bl artHandleFillArrayDataFromCode // (Array*, const DexFile::Payload*, Thread*, SP) 1015 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1016 RETURN_IF_RESULT_IS_ZERO 1017 DELIVER_PENDING_EXCEPTION 1018END art_quick_handle_fill_data 1019 1020 /* 1021 * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the 1022 * possibly null object to lock. 1023 * 1024 * Derived from arm32 code. 1025 */ 1026 .extern artLockObjectFromCode 1027ENTRY art_quick_lock_object 1028 cbz w0, .Lslow_lock 1029 add x4, x0, #LOCK_WORD_OFFSET // exclusive load/store had no immediate anymore 1030.Lretry_lock: 1031 ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop? 1032 ldxr w1, [x4] 1033 cbnz w1, .Lnot_unlocked // already thin locked 1034 stxr w3, w2, [x4] 1035 cbnz w3, .Lstrex_fail // store failed, retry 1036 dmb ishld // full (LoadLoad|LoadStore) memory barrier 1037 ret 1038.Lstrex_fail: 1039 b .Lretry_lock // unlikely forward branch, need to reload and recheck r1/r2 1040.Lnot_unlocked: 1041 lsr w3, w1, 30 1042 cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path 1043 eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() 1044 uxth w2, w2 // zero top 16 bits 1045 cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock 1046 // else contention, go to slow path 1047 add w2, w1, #65536 // increment count in lock word placing in w2 for storing 1048 lsr w1, w2, 30 // if either of the top two bits are set, we overflowed. 1049 cbnz w1, .Lslow_lock // if we overflow the count go slow path 1050 str w2, [x0, #LOCK_WORD_OFFSET]// no need for stxr as we hold the lock 1051 ret 1052.Lslow_lock: 1053 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case we block 1054 mov x1, xSELF // pass Thread::Current 1055 mov x2, sp // pass SP 1056 bl artLockObjectFromCode // (Object* obj, Thread*, SP) 1057 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1058 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1059END art_quick_lock_object 1060 1061 /* 1062 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. 1063 * x0 holds the possibly null object to lock. 1064 * 1065 * Derived from arm32 code. 1066 */ 1067 .extern artUnlockObjectFromCode 1068ENTRY art_quick_unlock_object 1069 cbz x0, .Lslow_unlock 1070 ldr w1, [x0, #LOCK_WORD_OFFSET] 1071 lsr w2, w1, 30 1072 cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path 1073 ldr w2, [xSELF, #THREAD_ID_OFFSET] 1074 eor w3, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() 1075 uxth w3, w3 // zero top 16 bits 1076 cbnz w3, .Lslow_unlock // do lock word and self thread id's match? 1077 cmp w1, #65536 1078 bpl .Lrecursive_thin_unlock 1079 // transition to unlocked, w3 holds 0 1080 dmb ish // full (LoadStore|StoreStore) memory barrier 1081 str w3, [x0, #LOCK_WORD_OFFSET] 1082 ret 1083.Lrecursive_thin_unlock: 1084 sub w1, w1, #65536 1085 str w1, [x0, #LOCK_WORD_OFFSET] 1086 ret 1087.Lslow_unlock: 1088 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case exception allocation triggers GC 1089 mov x1, xSELF // pass Thread::Current 1090 mov x2, sp // pass SP 1091 bl artUnlockObjectFromCode // (Object* obj, Thread*, SP) 1092 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1093 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1094END art_quick_unlock_object 1095 1096 /* 1097 * Entry from managed code that calls artIsAssignableFromCode and on failure calls 1098 * artThrowClassCastException. 1099 */ 1100 .extern artThrowClassCastException 1101ENTRY art_quick_check_cast 1102 // Store arguments and link register 1103 sub sp, sp, #32 // Stack needs to be 16b aligned on calls 1104 .cfi_adjust_cfa_offset 32 1105 stp x0, x1, [sp] 1106 .cfi_rel_offset x0, 0 1107 .cfi_rel_offset x1, 8 1108 stp xSELF, xLR, [sp, #16] 1109 .cfi_rel_offset x18, 16 1110 .cfi_rel_offset x30, 24 1111 1112 // Call runtime code 1113 bl artIsAssignableFromCode 1114 1115 // Check for exception 1116 cbz x0, .Lthrow_class_cast_exception 1117 1118 // Restore and return 1119 ldp x0, x1, [sp] 1120 .cfi_restore x0 1121 .cfi_restore x1 1122 ldp xSELF, xLR, [sp, #16] 1123 .cfi_restore x18 1124 .cfi_restore x30 1125 add sp, sp, #32 1126 .cfi_adjust_cfa_offset -32 1127 ret 1128 1129.Lthrow_class_cast_exception: 1130 // Restore 1131 ldp x0, x1, [sp] 1132 .cfi_restore x0 1133 .cfi_restore x1 1134 ldp xSELF, xLR, [sp, #16] 1135 .cfi_restore x18 1136 .cfi_restore x30 1137 add sp, sp, #32 1138 .cfi_adjust_cfa_offset -32 1139 1140 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME // save all registers as basis for long jump context 1141 mov x2, xSELF // pass Thread::Current 1142 mov x3, sp // pass SP 1143 b artThrowClassCastException // (Class*, Class*, Thread*, SP) 1144 brk 0 // We should not return here... 1145END art_quick_check_cast 1146 1147 /* 1148 * Entry from managed code for array put operations of objects where the value being stored 1149 * needs to be checked for compatibility. 1150 * x0 = array, x1 = index, x2 = value 1151 * 1152 * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We 1153 * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by 1154 * using index-zero-extension in load/stores. 1155 * 1156 * Temporaries: x3, x4 1157 * TODO: x4 OK? ip seems wrong here. 1158 */ 1159ENTRY art_quick_aput_obj_with_null_and_bound_check 1160 tst x0, x0 1161 bne art_quick_aput_obj_with_bound_check 1162 b art_quick_throw_null_pointer_exception 1163END art_quick_aput_obj_with_null_and_bound_check 1164 1165ENTRY art_quick_aput_obj_with_bound_check 1166 ldr w3, [x0, #ARRAY_LENGTH_OFFSET] 1167 cmp w3, w1 1168 bhi art_quick_aput_obj 1169 mov x0, x1 1170 mov x1, x3 1171 b art_quick_throw_array_bounds 1172END art_quick_aput_obj_with_bound_check 1173 1174ENTRY art_quick_aput_obj 1175 cbz x2, .Ldo_aput_null 1176 ldr w3, [x0, #CLASS_OFFSET] // Heap reference = 32b 1177 // This also zero-extends to x3 1178 ldr w4, [x2, #CLASS_OFFSET] // Heap reference = 32b 1179 // This also zero-extends to x4 1180 ldr w3, [x3, #CLASS_COMPONENT_TYPE_OFFSET] // Heap reference = 32b 1181 // This also zero-extends to x3 1182 cmp w3, w4 // value's type == array's component type - trivial assignability 1183 bne .Lcheck_assignability 1184.Ldo_aput: 1185 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET 1186 // "Compress" = do nothing 1187 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1188 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1189 lsr x0, x0, #7 1190 strb w3, [x3, x0] 1191 ret 1192.Ldo_aput_null: 1193 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET 1194 // "Compress" = do nothing 1195 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1196 ret 1197.Lcheck_assignability: 1198 // Store arguments and link register 1199 sub sp, sp, #48 // Stack needs to be 16b aligned on calls 1200 .cfi_adjust_cfa_offset 48 1201 stp x0, x1, [sp] 1202 .cfi_rel_offset x0, 0 1203 .cfi_rel_offset x1, 8 1204 stp x2, xSELF, [sp, #16] 1205 .cfi_rel_offset x2, 16 1206 .cfi_rel_offset x18, 24 1207 str xLR, [sp, #32] 1208 .cfi_rel_offset x30, 32 1209 1210 // Call runtime code 1211 mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1212 mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended 1213 bl artIsAssignableFromCode 1214 1215 // Check for exception 1216 cbz x0, .Lthrow_array_store_exception 1217 1218 // Restore 1219 ldp x0, x1, [sp] 1220 .cfi_restore x0 1221 .cfi_restore x1 1222 ldp x2, xSELF, [sp, #16] 1223 .cfi_restore x2 1224 .cfi_restore x18 1225 ldr xLR, [sp, #32] 1226 .cfi_restore x30 1227 add sp, sp, #48 1228 .cfi_adjust_cfa_offset -48 1229 1230 add x3, x0, #OBJECT_ARRAY_DATA_OFFSET 1231 // "Compress" = do nothing 1232 str w2, [x3, x1, lsl #2] // Heap reference = 32b 1233 ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] 1234 lsr x0, x0, #7 1235 strb w3, [x3, x0] 1236 ret 1237.Lthrow_array_store_exception: 1238 ldp x0, x1, [sp] 1239 .cfi_restore x0 1240 .cfi_restore x1 1241 ldp x2, xSELF, [sp, #16] 1242 .cfi_restore x2 1243 .cfi_restore x18 1244 ldr xLR, [sp, #32] 1245 .cfi_restore x30 1246 add sp, sp, #48 1247 .cfi_adjust_cfa_offset -48 1248 1249 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1250 mov x1, x2 // Pass value. 1251 mov x2, xSELF // Pass Thread::Current. 1252 mov x3, sp // Pass SP. 1253 b artThrowArrayStoreException // (Object*, Object*, Thread*, SP). 1254 brk 0 // Unreached. 1255END art_quick_aput_obj 1256 1257// Macro to facilitate adding new allocation entrypoints. 1258.macro TWO_ARG_DOWNCALL name, entrypoint, return 1259 .extern \entrypoint 1260ENTRY \name 1261 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1262 mov x2, xSELF // pass Thread::Current 1263 mov x3, sp // pass SP 1264 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) 1265 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1266 \return 1267 DELIVER_PENDING_EXCEPTION 1268END \name 1269.endm 1270 1271// Macro to facilitate adding new array allocation entrypoints. 1272.macro THREE_ARG_DOWNCALL name, entrypoint, return 1273 .extern \entrypoint 1274ENTRY \name 1275 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1276 mov x3, xSELF // pass Thread::Current 1277 mov x4, sp // pass SP 1278 bl \entrypoint 1279 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1280 \return 1281 DELIVER_PENDING_EXCEPTION 1282END \name 1283.endm 1284 1285// Macros taking opportunity of code similarities for downcalls with referrer. 1286 1287// TODO: xSELF -> x19. Temporarily rely on xSELF being saved in REF_ONLY 1288.macro ONE_ARG_REF_DOWNCALL name, entrypoint, return 1289 .extern \entrypoint 1290ENTRY \name 1291 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1292 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1293 mov x2, xSELF // pass Thread::Current 1294 mov x3, sp // pass SP 1295 bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) 1296 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1297 \return 1298END \name 1299.endm 1300 1301// TODO: xSELF -> x19. Temporarily rely on xSELF being saved in REF_ONLY 1302.macro TWO_ARG_REF_DOWNCALL name, entrypoint, return 1303 .extern \entrypoint 1304ENTRY \name 1305 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1306 ldr x2, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1307 mov x3, xSELF // pass Thread::Current 1308 mov x4, sp // pass SP 1309 bl \entrypoint 1310 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1311 \return 1312END \name 1313.endm 1314 1315// TODO: xSELF -> x19. Temporarily rely on xSELF being saved in REF_ONLY 1316.macro THREE_ARG_REF_DOWNCALL name, entrypoint, return 1317 .extern \entrypoint 1318ENTRY \name 1319 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1320 ldr x3, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1321 mov x4, xSELF // pass Thread::Current 1322 mov x5, sp // pass SP 1323 bl \entrypoint 1324 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1325 \return 1326END \name 1327.endm 1328 1329 /* 1330 * Entry from managed code when uninitialized static storage, this stub will run the class 1331 * initializer and deliver the exception on error. On success the static storage base is 1332 * returned. 1333 */ 1334TWO_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO 1335 1336UNIMPLEMENTED art_quick_initialize_type 1337UNIMPLEMENTED art_quick_initialize_type_and_verify_access 1338 1339ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1340ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1341ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1342 1343TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1344TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1345TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 1346 1347TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1348TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1349 1350THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1351THREE_ARG_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1352THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER 1353 1354// This is separated out as the argument order is different. 1355 .extern artSet64StaticFromCode 1356ENTRY art_quick_set64_static 1357 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves in case of GC 1358 mov x3, x1 // Store value 1359 ldr x1, [sp, #FRAME_SIZE_REFS_ONLY_CALLEE_SAVE] // Load referrer 1360 mov x2, x3 // Put value param 1361 mov x3, xSELF // pass Thread::Current 1362 mov x4, sp // pass SP 1363 bl artSet64StaticFromCode 1364 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME 1365 RETURN_IF_W0_IS_ZERO_OR_DELIVER 1366END art_quick_set64_static 1367 1368 /* 1369 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an 1370 * exception on error. On success the String is returned. x0 holds the referring method, 1371 * w1 holds the string index. The fast path check for hit in strings cache has already been 1372 * performed. 1373 */ 1374TWO_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO 1375 1376// Generate the allocation entrypoints for each allocator. 1377GENERATE_ALL_ALLOC_ENTRYPOINTS 1378 1379 /* 1380 * Called by managed code when the value in wSUSPEND has been decremented to 0. 1381 */ 1382 .extern artTestSuspendFromCode 1383ENTRY art_quick_test_suspend 1384 ldrh w0, [xSELF, #THREAD_FLAGS_OFFSET] // get xSELF->state_and_flags.as_struct.flags 1385 mov wSUSPEND, #SUSPEND_CHECK_INTERVAL // reset wSUSPEND to SUSPEND_CHECK_INTERVAL 1386 cbnz w0, .Lneed_suspend // check flags == 0 1387 ret // return if flags == 0 1388.Lneed_suspend: 1389 mov x0, xSELF 1390 SETUP_REF_ONLY_CALLEE_SAVE_FRAME // save callee saves for stack crawl 1391 mov x1, sp 1392 bl artTestSuspendFromCode // (Thread*, SP) 1393 RESTORE_REF_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1394END art_quick_test_suspend 1395 1396 /* 1397 * Called by managed code that is attempting to call a method on a proxy class. On entry 1398 * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy 1399 * method agrees with a ref and args callee save frame. 1400 */ 1401 .extern artQuickProxyInvokeHandler 1402ENTRY art_quick_proxy_invoke_handler 1403 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME 1404 str x0, [sp, #0] // place proxy method at bottom of frame 1405 mov x2, xSELF // pass Thread::Current 1406 mov x3, sp // pass SP 1407 bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP) 1408 ldr xSELF, [sp, #200] // Restore self pointer. 1409 ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] 1410 cbnz x2, .Lexception_in_proxy // success if no exception is pending 1411 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME_NO_D0 // keep d0 1412 ret // return on success 1413.Lexception_in_proxy: 1414 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 1415 DELIVER_PENDING_EXCEPTION 1416END art_quick_proxy_invoke_handler 1417 1418 /* 1419 * Called to resolve an imt conflict. x12 is a hidden argument that holds the target method's 1420 * dex method index. 1421 */ 1422ENTRY art_quick_imt_conflict_trampoline 1423 ldr x0, [sp, #0] // load caller Method* 1424 ldr w0, [x0, #METHOD_DEX_CACHE_METHODS_OFFSET] // load dex_cache_resolved_methods 1425 add x0, x0, #OBJECT_ARRAY_DATA_OFFSET // get starting address of data 1426 ldr w0, [x0, x12, lsl 2] // load the target method 1427 b art_quick_invoke_interface_trampoline 1428END art_quick_imt_conflict_trampoline 1429 1430ENTRY art_quick_resolution_trampoline 1431 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME 1432 mov x2, xSELF 1433 mov x3, sp 1434 bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP) 1435 cbz x0, 1f 1436 mov x9, x0 // Remember returned code pointer in x9. 1437 ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP. 1438 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 1439 br x9 14401: 1441 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 1442 DELIVER_PENDING_EXCEPTION 1443END art_quick_resolution_trampoline 1444 1445/* 1446 * Generic JNI frame layout: 1447 * 1448 * #-------------------# 1449 * | | 1450 * | caller method... | 1451 * #-------------------# <--- SP on entry 1452 * | Return X30/LR | 1453 * | X29/FP | callee save 1454 * | X28 | callee save 1455 * | X27 | callee save 1456 * | X26 | callee save 1457 * | X25 | callee save 1458 * | X24 | callee save 1459 * | X23 | callee save 1460 * | X22 | callee save 1461 * | X21 | callee save 1462 * | X20 | callee save 1463 * | X19 | callee save 1464 * | X7 | arg7 1465 * | X6 | arg6 1466 * | X5 | arg5 1467 * | X4 | arg4 1468 * | X3 | arg3 1469 * | X2 | arg2 1470 * | X1 | arg1 1471 * | D15 | float arg 8 1472 * | D14 | float arg 8 1473 * | D13 | float arg 8 1474 * | D12 | callee save 1475 * | D11 | callee save 1476 * | D10 | callee save 1477 * | D9 | callee save 1478 * | D8 | callee save 1479 * | D7 | float arg 8 1480 * | D6 | float arg 7 1481 * | D5 | float arg 6 1482 * | D4 | float arg 5 1483 * | D3 | float arg 4 1484 * | D2 | float arg 3 1485 * | D1 | float arg 2 1486 * | D0 | float arg 1 1487 * | RDI/Method* | <- X0 1488 * #-------------------# 1489 * | local ref cookie | // 4B 1490 * | handle scope size | // 4B 1491 * #-------------------# 1492 * | JNI Call Stack | 1493 * #-------------------# <--- SP on native call 1494 * | | 1495 * | Stack for Regs | The trampoline assembly will pop these values 1496 * | | into registers for native call 1497 * #-------------------# 1498 * | Native code ptr | 1499 * #-------------------# 1500 * | Free scratch | 1501 * #-------------------# 1502 * | Ptr to (1) | <--- SP 1503 * #-------------------# 1504 */ 1505 /* 1506 * Called to do a generic JNI down-call 1507 */ 1508ENTRY art_quick_generic_jni_trampoline 1509 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL 1510 str x0, [sp, #0] // Store native ArtMethod* to bottom of stack. 1511 1512 // Save SP , so we can have static CFI info. 1513 mov x28, sp 1514 .cfi_def_cfa_register x28 1515 1516 // This looks the same, but is different: this will be updated to point to the bottom 1517 // of the frame when the handle scope is inserted. 1518 mov xFP, sp 1519 1520 mov x8, #5120 1521 sub sp, sp, x8 1522 1523 // prepare for artQuickGenericJniTrampoline call 1524 // (Thread*, SP) 1525 // x0 x1 <= C calling convention 1526 // xSELF xFP <= where they are 1527 1528 mov x0, xSELF // Thread* 1529 mov x1, xFP 1530 bl artQuickGenericJniTrampoline // (Thread*, sp) 1531 1532 // Get the updated pointer. This is the bottom of the frame _with_ handle scope. 1533 ldr xFP, [sp] 1534 add x9, sp, #8 1535 1536 cmp x0, #0 1537 b.mi .Lentry_error // Check for error, negative value. 1538 1539 // release part of the alloca. 1540 add x9, x9, x0 1541 1542 // Get the code pointer 1543 ldr xIP0, [x9, #0] 1544 1545 // Load parameters from frame into registers. 1546 // TODO Check with artQuickGenericJniTrampoline. 1547 // Also, check again APPCS64 - the stack arguments are interleaved. 1548 ldp x0, x1, [x9, #8] 1549 ldp x2, x3, [x9, #24] 1550 ldp x4, x5, [x9, #40] 1551 ldp x6, x7, [x9, #56] 1552 1553 ldp d0, d1, [x9, #72] 1554 ldp d2, d3, [x9, #88] 1555 ldp d4, d5, [x9, #104] 1556 ldp d6, d7, [x9, #120] 1557 1558 add sp, x9, #136 1559 1560 blr xIP0 // native call. 1561 1562 // Restore self pointer. 1563 ldr xSELF, [x28, #200] 1564 1565 // result sign extension is handled in C code 1566 // prepare for artQuickGenericJniEndTrampoline call 1567 // (Thread*, SP, result, result_f) 1568 // x0 x1 x2 x3 <= C calling convention 1569 mov x5, x0 // Save return value 1570 mov x0, xSELF // Thread register 1571 mov x1, xFP // Stack pointer 1572 mov x2, x5 // Result (from saved) 1573 fmov x3, d0 // d0 will contain floating point result, but needs to go into x3 1574 1575 bl artQuickGenericJniEndTrampoline 1576 1577 // Tear down the alloca. 1578 mov sp, x28 1579 .cfi_def_cfa_register sp 1580 1581 // Restore self pointer. 1582 ldr xSELF, [x28, #200] 1583 1584 // Pending exceptions possible. 1585 ldr x1, [xSELF, THREAD_EXCEPTION_OFFSET] 1586 cbnz x1, .Lexception_in_native 1587 1588 // Tear down the callee-save frame. 1589 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 1590 1591 // store into fpr, for when it's a fpr return... 1592 fmov d0, x0 1593 ret 1594 1595.Lentry_error: 1596 mov sp, x28 1597 .cfi_def_cfa_register sp 1598 ldr xSELF, [x28, #200] 1599.Lexception_in_native: 1600 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME 1601 DELIVER_PENDING_EXCEPTION 1602 1603END art_quick_generic_jni_trampoline 1604 1605/* 1606 * Called to bridge from the quick to interpreter ABI. On entry the arguments match those 1607 * of a quick call: 1608 * x0 = method being called/to bridge to. 1609 * x1..x7, d0..d7 = arguments to that method. 1610 */ 1611ENTRY art_quick_to_interpreter_bridge 1612 SETUP_REF_AND_ARGS_CALLEE_SAVE_FRAME // Set up frame and save arguments. 1613 1614 // x0 will contain mirror::ArtMethod* method. 1615 mov x1, xSELF // How to get Thread::Current() ??? 1616 mov x2, sp 1617 1618 // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self, 1619 // mirror::ArtMethod** sp) 1620 bl artQuickToInterpreterBridge 1621 1622 RESTORE_REF_AND_ARGS_CALLEE_SAVE_FRAME // TODO: no need to restore arguments in this case. 1623 1624 fmov d0, x0 1625 1626 RETURN_OR_DELIVER_PENDING_EXCEPTION 1627END art_quick_to_interpreter_bridge 1628 1629UNIMPLEMENTED art_quick_instrumentation_entry 1630UNIMPLEMENTED art_quick_instrumentation_exit 1631UNIMPLEMENTED art_quick_deoptimize 1632UNIMPLEMENTED art_quick_indexof 1633 1634 /* 1635 * String's compareTo. 1636 * 1637 * TODO: Not very optimized. 1638 * 1639 * On entry: 1640 * x0: this object pointer 1641 * x1: comp object pointer 1642 * 1643 */ 1644 .extern __memcmp16 1645ENTRY art_quick_string_compareto 1646 mov x2, x0 // x0 is return, use x2 for first input. 1647 sub x0, x2, x1 // Same string object? 1648 cbnz x0,1f 1649 ret 16501: // Different string objects. 1651 1652 ldr w6, [x2, #STRING_OFFSET_OFFSET] 1653 ldr w5, [x1, #STRING_OFFSET_OFFSET] 1654 ldr w4, [x2, #STRING_COUNT_OFFSET] 1655 ldr w3, [x1, #STRING_COUNT_OFFSET] 1656 ldr w2, [x2, #STRING_VALUE_OFFSET] 1657 ldr w1, [x1, #STRING_VALUE_OFFSET] 1658 1659 /* 1660 * Now: CharArray* Offset Count 1661 * first arg x2 w6 w4 1662 * second arg x1 w5 w3 1663 */ 1664 1665 // x0 := str1.length(w4) - str2.length(w3). ldr zero-extended w3/w4 into x3/x4. 1666 subs x0, x4, x3 1667 // Min(count1, count2) into w3. 1668 csel x3, x3, x4, ge 1669 1670 // Build pointer into string data. 1671 1672 // Add offset in array (substr etc.) (sign extend and << 1). 1673 add x2, x2, w6, sxtw #1 1674 add x1, x1, w5, sxtw #1 1675 1676 // Add offset in CharArray to array. 1677 add x2, x2, #STRING_DATA_OFFSET 1678 add x1, x1, #STRING_DATA_OFFSET 1679 1680 // Check for long string, do memcmp16 for them. 1681 cmp w3, #28 // Constant from arm32. 1682 bgt .Ldo_memcmp16 1683 1684 /* 1685 * Now: 1686 * x2: *first string data 1687 * x1: *second string data 1688 * w3: iteration count 1689 * x0: return value if comparison equal 1690 * x4, x5, x6, x7: free 1691 */ 1692 1693 // Do a simple unrolled loop. 1694.Lloop: 1695 // At least two more elements? 1696 subs w3, w3, #2 1697 b.lt .Lremainder_or_done 1698 1699 ldrh w4, [x2], #2 1700 ldrh w5, [x1], #2 1701 1702 ldrh w6, [x2], #2 1703 ldrh w7, [x1], #2 1704 1705 subs w4, w4, w5 1706 b.ne .Lw4_result 1707 1708 subs w6, w6, w7 1709 b.ne .Lw6_result 1710 1711 b .Lloop 1712 1713.Lremainder_or_done: 1714 adds w3, w3, #1 1715 b.eq .Lremainder 1716 ret 1717 1718.Lremainder: 1719 ldrh w4, [x2], #2 1720 ldrh w5, [x1], #2 1721 subs w4, w4, w5 1722 b.ne .Lw4_result 1723 ret 1724 1725// Result is in w4 1726.Lw4_result: 1727 sxtw x0, w4 1728 ret 1729 1730// Result is in w6 1731.Lw6_result: 1732 sxtw x0, w6 1733 ret 1734 1735.Ldo_memcmp16: 1736 str x0, [sp,#-16]! // Save x0 1737 1738 mov x0, x2 1739 uxtw x2, w3 1740 bl __memcmp16 1741 1742 ldr x1, [sp], #16 // Restore old x0 = length diff 1743 1744 cmp x0, #0 // Check the memcmp difference 1745 csel x0, x0, x1, ne // x0 := x0 != 0 ? x0 : x1 1746 ret 1747END art_quick_string_compareto 1748