1/* 2 * Copyright (C) 2012 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_mips.S" 18 19#include "arch/quick_alloc_entrypoints.S" 20 21 .set noreorder 22 .balign 4 23 24 /* Deliver the given exception */ 25 .extern artDeliverExceptionFromCode 26 /* Deliver an exception pending on a thread */ 27 .extern artDeliverPendingExceptionFromCode 28 29#define ARG_SLOT_SIZE 32 // space for a0-a3 plus 4 more words 30 31 /* 32 * Macro that sets up the callee save frame to conform with 33 * Runtime::CreateCalleeSaveMethod(kSaveAll) 34 * Callee-save: $s0-$s8 + $gp + $ra, 11 total + 1 word for Method* 35 * Clobbers $t0 and $sp 36 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots. 37 * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack 38 */ 39.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 40 addiu $sp, $sp, -96 41 .cfi_adjust_cfa_offset 96 42 43 // Ugly compile-time check, but we only have the preprocessor. 44#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 96) 45#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS) size not as expected." 46#endif 47 48 sw $ra, 92($sp) 49 .cfi_rel_offset 31, 92 50 sw $s8, 88($sp) 51 .cfi_rel_offset 30, 88 52 sw $gp, 84($sp) 53 .cfi_rel_offset 28, 84 54 sw $s7, 80($sp) 55 .cfi_rel_offset 23, 80 56 sw $s6, 76($sp) 57 .cfi_rel_offset 22, 76 58 sw $s5, 72($sp) 59 .cfi_rel_offset 21, 72 60 sw $s4, 68($sp) 61 .cfi_rel_offset 20, 68 62 sw $s3, 64($sp) 63 .cfi_rel_offset 19, 64 64 sw $s2, 60($sp) 65 .cfi_rel_offset 18, 60 66 sw $s1, 56($sp) 67 .cfi_rel_offset 17, 56 68 sw $s0, 52($sp) 69 .cfi_rel_offset 16, 52 70 71 SDu $f30, $f31, 44, $sp, $t1 72 SDu $f28, $f29, 36, $sp, $t1 73 SDu $f26, $f27, 28, $sp, $t1 74 SDu $f24, $f25, 20, $sp, $t1 75 SDu $f22, $f23, 12, $sp, $t1 76 SDu $f20, $f21, 4, $sp, $t1 77 78 # 1 word for holding Method* 79 80 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp) 81 lw $t0, 0($t0) 82 THIS_LOAD_REQUIRES_READ_BARRIER 83 lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t0) 84 sw $t0, 0($sp) # Place Method* at bottom of stack. 85 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame. 86 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack 87 .cfi_adjust_cfa_offset ARG_SLOT_SIZE 88.endm 89 90 /* 91 * Macro that sets up the callee save frame to conform with 92 * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC. 93 * Does not include rSUSPEND or rSELF 94 * callee-save: $s2-$s8 + $gp + $ra, 9 total + 2 words padding + 1 word to hold Method* 95 * Clobbers $t0 and $sp 96 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots. 97 * Reserves FRAME_SIZE_REFS_ONLY_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack 98 */ 99.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 100 addiu $sp, $sp, -48 101 .cfi_adjust_cfa_offset 48 102 103 // Ugly compile-time check, but we only have the preprocessor. 104#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 48) 105#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS) size not as expected." 106#endif 107 108 sw $ra, 44($sp) 109 .cfi_rel_offset 31, 44 110 sw $s8, 40($sp) 111 .cfi_rel_offset 30, 40 112 sw $gp, 36($sp) 113 .cfi_rel_offset 28, 36 114 sw $s7, 32($sp) 115 .cfi_rel_offset 23, 32 116 sw $s6, 28($sp) 117 .cfi_rel_offset 22, 28 118 sw $s5, 24($sp) 119 .cfi_rel_offset 21, 24 120 sw $s4, 20($sp) 121 .cfi_rel_offset 20, 20 122 sw $s3, 16($sp) 123 .cfi_rel_offset 19, 16 124 sw $s2, 12($sp) 125 .cfi_rel_offset 18, 12 126 # 2 words for alignment and bottom word will hold Method* 127 128 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp) 129 lw $t0, 0($t0) 130 THIS_LOAD_REQUIRES_READ_BARRIER 131 lw $t0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t0) 132 sw $t0, 0($sp) # Place Method* at bottom of stack. 133 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame. 134 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack 135 .cfi_adjust_cfa_offset ARG_SLOT_SIZE 136.endm 137 138.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 139 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack 140 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE 141 lw $ra, 44($sp) 142 .cfi_restore 31 143 lw $s8, 40($sp) 144 .cfi_restore 30 145 lw $gp, 36($sp) 146 .cfi_restore 28 147 lw $s7, 32($sp) 148 .cfi_restore 23 149 lw $s6, 28($sp) 150 .cfi_restore 22 151 lw $s5, 24($sp) 152 .cfi_restore 21 153 lw $s4, 20($sp) 154 .cfi_restore 20 155 lw $s3, 16($sp) 156 .cfi_restore 19 157 lw $s2, 12($sp) 158 .cfi_restore 18 159 addiu $sp, $sp, 48 160 .cfi_adjust_cfa_offset -48 161.endm 162 163.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 164 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 165 jalr $zero, $ra 166 nop 167.endm 168 169 /* 170 * Macro that sets up the callee save frame to conform with 171 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). 172 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method* 173 */ 174.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY 175 addiu $sp, $sp, -64 176 .cfi_adjust_cfa_offset 64 177 178 // Ugly compile-time check, but we only have the preprocessor. 179#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 64) 180#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS) size not as expected." 181#endif 182 183 sw $ra, 60($sp) 184 .cfi_rel_offset 31, 60 185 sw $s8, 56($sp) 186 .cfi_rel_offset 30, 56 187 sw $gp, 52($sp) 188 .cfi_rel_offset 28, 52 189 sw $s7, 48($sp) 190 .cfi_rel_offset 23, 48 191 sw $s6, 44($sp) 192 .cfi_rel_offset 22, 44 193 sw $s5, 40($sp) 194 .cfi_rel_offset 21, 40 195 sw $s4, 36($sp) 196 .cfi_rel_offset 20, 36 197 sw $s3, 32($sp) 198 .cfi_rel_offset 19, 32 199 sw $s2, 28($sp) 200 .cfi_rel_offset 18, 28 201 sw $a3, 24($sp) 202 .cfi_rel_offset 7, 24 203 sw $a2, 20($sp) 204 .cfi_rel_offset 6, 20 205 sw $a1, 16($sp) 206 .cfi_rel_offset 5, 16 207 # bottom will hold Method* 208.endm 209 210 /* 211 * Macro that sets up the callee save frame to conform with 212 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC. 213 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method* 214 * Clobbers $t0 and $sp 215 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots. 216 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack 217 */ 218.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 219 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY 220 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp) 221 lw $t0, 0($t0) 222 THIS_LOAD_REQUIRES_READ_BARRIER 223 lw $t0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t0) 224 sw $t0, 0($sp) # Place Method* at bottom of stack. 225 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame. 226 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack 227 .cfi_adjust_cfa_offset ARG_SLOT_SIZE 228.endm 229 230 /* 231 * Macro that sets up the callee save frame to conform with 232 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC. 233 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method* 234 * Clobbers $sp 235 * Use $a0 as the Method* and loads it into bottom of stack. 236 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots. 237 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack 238 */ 239.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0 240 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY 241 sw $a0, 0($sp) # Place Method* at bottom of stack. 242 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame. 243 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack 244 .cfi_adjust_cfa_offset ARG_SLOT_SIZE 245.endm 246 247.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 248 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack 249 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE 250 lw $ra, 60($sp) 251 .cfi_restore 31 252 lw $s8, 56($sp) 253 .cfi_restore 30 254 lw $gp, 52($sp) 255 .cfi_restore 28 256 lw $s7, 48($sp) 257 .cfi_restore 23 258 lw $s6, 44($sp) 259 .cfi_restore 22 260 lw $s5, 40($sp) 261 .cfi_restore 21 262 lw $s4, 36($sp) 263 .cfi_restore 20 264 lw $s3, 32($sp) 265 .cfi_restore 19 266 lw $s2, 28($sp) 267 .cfi_restore 18 268 lw $a3, 24($sp) 269 .cfi_restore 7 270 lw $a2, 20($sp) 271 .cfi_restore 6 272 lw $a1, 16($sp) 273 .cfi_restore 5 274 addiu $sp, $sp, 64 # pop frame 275 .cfi_adjust_cfa_offset -64 276.endm 277 278 /* 279 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending 280 * exception is Thread::Current()->exception_ 281 */ 282.macro DELIVER_PENDING_EXCEPTION 283 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME # save callee saves for throw 284 la $t9, artDeliverPendingExceptionFromCode 285 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*) 286 move $a0, rSELF # pass Thread::Current 287.endm 288 289.macro RETURN_IF_NO_EXCEPTION 290 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_ 291 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 292 bnez $t0, 1f # success if no exception is pending 293 nop 294 jalr $zero, $ra 295 nop 2961: 297 DELIVER_PENDING_EXCEPTION 298.endm 299 300.macro RETURN_IF_ZERO 301 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 302 bnez $v0, 1f # success? 303 nop 304 jalr $zero, $ra # return on success 305 nop 3061: 307 DELIVER_PENDING_EXCEPTION 308.endm 309 310.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 311 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME 312 beqz $v0, 1f # success? 313 nop 314 jalr $zero, $ra # return on success 315 nop 3161: 317 DELIVER_PENDING_EXCEPTION 318.endm 319 320 /* 321 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_ 322 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be? 323 */ 324ENTRY art_quick_do_long_jump 325 LDu $f0, $f1, 0*8, $a1, $t1 326 LDu $f2, $f3, 1*8, $a1, $t1 327 LDu $f4, $f5, 2*8, $a1, $t1 328 LDu $f6, $f7, 3*8, $a1, $t1 329 LDu $f8, $f9, 4*8, $a1, $t1 330 LDu $f10, $f11, 5*8, $a1, $t1 331 LDu $f12, $f13, 6*8, $a1, $t1 332 LDu $f14, $f15, 7*8, $a1, $t1 333 LDu $f16, $f17, 8*8, $a1, $t1 334 LDu $f18, $f19, 9*8, $a1, $t1 335 LDu $f20, $f21, 10*8, $a1, $t1 336 LDu $f22, $f23, 11*8, $a1, $t1 337 LDu $f24, $f25, 12*8, $a1, $t1 338 LDu $f26, $f27, 13*8, $a1, $t1 339 LDu $f28, $f29, 14*8, $a1, $t1 340 LDu $f30, $f31, 15*8, $a1, $t1 341 342 .set push 343 .set nomacro 344 .set noat 345 lw $at, 4($a0) 346 .set pop 347 lw $v0, 8($a0) 348 lw $v1, 12($a0) 349 lw $a1, 20($a0) 350 lw $a2, 24($a0) 351 lw $a3, 28($a0) 352 lw $t0, 32($a0) 353 lw $t1, 36($a0) 354 lw $t2, 40($a0) 355 lw $t3, 44($a0) 356 lw $t4, 48($a0) 357 lw $t5, 52($a0) 358 lw $t6, 56($a0) 359 lw $t7, 60($a0) 360 lw $s0, 64($a0) 361 lw $s1, 68($a0) 362 lw $s2, 72($a0) 363 lw $s3, 76($a0) 364 lw $s4, 80($a0) 365 lw $s5, 84($a0) 366 lw $s6, 88($a0) 367 lw $s7, 92($a0) 368 lw $t8, 96($a0) 369 lw $t9, 100($a0) 370 lw $gp, 112($a0) 371 lw $sp, 116($a0) 372 lw $fp, 120($a0) 373 lw $ra, 124($a0) 374 lw $a0, 16($a0) 375 move $v0, $zero # clear result registers r0 and r1 376 jalr $zero, $ra # do long jump 377 move $v1, $zero 378END art_quick_do_long_jump 379 380 /* 381 * Called by managed code, saves most registers (forms basis of long jump context) and passes 382 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at 383 * the bottom of the thread. On entry a0 holds Throwable* 384 */ 385ENTRY art_quick_deliver_exception 386 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 387 la $t9, artDeliverExceptionFromCode 388 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*) 389 move $a1, rSELF # pass Thread::Current 390END art_quick_deliver_exception 391 392 /* 393 * Called by managed code to create and deliver a NullPointerException 394 */ 395 .extern artThrowNullPointerExceptionFromCode 396ENTRY art_quick_throw_null_pointer_exception 397 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 398 la $t9, artThrowNullPointerExceptionFromCode 399 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*) 400 move $a0, rSELF # pass Thread::Current 401END art_quick_throw_null_pointer_exception 402 403 /* 404 * Called by managed code to create and deliver an ArithmeticException 405 */ 406 .extern artThrowDivZeroFromCode 407ENTRY art_quick_throw_div_zero 408 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 409 la $t9, artThrowDivZeroFromCode 410 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*) 411 move $a0, rSELF # pass Thread::Current 412END art_quick_throw_div_zero 413 414 /* 415 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException 416 */ 417 .extern artThrowArrayBoundsFromCode 418ENTRY art_quick_throw_array_bounds 419 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 420 la $t9, artThrowArrayBoundsFromCode 421 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*) 422 move $a2, rSELF # pass Thread::Current 423END art_quick_throw_array_bounds 424 425 /* 426 * Called by managed code to create and deliver a StackOverflowError. 427 */ 428 .extern artThrowStackOverflowFromCode 429ENTRY art_quick_throw_stack_overflow 430 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 431 la $t9, artThrowStackOverflowFromCode 432 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*) 433 move $a0, rSELF # pass Thread::Current 434END art_quick_throw_stack_overflow 435 436 /* 437 * Called by managed code to create and deliver a NoSuchMethodError. 438 */ 439 .extern artThrowNoSuchMethodFromCode 440ENTRY art_quick_throw_no_such_method 441 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 442 la $t9, artThrowNoSuchMethodFromCode 443 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*) 444 move $a1, rSELF # pass Thread::Current 445END art_quick_throw_no_such_method 446 447 /* 448 * All generated callsites for interface invokes and invocation slow paths will load arguments 449 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain 450 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the 451 * stack and call the appropriate C helper. 452 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1. 453 * 454 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting 455 * of the target Method* in $v0 and method->code_ in $v1. 456 * 457 * If unsuccessful, the helper will return null/null. There will be a pending exception in the 458 * thread and we branch to another stub to deliver it. 459 * 460 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr 461 * pointing back to the original caller. 462 */ 463.macro INVOKE_TRAMPOLINE c_name, cxx_name 464 .extern \cxx_name 465ENTRY \c_name 466 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME # save callee saves in case allocation triggers GC 467 lw $a2, FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE+ARG_SLOT_SIZE($sp) # pass caller Method* 468 addiu $t0, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots) 469 move $a3, rSELF # pass Thread::Current 470 jal \cxx_name # (method_idx, this, caller, Thread*, $sp) 471 sw $t0, 16($sp) # pass $sp 472 move $a0, $v0 # save target Method* 473 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 474 beqz $v0, 1f 475 move $t9, $v1 # save $v0->code_ 476 jalr $zero, $t9 477 nop 4781: 479 DELIVER_PENDING_EXCEPTION 480END \c_name 481.endm 482 483INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline, artInvokeInterfaceTrampoline 484INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck 485 486INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck 487INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck 488INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck 489INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck 490 491 /* 492 * Invocation stub for quick code. 493 * On entry: 494 * a0 = method pointer 495 * a1 = argument array or null for no argument methods 496 * a2 = size of argument array in bytes 497 * a3 = (managed) thread pointer 498 * [sp + 16] = JValue* result 499 * [sp + 20] = shorty 500 */ 501ENTRY art_quick_invoke_stub 502 sw $a0, 0($sp) # save out a0 503 addiu $sp, $sp, -16 # spill s0, s1, fp, ra 504 .cfi_adjust_cfa_offset 16 505 sw $ra, 12($sp) 506 .cfi_rel_offset 31, 12 507 sw $fp, 8($sp) 508 .cfi_rel_offset 30, 8 509 sw $s1, 4($sp) 510 .cfi_rel_offset 17, 4 511 sw $s0, 0($sp) 512 .cfi_rel_offset 16, 0 513 move $fp, $sp # save sp in fp 514 .cfi_def_cfa_register 30 515 move $s1, $a3 # move managed thread pointer into s1 516 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval 517 addiu $t0, $a2, 4 # create space for method pointer in frame. 518 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes: 519 srl $t0, $t0, 4 # native calling convention only aligns to 8B, 520 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves. 521 addiu $a0, $sp, 4 # pass stack pointer + method ptr as dest for memcpy 522 jal memcpy # (dest, src, bytes) 523 addiu $sp, $sp, -16 # make space for argument slots for memcpy 524 addiu $sp, $sp, 16 # restore stack after memcpy 525 lw $a0, 16($fp) # restore method* 526 lw $a1, 4($sp) # copy arg value for a1 527 lw $a2, 8($sp) # copy arg value for a2 528 lw $a3, 12($sp) # copy arg value for a3 529 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code 530 jalr $t9 # call the method 531 sw $zero, 0($sp) # store null for method* at bottom of frame 532 move $sp, $fp # restore the stack 533 lw $s0, 0($sp) 534 .cfi_restore 16 535 lw $s1, 4($sp) 536 .cfi_restore 17 537 lw $fp, 8($sp) 538 .cfi_restore 30 539 lw $ra, 12($sp) 540 .cfi_restore 31 541 addiu $sp, $sp, 16 542 .cfi_adjust_cfa_offset -16 543 lw $t0, 16($sp) # get result pointer 544 lw $t1, 20($sp) # get shorty 545 lb $t1, 0($t1) # get result type char 546 li $t2, 68 # put char 'D' into t2 547 beq $t1, $t2, 1f # branch if result type char == 'D' 548 li $t3, 70 # put char 'F' into t3 549 beq $t1, $t3, 1f # branch if result type char == 'F' 550 sw $v0, 0($t0) # store the result 551 jalr $zero, $ra 552 sw $v1, 4($t0) # store the other half of the result 5531: 554 SDu $f0, $f1, 0, $t0, $t1 # store floating point result 555 jalr $zero, $ra 556 nop 557END art_quick_invoke_stub 558 559 /* 560 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on 561 * failure. 562 */ 563 .extern artHandleFillArrayDataFromCode 564ENTRY art_quick_handle_fill_data 565 lw $a2, 0($sp) # pass referrer's Method* 566 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC 567 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*) 568 move $a3, rSELF # pass Thread::Current 569 RETURN_IF_ZERO 570END art_quick_handle_fill_data 571 572 /* 573 * Entry from managed code that calls artLockObjectFromCode, may block for GC. 574 */ 575 .extern artLockObjectFromCode 576ENTRY art_quick_lock_object 577 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set 578 nop 579 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block 580 jal artLockObjectFromCode # (Object* obj, Thread*) 581 move $a1, rSELF # pass Thread::Current 582 RETURN_IF_ZERO 583END art_quick_lock_object 584 585 /* 586 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. 587 */ 588 .extern artUnlockObjectFromCode 589ENTRY art_quick_unlock_object 590 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set 591 nop 592 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC 593 jal artUnlockObjectFromCode # (Object* obj, Thread*) 594 move $a1, rSELF # pass Thread::Current 595 RETURN_IF_ZERO 596END art_quick_unlock_object 597 598 /* 599 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure. 600 */ 601 .extern artThrowClassCastException 602ENTRY art_quick_check_cast 603 addiu $sp, $sp, -16 604 .cfi_adjust_cfa_offset 16 605 sw $ra, 12($sp) 606 .cfi_rel_offset 31, 12 607 sw $t9, 8($sp) 608 sw $a1, 4($sp) 609 sw $a0, 0($sp) 610 jal artIsAssignableFromCode 611 addiu $sp, $sp, -16 # reserve argument slots on the stack 612 addiu $sp, $sp, 16 613 beqz $v0, .Lthrow_class_cast_exception 614 lw $ra, 12($sp) 615 jalr $zero, $ra 616 addiu $sp, $sp, 16 617 .cfi_adjust_cfa_offset -16 618.Lthrow_class_cast_exception: 619 lw $t9, 8($sp) 620 lw $a1, 4($sp) 621 lw $a0, 0($sp) 622 addiu $sp, $sp, 16 623 .cfi_adjust_cfa_offset -16 624 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 625 la $t9, artThrowClassCastException 626 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*) 627 move $a2, rSELF # pass Thread::Current 628END art_quick_check_cast 629 630 /* 631 * Entry from managed code for array put operations of objects where the value being stored 632 * needs to be checked for compatibility. 633 * a0 = array, a1 = index, a2 = value 634 */ 635ENTRY art_quick_aput_obj_with_null_and_bound_check 636 bnez $a0, .Lart_quick_aput_obj_with_bound_check_gp_set 637 nop 638 b .Lart_quick_throw_null_pointer_exception_gp_set 639 nop 640END art_quick_aput_obj_with_null_and_bound_check 641 642ENTRY art_quick_aput_obj_with_bound_check 643 lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0) 644 sltu $t1, $a1, $t0 645 bnez $t1, .Lart_quick_aput_obj_gp_set 646 nop 647 move $a0, $a1 648 b .Lart_quick_throw_array_bounds_gp_set 649 move $a1, $t0 650END art_quick_aput_obj_with_bound_check 651 652ENTRY art_quick_aput_obj 653 beqz $a2, .Ldo_aput_null 654 nop 655 lw $t0, MIRROR_OBJECT_CLASS_OFFSET($a0) 656 lw $t1, MIRROR_OBJECT_CLASS_OFFSET($a2) 657 lw $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET($t0) 658 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability 659 nop 660.Ldo_aput: 661 sll $a1, $a1, 2 662 add $t0, $a0, $a1 663 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0) 664 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF) 665 srl $t1, $a0, 7 666 add $t1, $t1, $t0 667 sb $t0, ($t1) 668 jalr $zero, $ra 669 nop 670.Ldo_aput_null: 671 sll $a1, $a1, 2 672 add $t0, $a0, $a1 673 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0) 674 jalr $zero, $ra 675 nop 676.Lcheck_assignability: 677 addiu $sp, $sp, -32 678 .cfi_adjust_cfa_offset 32 679 sw $ra, 28($sp) 680 .cfi_rel_offset 31, 28 681 sw $t9, 12($sp) 682 sw $a2, 8($sp) 683 sw $a1, 4($sp) 684 sw $a0, 0($sp) 685 move $a1, $t1 686 move $a0, $t0 687 jal artIsAssignableFromCode # (Class*, Class*) 688 addiu $sp, $sp, -16 # reserve argument slots on the stack 689 addiu $sp, $sp, 16 690 lw $ra, 28($sp) 691 lw $t9, 12($sp) 692 lw $a2, 8($sp) 693 lw $a1, 4($sp) 694 lw $a0, 0($sp) 695 addiu $sp, 32 696 .cfi_adjust_cfa_offset -32 697 bnez $v0, .Ldo_aput 698 nop 699 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 700 move $a1, $a2 701 la $t9, artThrowArrayStoreException 702 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*) 703 move $a2, rSELF # pass Thread::Current 704END art_quick_aput_obj 705 706 /* 707 * Called by managed code to resolve a static field and load a boolean primitive value. 708 */ 709 .extern artGetBooleanStaticFromCode 710ENTRY art_quick_get_boolean_static 711 lw $a1, 0($sp) # pass referrer's Method* 712 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 713 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 714 move $a2, rSELF # pass Thread::Current 715 RETURN_IF_NO_EXCEPTION 716END art_quick_get_boolean_static 717 /* 718 * Called by managed code to resolve a static field and load a byte primitive value. 719 */ 720 .extern artGetByteStaticFromCode 721ENTRY art_quick_get_byte_static 722 lw $a1, 0($sp) # pass referrer's Method* 723 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 724 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 725 move $a2, rSELF # pass Thread::Current 726 RETURN_IF_NO_EXCEPTION 727END art_quick_get_byte_static 728 729 /* 730 * Called by managed code to resolve a static field and load a char primitive value. 731 */ 732 .extern artGetCharStaticFromCode 733ENTRY art_quick_get_char_static 734 lw $a1, 0($sp) # pass referrer's Method* 735 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 736 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 737 move $a2, rSELF # pass Thread::Current 738 RETURN_IF_NO_EXCEPTION 739END art_quick_get_char_static 740 /* 741 * Called by managed code to resolve a static field and load a short primitive value. 742 */ 743 .extern artGetShortStaticFromCode 744ENTRY art_quick_get_short_static 745 lw $a1, 0($sp) # pass referrer's Method* 746 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 747 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 748 move $a2, rSELF # pass Thread::Current 749 RETURN_IF_NO_EXCEPTION 750END art_quick_get_short_static 751 752 /* 753 * Called by managed code to resolve a static field and load a 32-bit primitive value. 754 */ 755 .extern artGet32StaticFromCode 756ENTRY art_quick_get32_static 757 lw $a1, 0($sp) # pass referrer's Method* 758 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 759 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 760 move $a2, rSELF # pass Thread::Current 761 RETURN_IF_NO_EXCEPTION 762END art_quick_get32_static 763 764 /* 765 * Called by managed code to resolve a static field and load a 64-bit primitive value. 766 */ 767 .extern artGet64StaticFromCode 768ENTRY art_quick_get64_static 769 lw $a1, 0($sp) # pass referrer's Method* 770 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 771 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 772 move $a2, rSELF # pass Thread::Current 773 RETURN_IF_NO_EXCEPTION 774END art_quick_get64_static 775 776 /* 777 * Called by managed code to resolve a static field and load an object reference. 778 */ 779 .extern artGetObjStaticFromCode 780ENTRY art_quick_get_obj_static 781 lw $a1, 0($sp) # pass referrer's Method* 782 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 783 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*) 784 move $a2, rSELF # pass Thread::Current 785 RETURN_IF_NO_EXCEPTION 786END art_quick_get_obj_static 787 788 /* 789 * Called by managed code to resolve an instance field and load a boolean primitive value. 790 */ 791 .extern artGetBooleanInstanceFromCode 792ENTRY art_quick_get_boolean_instance 793 lw $a2, 0($sp) # pass referrer's Method* 794 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 795 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*) 796 move $a3, rSELF # pass Thread::Current 797 RETURN_IF_NO_EXCEPTION 798END art_quick_get_boolean_instance 799 /* 800 * Called by managed code to resolve an instance field and load a byte primitive value. 801 */ 802 .extern artGetByteInstanceFromCode 803ENTRY art_quick_get_byte_instance 804 lw $a2, 0($sp) # pass referrer's Method* 805 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 806 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*) 807 move $a3, rSELF # pass Thread::Current 808 RETURN_IF_NO_EXCEPTION 809END art_quick_get_byte_instance 810 811 /* 812 * Called by managed code to resolve an instance field and load a char primitive value. 813 */ 814 .extern artGetCharInstanceFromCode 815ENTRY art_quick_get_char_instance 816 lw $a2, 0($sp) # pass referrer's Method* 817 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 818 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*) 819 move $a3, rSELF # pass Thread::Current 820 RETURN_IF_NO_EXCEPTION 821END art_quick_get_char_instance 822 /* 823 * Called by managed code to resolve an instance field and load a short primitive value. 824 */ 825 .extern artGetShortInstanceFromCode 826ENTRY art_quick_get_short_instance 827 lw $a2, 0($sp) # pass referrer's Method* 828 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 829 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*) 830 move $a3, rSELF # pass Thread::Current 831 RETURN_IF_NO_EXCEPTION 832END art_quick_get_short_instance 833 834 /* 835 * Called by managed code to resolve an instance field and load a 32-bit primitive value. 836 */ 837 .extern artGet32InstanceFromCode 838ENTRY art_quick_get32_instance 839 lw $a2, 0($sp) # pass referrer's Method* 840 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 841 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*) 842 move $a3, rSELF # pass Thread::Current 843 RETURN_IF_NO_EXCEPTION 844END art_quick_get32_instance 845 846 /* 847 * Called by managed code to resolve an instance field and load a 64-bit primitive value. 848 */ 849 .extern artGet64InstanceFromCode 850ENTRY art_quick_get64_instance 851 lw $a2, 0($sp) # pass referrer's Method* 852 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 853 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*) 854 move $a3, rSELF # pass Thread::Current 855 RETURN_IF_NO_EXCEPTION 856END art_quick_get64_instance 857 858 /* 859 * Called by managed code to resolve an instance field and load an object reference. 860 */ 861 .extern artGetObjInstanceFromCode 862ENTRY art_quick_get_obj_instance 863 lw $a2, 0($sp) # pass referrer's Method* 864 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 865 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*) 866 move $a3, rSELF # pass Thread::Current 867 RETURN_IF_NO_EXCEPTION 868END art_quick_get_obj_instance 869 870 /* 871 * Called by managed code to resolve a static field and store a 8-bit primitive value. 872 */ 873 .extern artSet8StaticFromCode 874ENTRY art_quick_set8_static 875 lw $a2, 0($sp) # pass referrer's Method* 876 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 877 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*) 878 move $a3, rSELF # pass Thread::Current 879 RETURN_IF_ZERO 880END art_quick_set8_static 881 882 /* 883 * Called by managed code to resolve a static field and store a 16-bit primitive value. 884 */ 885 .extern artSet16StaticFromCode 886ENTRY art_quick_set16_static 887 lw $a2, 0($sp) # pass referrer's Method* 888 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 889 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*, $sp) 890 move $a3, rSELF # pass Thread::Current 891 RETURN_IF_ZERO 892END art_quick_set16_static 893 894 /* 895 * Called by managed code to resolve a static field and store a 32-bit primitive value. 896 */ 897 .extern artSet32StaticFromCode 898ENTRY art_quick_set32_static 899 lw $a2, 0($sp) # pass referrer's Method* 900 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 901 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*) 902 move $a3, rSELF # pass Thread::Current 903 RETURN_IF_ZERO 904END art_quick_set32_static 905 906 /* 907 * Called by managed code to resolve a static field and store a 64-bit primitive value. 908 */ 909 .extern artSet64StaticFromCode 910ENTRY art_quick_set64_static 911 lw $a1, 0($sp) # pass referrer's Method* 912 # 64 bit new_val is in a2:a3 pair 913 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 914 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*) 915 sw rSELF, 16($sp) # pass Thread::Current 916 RETURN_IF_ZERO 917END art_quick_set64_static 918 919 /* 920 * Called by managed code to resolve a static field and store an object reference. 921 */ 922 .extern artSetObjStaticFromCode 923ENTRY art_quick_set_obj_static 924 lw $a2, 0($sp) # pass referrer's Method* 925 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 926 move $a3, rSELF # pass Thread::Current 927 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*) 928 RETURN_IF_ZERO 929END art_quick_set_obj_static 930 931 /* 932 * Called by managed code to resolve an instance field and store a 8-bit primitive value. 933 */ 934 .extern artSet8InstanceFromCode 935ENTRY art_quick_set8_instance 936 lw $a3, 0($sp) # pass referrer's Method* 937 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 938 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*) 939 sw rSELF, 16($sp) # pass Thread::Current 940 RETURN_IF_ZERO 941END art_quick_set8_instance 942 943 /* 944 * Called by managed code to resolve an instance field and store a 16-bit primitive value. 945 */ 946 .extern artSet16InstanceFromCode 947ENTRY art_quick_set16_instance 948 lw $a3, 0($sp) # pass referrer's Method* 949 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 950 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*) 951 sw rSELF, 16($sp) # pass Thread::Current 952 RETURN_IF_ZERO 953END art_quick_set16_instance 954 955 /* 956 * Called by managed code to resolve an instance field and store a 32-bit primitive value. 957 */ 958 .extern artSet32InstanceFromCode 959ENTRY art_quick_set32_instance 960 lw $a3, 0($sp) # pass referrer's Method* 961 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 962 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*) 963 sw rSELF, 16($sp) # pass Thread::Current 964 RETURN_IF_ZERO 965END art_quick_set32_instance 966 967 /* 968 * Called by managed code to resolve an instance field and store a 64-bit primitive value. 969 */ 970 .extern artSet64InstanceFromCode 971ENTRY art_quick_set64_instance 972 lw $t1, 0($sp) # load referrer's Method* 973 # 64 bit new_val is in a2:a3 pair 974 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 975 sw rSELF, 20($sp) # pass Thread::Current 976 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*) 977 sw $t1, 16($sp) # pass referrer's Method* 978 RETURN_IF_ZERO 979END art_quick_set64_instance 980 981 /* 982 * Called by managed code to resolve an instance field and store an object reference. 983 */ 984 .extern artSetObjInstanceFromCode 985ENTRY art_quick_set_obj_instance 986 lw $a3, 0($sp) # pass referrer's Method* 987 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 988 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*) 989 sw rSELF, 16($sp) # pass Thread::Current 990 RETURN_IF_ZERO 991END art_quick_set_obj_instance 992 993// Macro to facilitate adding new allocation entrypoints. 994.macro ONE_ARG_DOWNCALL name, entrypoint, return 995 .extern \entrypoint 996ENTRY \name 997 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 998 jal \entrypoint 999 move $a1, rSELF # pass Thread::Current 1000 \return 1001END \name 1002.endm 1003 1004.macro TWO_ARG_DOWNCALL name, entrypoint, return 1005 .extern \entrypoint 1006ENTRY \name 1007 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 1008 jal \entrypoint 1009 move $a2, rSELF # pass Thread::Current 1010 \return 1011END \name 1012.endm 1013 1014.macro THREE_ARG_DOWNCALL name, entrypoint, return 1015 .extern \entrypoint 1016ENTRY \name 1017 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 1018 jal \entrypoint 1019 move $a3, rSELF # pass Thread::Current 1020 \return 1021END \name 1022.endm 1023 1024.macro FOUR_ARG_DOWNCALL name, entrypoint, return 1025 .extern \entrypoint 1026ENTRY \name 1027 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC 1028 jal \entrypoint 1029 sw rSELF, 16($sp) # pass Thread::Current 1030 \return 1031END \name 1032.endm 1033 1034// Generate the allocation entrypoints for each allocator. 1035GENERATE_ALL_ALLOC_ENTRYPOINTS 1036 1037 /* 1038 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an 1039 * exception on error. On success the String is returned. A0 holds the string index. The fast 1040 * path check for hit in strings cache has already been performed. 1041 */ 1042ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1043 1044 /* 1045 * Entry from managed code when uninitialized static storage, this stub will run the class 1046 * initializer and deliver the exception on error. On success the static storage base is 1047 * returned. 1048 */ 1049ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1050 1051 /* 1052 * Entry from managed code when dex cache misses for a type_idx. 1053 */ 1054ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1055 1056 /* 1057 * Entry from managed code when type_idx needs to be checked for access and dex cache may also 1058 * miss. 1059 */ 1060ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER 1061 1062 /* 1063 * Called by managed code when the value in rSUSPEND has been decremented to 0. 1064 */ 1065 .extern artTestSuspendFromCode 1066ENTRY art_quick_test_suspend 1067 lh $a0, THREAD_FLAGS_OFFSET(rSELF) 1068 bnez $a0, 1f 1069 addiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL 1070 jalr $zero, $ra 1071 nop 10721: 1073 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves for stack crawl 1074 jal artTestSuspendFromCode # (Thread*) 1075 move $a0, rSELF 1076 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN 1077END art_quick_test_suspend 1078 1079 /* 1080 * Called by managed code that is attempting to call a method on a proxy class. On entry 1081 * r0 holds the proxy method; r1, r2 and r3 may contain arguments. 1082 */ 1083 .extern artQuickProxyInvokeHandler 1084ENTRY art_quick_proxy_invoke_handler 1085 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0 1086 move $a2, rSELF # pass Thread::Current 1087 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP) 1088 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots) 1089 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_ 1090 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1091 bnez $t0, 1f 1092 # don't care if $v0 and/or $v1 are modified, when exception branch taken 1093 MTD $v0, $v1, $f0, $f1 # move float value to return value 1094 jalr $zero, $ra 1095 nop 10961: 1097 DELIVER_PENDING_EXCEPTION 1098END art_quick_proxy_invoke_handler 1099 1100 /* 1101 * Called to resolve an imt conflict. t0 is a hidden argument that holds the target method's 1102 * dex method index. 1103 */ 1104ENTRY art_quick_imt_conflict_trampoline 1105 lw $a0, 0($sp) # load caller Method* 1106 lw $a0, ART_METHOD_DEX_CACHE_METHODS_OFFSET($a0) # load dex_cache_resolved_methods 1107 sll $t0, 2 # convert target method offset to bytes 1108 add $a0, $t0 # get address of target method 1109 lw $a0, MIRROR_OBJECT_ARRAY_DATA_OFFSET($a0) # load the target method 1110 la $t9, art_quick_invoke_interface_trampoline 1111 jalr $zero, $t9 1112END art_quick_imt_conflict_trampoline 1113 1114 .extern artQuickResolutionTrampoline 1115ENTRY art_quick_resolution_trampoline 1116 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1117 move $a2, rSELF # pass Thread::Current 1118 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP) 1119 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots) 1120 beqz $v0, 1f 1121 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0 1122 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1123 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer 1124 jalr $zero, $t9 # tail call to method 1125 nop 11261: 1127 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1128 DELIVER_PENDING_EXCEPTION 1129END art_quick_resolution_trampoline 1130 1131 .extern artQuickGenericJniTrampoline 1132 .extern artQuickGenericJniEndTrampoline 1133ENTRY art_quick_generic_jni_trampoline 1134 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0 1135 move $s8, $sp # save $sp to $s8 1136 move $s3, $gp # save $gp to $s3 1137 1138 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP) 1139 move $a0, rSELF # pass Thread::Current 1140 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots) 1141 jal artQuickGenericJniTrampoline # (Thread*, SP) 1142 addiu $sp, $sp, -5120 # reserve space on the stack 1143 1144 # The C call will have registered the complete save-frame on success. 1145 # The result of the call is: 1146 # v0: ptr to native code, 0 on error. 1147 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here. 1148 beq $v0, $zero, 1f # check entry error 1149 move $t9, $v0 # save the code ptr 1150 move $sp, $v1 # release part of the alloca 1151 1152 # Load parameters from stack into registers 1153 lw $a0, 0($sp) 1154 lw $a1, 4($sp) 1155 lw $a2, 8($sp) 1156 1157 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine. 1158 jalr $t9 # native call 1159 lw $a3, 12($sp) 1160 addiu $sp, $sp, 16 # remove arg slots 1161 1162 move $gp, $s3 # restore $gp from $s3 1163 1164 # result sign extension is handled in C code 1165 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f) 1166 move $a0, rSELF # pass Thread::Current 1167 move $a2, $v0 # pass result 1168 move $a3, $v1 1169 addiu $sp, $sp, -24 # reserve arg slots 1170 jal artQuickGenericJniEndTrampoline 1171 s.d $f0, 16($sp) # pass result_f 1172 1173 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_ 1174 bne $t0, $zero, 1f # check for pending exceptions 1175 1176 move $sp, $s8 # tear down the alloca 1177 1178 # tear dpown the callee-save frame 1179 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1180 1181 MTD $v0, $v1, $f0, $f1 # move float value to return value 1182 jalr $zero, $ra 1183 nop 1184 11851: 1186 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) 1187 # This will create a new save-all frame, required by the runtime. 1188 DELIVER_PENDING_EXCEPTION 1189END art_quick_generic_jni_trampoline 1190 1191 .extern artQuickToInterpreterBridge 1192ENTRY art_quick_to_interpreter_bridge 1193 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1194 move $a1, rSELF # pass Thread::Current 1195 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP) 1196 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots) 1197 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_ 1198 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1199 bnez $t0, 1f 1200 # don't care if $v0 and/or $v1 are modified, when exception branch taken 1201 MTD $v0, $v1, $f0, $f1 # move float value to return value 1202 jalr $zero, $ra 1203 nop 12041: 1205 DELIVER_PENDING_EXCEPTION 1206END art_quick_to_interpreter_bridge 1207 1208 /* 1209 * Routine that intercepts method calls and returns. 1210 */ 1211 .extern artInstrumentationMethodEntryFromCode 1212 .extern artInstrumentationMethodExitFromCode 1213ENTRY art_quick_instrumentation_entry 1214 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1215 sw $a0, 28($sp) # save arg0 in free arg slot 1216 move $a3, $ra # pass $ra 1217 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, LR) 1218 move $a2, rSELF # pass Thread::Current 1219 move $t9, $v0 # $t9 holds reference to code 1220 lw $a0, 28($sp) # restore arg0 from free arg slot 1221 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME 1222 jalr $t9 # call method 1223 nop 1224END art_quick_instrumentation_entry 1225 /* intentional fallthrough */ 1226 .global art_quick_instrumentation_exit 1227art_quick_instrumentation_exit: 1228 .cfi_startproc 1229 addiu $t9, $ra, 4 # put current address into $t9 to rebuild $gp 1230 .cpload $t9 1231 move $ra, $zero # link register is to here, so clobber with 0 for later checks 1232 1233 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME 1234 addiu $sp, $sp, -16 # allocate temp storage on the stack 1235 .cfi_adjust_cfa_offset 16 1236 sw $v0, ARG_SLOT_SIZE+12($sp) 1237 .cfi_rel_offset 2, ARG_SLOT_SIZE+12 1238 sw $v1, ARG_SLOT_SIZE+8($sp) 1239 .cfi_rel_offset 3, ARG_SLOT_SIZE+8 1240 s.d $f0, ARG_SLOT_SIZE($sp) 1241 s.d $f0, 16($sp) # pass fpr result 1242 move $a2, $v0 # pass gpr result 1243 move $a3, $v1 1244 addiu $a1, $sp, ARG_SLOT_SIZE+16 # pass $sp (remove arg slots and temp storage) 1245 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res) 1246 move $a0, rSELF # pass Thread::Current 1247 move $t9, $v0 # set aside returned link register 1248 move $ra, $v1 # set link register for deoptimization 1249 lw $v0, ARG_SLOT_SIZE+12($sp) # restore return values 1250 lw $v1, ARG_SLOT_SIZE+8($sp) 1251 l.d $f0, ARG_SLOT_SIZE($sp) 1252 jalr $zero, $t9 # return 1253 addiu $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16 # restore stack 1254 .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16) 1255END art_quick_instrumentation_exit 1256 1257 /* 1258 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization 1259 * will long jump to the upcall with a special exception of -1. 1260 */ 1261 .extern artDeoptimize 1262ENTRY art_quick_deoptimize 1263 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME 1264 jal artDeoptimize # artDeoptimize(Thread*) 1265 # Returns caller method's frame size. 1266 move $a0, rSELF # pass Thread::current 1267END art_quick_deoptimize 1268 1269 /* 1270 * Long integer shift. This is different from the generic 32/64-bit 1271 * binary operations because vAA/vBB are 64-bit but vCC (the shift 1272 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low 1273 * 6 bits. 1274 * On entry: 1275 * $a0: low word 1276 * $a1: high word 1277 * $a2: shift count 1278 */ 1279ENTRY_NO_GP art_quick_shl_long 1280 /* shl-long vAA, vBB, vCC */ 1281 sll $v0, $a0, $a2 # rlo<- alo << (shift&31) 1282 not $v1, $a2 # rhi<- 31-shift (shift is 5b) 1283 srl $a0, 1 1284 srl $a0, $v1 # alo<- alo >> (32-(shift&31)) 1285 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31) 1286 andi $a2, 0x20 # shift< shift & 0x20 1287 beqz $a2, 1f 1288 or $v1, $a0 # rhi<- rhi | alo 1289 1290 move $v1, $v0 # rhi<- rlo (if shift&0x20) 1291 move $v0, $zero # rlo<- 0 (if shift&0x20) 1292 12931: jalr $zero, $ra 1294 nop 1295END art_quick_shl_long 1296 1297 /* 1298 * Long integer shift. This is different from the generic 32/64-bit 1299 * binary operations because vAA/vBB are 64-bit but vCC (the shift 1300 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low 1301 * 6 bits. 1302 * On entry: 1303 * $a0: low word 1304 * $a1: high word 1305 * $a2: shift count 1306 */ 1307ENTRY_NO_GP art_quick_shr_long 1308 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31) 1309 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31) 1310 sra $a3, $a1, 31 # $a3<- sign(ah) 1311 not $a0, $a2 # alo<- 31-shift (shift is 5b) 1312 sll $a1, 1 1313 sll $a1, $a0 # ahi<- ahi << (32-(shift&31)) 1314 andi $a2, 0x20 # shift & 0x20 1315 beqz $a2, 1f 1316 or $v0, $a1 # rlo<- rlo | ahi 1317 1318 move $v0, $v1 # rlo<- rhi (if shift&0x20) 1319 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20) 1320 13211: jalr $zero, $ra 1322 nop 1323END art_quick_shr_long 1324 1325 /* 1326 * Long integer shift. This is different from the generic 32/64-bit 1327 * binary operations because vAA/vBB are 64-bit but vCC (the shift 1328 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low 1329 * 6 bits. 1330 * On entry: 1331 * r0: low word 1332 * r1: high word 1333 * r2: shift count 1334 */ 1335 /* ushr-long vAA, vBB, vCC */ 1336ENTRY_NO_GP art_quick_ushr_long 1337 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31) 1338 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31) 1339 not $a0, $a2 # alo<- 31-shift (shift is 5b) 1340 sll $a1, 1 1341 sll $a1, $a0 # ahi<- ahi << (32-(shift&31)) 1342 andi $a2, 0x20 # shift & 0x20 1343 beqz $a2, 1f 1344 or $v0, $a1 # rlo<- rlo | ahi 1345 1346 move $v0, $v1 # rlo<- rhi (if shift&0x20) 1347 move $v1, $zero # rhi<- 0 (if shift&0x20) 1348 13491: jalr $zero, $ra 1350 nop 1351END art_quick_ushr_long 1352 1353UNIMPLEMENTED art_quick_indexof 1354UNIMPLEMENTED art_quick_string_compareto 1355