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