quick_entrypoints_mips64.S revision 0747466fca310eedea5fc49e37d54f240a0b3c0f
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_mips64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21    .set noreorder
22    .balign 16
23
24    /* Deliver the given exception */
25    .extern artDeliverExceptionFromCode
26    /* Deliver an exception pending on a thread */
27    .extern artDeliverPendingExceptionFromCode
28
29    /*
30     * Macro that sets up $gp and stores the previous $gp value to $t8.
31     * This macro modifies v1 and t8.
32     */
33.macro SETUP_GP
34    move $v1, $ra
35    bal 1f
36    nop
371:
38    .cpsetup $ra, $t8, 1b
39    move $ra, $v1
40.endm
41
42    /*
43     * Macro that sets up the callee save frame to conform with
44     * Runtime::CreateCalleeSaveMethod(kSaveAll)
45     * callee-save: padding + $f24-$f31 + $s0-$s7 + $gp + $ra + $s8 = 19 total + 1x8 bytes padding
46     */
47.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
48    daddiu $sp, $sp, -160
49    .cfi_adjust_cfa_offset 160
50
51     // Ugly compile-time check, but we only have the preprocessor.
52#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 160)
53#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
54#endif
55
56    sd     $ra, 152($sp)
57    .cfi_rel_offset 31, 152
58    sd     $s8, 144($sp)
59    .cfi_rel_offset 30, 144
60    sd     $t8, 136($sp)           # t8 holds caller's gp, now save it to the stack.
61    .cfi_rel_offset 28, 136        # Value from gp is pushed, so set the cfi offset accordingly.
62    sd     $s7, 128($sp)
63    .cfi_rel_offset 23, 128
64    sd     $s6, 120($sp)
65    .cfi_rel_offset 22, 120
66    sd     $s5, 112($sp)
67    .cfi_rel_offset 21, 112
68    sd     $s4, 104($sp)
69    .cfi_rel_offset 20, 104
70    sd     $s3,  96($sp)
71    .cfi_rel_offset 19, 96
72    sd     $s2,  88($sp)
73    .cfi_rel_offset 18, 88
74    sd     $s1,  80($sp)
75    .cfi_rel_offset 17, 80
76    sd     $s0,  72($sp)
77    .cfi_rel_offset 16, 72
78
79    // FP callee-saves
80    s.d    $f31, 64($sp)
81    s.d    $f30, 56($sp)
82    s.d    $f29, 48($sp)
83    s.d    $f28, 40($sp)
84    s.d    $f27, 32($sp)
85    s.d    $f26, 24($sp)
86    s.d    $f25, 16($sp)
87    s.d    $f24,  8($sp)
88
89    # load appropriate callee-save-method
90    ld      $t1, %got(_ZN3art7Runtime9instance_E)($gp)
91    ld      $t1, 0($t1)
92    ld      $t1, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t1)
93    sd      $t1, 0($sp)                                # Place ArtMethod* at bottom of stack.
94    sd      $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
95.endm
96
97    /*
98     * Macro that sets up the callee save frame to conform with
99     * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes
100     * non-moving GC.
101     * Does not include rSUSPEND or rSELF
102     * callee-save: padding + $s2-$s7 + $gp + $ra + $s8 = 9 total + 1x8 bytes padding
103     */
104.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
105    daddiu $sp, $sp, -80
106    .cfi_adjust_cfa_offset 80
107
108    // Ugly compile-time check, but we only have the preprocessor.
109#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 80)
110#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
111#endif
112
113    sd     $ra, 72($sp)
114    .cfi_rel_offset 31, 72
115    sd     $s8, 64($sp)
116    .cfi_rel_offset 30, 64
117    sd     $t8, 56($sp)            # t8 holds caller's gp, now save it to the stack.
118    .cfi_rel_offset 28, 56         # Value from gp is pushed, so set the cfi offset accordingly.
119    sd     $s7, 48($sp)
120    .cfi_rel_offset 23, 48
121    sd     $s6, 40($sp)
122    .cfi_rel_offset 22, 40
123    sd     $s5, 32($sp)
124    .cfi_rel_offset 21, 32
125    sd     $s4, 24($sp)
126    .cfi_rel_offset 20, 24
127    sd     $s3, 16($sp)
128    .cfi_rel_offset 19, 16
129    sd     $s2, 8($sp)
130    .cfi_rel_offset 18, 8
131    # load appropriate callee-save-method
132    ld      $t1, %got(_ZN3art7Runtime9instance_E)($gp)
133    ld      $t1, 0($t1)
134    ld      $t1, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t1)
135    sd      $t1, 0($sp)                                # Place Method* at bottom of stack.
136    sd      $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
137.endm
138
139.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
140    ld     $ra, 72($sp)
141    .cfi_restore 31
142    ld     $s8, 64($sp)
143    .cfi_restore 30
144    ld     $t8, 56($sp)            # Restore gp back to it's temp storage.
145    .cfi_restore 28
146    ld     $s7, 48($sp)
147    .cfi_restore 23
148    ld     $s6, 40($sp)
149    .cfi_restore 22
150    ld     $s5, 32($sp)
151    .cfi_restore 21
152    ld     $s4, 24($sp)
153    .cfi_restore 20
154    ld     $s3, 16($sp)
155    .cfi_restore 19
156    ld     $s2, 8($sp)
157    .cfi_restore 18
158    daddiu $sp, $sp, 80
159    .cfi_adjust_cfa_offset -80
160    .cpreturn
161.endm
162
163.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
164    ld     $ra, 72($sp)
165    .cfi_restore 31
166    ld     $s8, 64($sp)
167    .cfi_restore 30
168    ld     $t8, 56($sp)            # Restore gp back to it's temp storage.
169    .cfi_restore 28
170    ld     $s7, 48($sp)
171    .cfi_restore 23
172    ld     $s6, 40($sp)
173    .cfi_restore 22
174    ld     $s5, 32($sp)
175    .cfi_restore 21
176    ld     $s4, 24($sp)
177    .cfi_restore 20
178    ld     $s3, 16($sp)
179    .cfi_restore 19
180    ld     $s2, 8($sp)
181    .cfi_restore 18
182    .cpreturn
183    jalr   $zero, $ra
184    daddiu $sp, $sp, 80
185    .cfi_adjust_cfa_offset -80
186.endm
187
188// This assumes the top part of these stack frame types are identical.
189#define REFS_AND_ARGS_MINUS_REFS_SIZE (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
190
191.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
192    daddiu  $sp, $sp, -208
193    .cfi_adjust_cfa_offset 208
194
195    // Ugly compile-time check, but we only have the preprocessor.
196#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 208)
197#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
198#endif
199
200    sd     $ra, 200($sp)           # = kQuickCalleeSaveFrame_RefAndArgs_LrOffset
201    .cfi_rel_offset 31, 200
202    sd     $s8, 192($sp)
203    .cfi_rel_offset 30, 192
204    sd     $t8, 184($sp)           # t8 holds caller's gp, now save it to the stack.
205    .cfi_rel_offset 28, 184        # Value from gp is pushed, so set the cfi offset accordingly.
206    sd     $s7, 176($sp)
207    .cfi_rel_offset 23, 176
208    sd     $s6, 168($sp)
209    .cfi_rel_offset 22, 168
210    sd     $s5, 160($sp)
211    .cfi_rel_offset 21, 160
212    sd     $s4, 152($sp)
213    .cfi_rel_offset 20, 152
214    sd     $s3, 144($sp)
215    .cfi_rel_offset 19, 144
216    sd     $s2, 136($sp)
217    .cfi_rel_offset 18, 136
218
219    sd     $a7, 128($sp)
220    .cfi_rel_offset 11, 128
221    sd     $a6, 120($sp)
222    .cfi_rel_offset 10, 120
223    sd     $a5, 112($sp)
224    .cfi_rel_offset 9, 112
225    sd     $a4, 104($sp)
226    .cfi_rel_offset 8, 104
227    sd     $a3,  96($sp)
228    .cfi_rel_offset 7, 96
229    sd     $a2,  88($sp)
230    .cfi_rel_offset 6, 88
231    sd     $a1,  80($sp)           # = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset
232    .cfi_rel_offset 5, 80
233
234    s.d    $f19, 72($sp)
235    s.d    $f18, 64($sp)
236    s.d    $f17, 56($sp)
237    s.d    $f16, 48($sp)
238    s.d    $f15, 40($sp)
239    s.d    $f14, 32($sp)
240    s.d    $f13, 24($sp)           # = kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset
241    s.d    $f12, 16($sp)           # This isn't necessary to store.
242    # 1x8 bytes padding + Method*
243.endm
244
245    /*
246     * Macro that sets up the callee save frame to conform with
247     * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes
248     * non-moving GC.
249     * callee-save: padding + $f12-$f19 + $a1-$a7 + $s2-$s7 + $gp + $ra + $s8 = 24 total + 1 words padding + Method*
250     */
251.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
252    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
253    # load appropriate callee-save-method
254    ld      $t1, %got(_ZN3art7Runtime9instance_E)($gp)
255    ld      $t1, 0($t1)
256    ld      $t1, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t1)
257    sd      $t1, 0($sp)                                # Place Method* at bottom of stack.
258    sd      $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
259.endm
260
261.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
262    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
263    sd      $a0, 0($sp)                                # Place Method* at bottom of stack.
264    sd      $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)  # Place sp in Thread::Current()->top_quick_frame.
265.endm
266
267.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
268    ld     $ra, 200($sp)
269    .cfi_restore 31
270    ld     $s8, 192($sp)
271    .cfi_restore 30
272    ld     $t8, 184($sp)           # Restore gp back to it's temp storage.
273    .cfi_restore 28
274    ld     $s7, 176($sp)
275    .cfi_restore 23
276    ld     $s6, 168($sp)
277    .cfi_restore 22
278    ld     $s5, 160($sp)
279    .cfi_restore 21
280    ld     $s4, 152($sp)
281    .cfi_restore 20
282    ld     $s3, 144($sp)
283    .cfi_restore 19
284    ld     $s2, 136($sp)
285    .cfi_restore 18
286
287    ld     $a7, 128($sp)
288    .cfi_restore 11
289    ld     $a6, 120($sp)
290    .cfi_restore 10
291    ld     $a5, 112($sp)
292    .cfi_restore 9
293    ld     $a4, 104($sp)
294    .cfi_restore 8
295    ld     $a3,  96($sp)
296    .cfi_restore 7
297    ld     $a2,  88($sp)
298    .cfi_restore 6
299    ld     $a1,  80($sp)
300    .cfi_restore 5
301
302    l.d    $f19, 72($sp)
303    l.d    $f18, 64($sp)
304    l.d    $f17, 56($sp)
305    l.d    $f16, 48($sp)
306    l.d    $f15, 40($sp)
307    l.d    $f14, 32($sp)
308    l.d    $f13, 24($sp)
309    l.d    $f12, 16($sp)
310
311    .cpreturn
312    daddiu $sp, $sp, 208
313    .cfi_adjust_cfa_offset -208
314.endm
315
316    /*
317     * Macro that set calls through to artDeliverPendingExceptionFromCode,
318     * where the pending
319     * exception is Thread::Current()->exception_
320     */
321.macro DELIVER_PENDING_EXCEPTION
322    SETUP_GP
323    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME     # save callee saves for throw
324    dla     $t9, artDeliverPendingExceptionFromCode
325    jalr    $zero, $t9                   # artDeliverPendingExceptionFromCode(Thread*)
326    move    $a0, rSELF                   # pass Thread::Current
327.endm
328
329.macro RETURN_IF_NO_EXCEPTION
330    ld     $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
331    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
332    bne    $t0, $zero, 1f                      # success if no exception is pending
333    nop
334    jalr   $zero, $ra
335    nop
3361:
337    DELIVER_PENDING_EXCEPTION
338.endm
339
340.macro RETURN_IF_ZERO
341    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
342    bne    $v0, $zero, 1f                # success?
343    nop
344    jalr   $zero, $ra                    # return on success
345    nop
3461:
347    DELIVER_PENDING_EXCEPTION
348.endm
349
350.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
351    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
352    beq    $v0, $zero, 1f                # success?
353    nop
354    jalr   $zero, $ra                    # return on success
355    nop
3561:
357    DELIVER_PENDING_EXCEPTION
358.endm
359
360    /*
361     * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
362     * FIXME: just guessing about the shape of the jmpbuf.  Where will pc be?
363     */
364ENTRY_NO_GP art_quick_do_long_jump
365    l.d     $f0, 0($a1)
366    l.d     $f1, 8($a1)
367    l.d     $f2, 16($a1)
368    l.d     $f3, 24($a1)
369    l.d     $f4, 32($a1)
370    l.d     $f5, 40($a1)
371    l.d     $f6, 48($a1)
372    l.d     $f7, 56($a1)
373    l.d     $f8, 64($a1)
374    l.d     $f9, 72($a1)
375    l.d     $f10, 80($a1)
376    l.d     $f11, 88($a1)
377    l.d     $f12, 96($a1)
378    l.d     $f13, 104($a1)
379    l.d     $f14, 112($a1)
380    l.d     $f15, 120($a1)
381    l.d     $f16, 128($a1)
382    l.d     $f17, 136($a1)
383    l.d     $f18, 144($a1)
384    l.d     $f19, 152($a1)
385    l.d     $f20, 160($a1)
386    l.d     $f21, 168($a1)
387    l.d     $f22, 176($a1)
388    l.d     $f23, 184($a1)
389    l.d     $f24, 192($a1)
390    l.d     $f25, 200($a1)
391    l.d     $f26, 208($a1)
392    l.d     $f27, 216($a1)
393    l.d     $f28, 224($a1)
394    l.d     $f29, 232($a1)
395    l.d     $f30, 240($a1)
396    l.d     $f31, 248($a1)
397    .set push
398    .set nomacro
399    .set noat
400# no need to load zero
401    ld      $at, 8($a0)
402    .set pop
403    ld      $v0, 16($a0)
404    ld      $v1, 24($a0)
405# a0 has to be loaded last
406    ld      $a1, 40($a0)
407    ld      $a2, 48($a0)
408    ld      $a3, 56($a0)
409    ld      $a4, 64($a0)
410    ld      $a5, 72($a0)
411    ld      $a6, 80($a0)
412    ld      $a7, 88($a0)
413    ld      $t0, 96($a0)
414    ld      $t1, 104($a0)
415    ld      $t2, 112($a0)
416    ld      $t3, 120($a0)
417    ld      $s0, 128($a0)
418    ld      $s1, 136($a0)
419    ld      $s2, 144($a0)
420    ld      $s3, 152($a0)
421    ld      $s4, 160($a0)
422    ld      $s5, 168($a0)
423    ld      $s6, 176($a0)
424    ld      $s7, 184($a0)
425    ld      $t8, 192($a0)
426    ld      $t9, 200($a0)
427# no need to load k0, k1
428    ld      $gp, 224($a0)
429    ld      $sp, 232($a0)
430    ld      $s8, 240($a0)
431    ld      $ra, 248($a0)
432    ld      $a0, 32($a0)
433    move    $v0, $zero          # clear result registers v0 and v1
434    jalr    $zero, $ra          # do long jump
435    move    $v1, $zero
436END art_quick_do_long_jump
437
438    /*
439     * Called by managed code, saves most registers (forms basis of long jump
440     * context) and passes the bottom of the stack.
441     * artDeliverExceptionFromCode will place the callee save Method* at
442     * the bottom of the thread. On entry a0 holds Throwable*
443     */
444ENTRY art_quick_deliver_exception
445    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
446    dla  $t9, artDeliverExceptionFromCode
447    jalr $zero, $t9                 # artDeliverExceptionFromCode(Throwable*, Thread*)
448    move $a1, rSELF                 # pass Thread::Current
449END art_quick_deliver_exception
450
451    /*
452     * Called by managed code to create and deliver a NullPointerException
453     */
454    .extern artThrowNullPointerExceptionFromCode
455ENTRY art_quick_throw_null_pointer_exception
456.Lart_quick_throw_null_pointer_exception_gp_set:
457    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
458    dla  $t9, artThrowNullPointerExceptionFromCode
459    jalr $zero, $t9                 # artThrowNullPointerExceptionFromCode(Thread*)
460    move $a0, rSELF                 # pass Thread::Current
461END art_quick_throw_null_pointer_exception
462
463    /*
464     * Called by managed code to create and deliver an ArithmeticException
465     */
466    .extern artThrowDivZeroFromCode
467ENTRY art_quick_throw_div_zero
468    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
469    dla  $t9, artThrowDivZeroFromCode
470    jalr $zero, $t9                 # artThrowDivZeroFromCode(Thread*)
471    move $a0, rSELF                 # pass Thread::Current
472END art_quick_throw_div_zero
473
474    /*
475     * Called by managed code to create and deliver an
476     * ArrayIndexOutOfBoundsException
477     */
478    .extern artThrowArrayBoundsFromCode
479ENTRY art_quick_throw_array_bounds
480.Lart_quick_throw_array_bounds_gp_set:
481    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
482    dla  $t9, artThrowArrayBoundsFromCode
483    jalr $zero, $t9                 # artThrowArrayBoundsFromCode(index, limit, Thread*)
484    move $a2, rSELF                 # pass Thread::Current
485END art_quick_throw_array_bounds
486
487    /*
488     * Called by managed code to create and deliver a StackOverflowError.
489     */
490    .extern artThrowStackOverflowFromCode
491ENTRY art_quick_throw_stack_overflow
492    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
493    dla  $t9, artThrowStackOverflowFromCode
494    jalr $zero, $t9                 # artThrowStackOverflowFromCode(Thread*)
495    move $a0, rSELF                 # pass Thread::Current
496END art_quick_throw_stack_overflow
497
498    /*
499     * Called by managed code to create and deliver a NoSuchMethodError.
500     */
501    .extern artThrowNoSuchMethodFromCode
502ENTRY art_quick_throw_no_such_method
503    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
504    dla  $t9, artThrowNoSuchMethodFromCode
505    jalr $zero, $t9                 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
506    move $a1, rSELF                 # pass Thread::Current
507END art_quick_throw_no_such_method
508
509    /*
510     * All generated callsites for interface invokes and invocation slow paths will load arguments
511     * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
512     * the method_idx.  This wrapper will save arg1-arg3, load the caller's Method*, align the
513     * stack and call the appropriate C helper.
514     * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
515     *
516     * The helper will attempt to locate the target and return a 128-bit result in $v0/$v1 consisting
517     * of the target Method* in $v0 and method->code_ in $v1.
518     *
519     * If unsuccessful, the helper will return null/null. There will be a pending exception in the
520     * thread and we branch to another stub to deliver it.
521     *
522     * On success this wrapper will restore arguments and *jump* to the target, leaving the ra
523     * pointing back to the original caller.
524     */
525.macro INVOKE_TRAMPOLINE_BODY cxx_name
526    .extern \cxx_name
527    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME  # save callee saves in case allocation triggers GC
528    move  $a2, rSELF                       # pass Thread::Current
529    jal   \cxx_name                        # (method_idx, this, Thread*, $sp)
530    move  $a3, $sp                         # pass $sp
531    move  $a0, $v0                         # save target Method*
532    move  $t9, $v1                         # save $v0->code_
533    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
534    beq   $v0, $zero, 1f
535    nop
536    jalr  $zero, $t9
537    nop
5381:
539    DELIVER_PENDING_EXCEPTION
540.endm
541.macro INVOKE_TRAMPOLINE c_name, cxx_name
542ENTRY \c_name
543    INVOKE_TRAMPOLINE_BODY \cxx_name
544END \c_name
545.endm
546
547INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
548
549INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
550INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
551INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
552INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
553
554    # On entry:
555    #   t0 = shorty
556    #   t1 = ptr to arg_array
557    #   t2 = number of argument bytes remain
558    #   v0 = ptr to stack frame where to copy arg_array
559    # This macro modifies t3, t9 and v0
560.macro LOOP_OVER_SHORTY_LOADING_REG gpu, fpu, label
561    lbu    $t3, 0($t0)           # get argument type from shorty
562    beqz   $t3, \label
563    daddiu $t0, 1
564    li     $t9, 68               # put char 'D' into t9
565    beq    $t9, $t3, 1f          # branch if result type char == 'D'
566    li     $t9, 70               # put char 'F' into t9
567    beq    $t9, $t3, 2f          # branch if result type char == 'F'
568    li     $t9, 74               # put char 'J' into t9
569    beq    $t9, $t3, 3f          # branch if result type char == 'J'
570    nop
571    lw     $\gpu, 0($t1)
572    sw     $\gpu, 0($v0)
573    daddiu $v0, 4
574    daddiu $t1, 4
575    b      4f
576    daddiu $t2, -4               # delay slot
577
5781:  # found double
579    lwu    $t3, 0($t1)
580    mtc1   $t3, $\fpu
581    sw     $t3, 0($v0)
582    lwu    $t3, 4($t1)
583    mthc1  $t3, $\fpu
584    sw     $t3, 4($v0)
585    daddiu $v0, 8
586    daddiu $t1, 8
587    b      4f
588    daddiu $t2, -8               # delay slot
589
5902:  # found float
591    lwu    $t3, 0($t1)
592    mtc1   $t3, $\fpu
593    sw     $t3, 0($v0)
594    daddiu $v0, 4
595    daddiu $t1, 4
596    b      4f
597    daddiu $t2, -4               # delay slot
598
5993:  # found long (8 bytes)
600    lwu    $t3, 0($t1)
601    sw     $t3, 0($v0)
602    lwu    $t9, 4($t1)
603    sw     $t9, 4($v0)
604    dsll   $t9, $t9, 32
605    or     $\gpu, $t9, $t3
606    daddiu $v0, 8
607    daddiu $t1, 8
608    daddiu $t2, -8
6094:
610.endm
611
612    /*
613     * Invocation stub for quick code.
614     * On entry:
615     *   a0 = method pointer
616     *   a1 = argument array that must at least contain the this ptr.
617     *   a2 = size of argument array in bytes
618     *   a3 = (managed) thread pointer
619     *   a4 = JValue* result
620     *   a5 = shorty
621     */
622ENTRY_NO_GP art_quick_invoke_stub
623    # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra onto the stack
624    daddiu $sp, $sp, -48
625    .cfi_adjust_cfa_offset 48
626    sd     $ra, 40($sp)
627    .cfi_rel_offset 31, 40
628    sd     $s8, 32($sp)
629    .cfi_rel_offset 30, 32
630    sd     $s1, 24($sp)
631    .cfi_rel_offset 17, 24
632    sd     $s0, 16($sp)
633    .cfi_rel_offset 16, 16
634    sd     $a5, 8($sp)
635    .cfi_rel_offset 9, 8
636    sd     $a4, 0($sp)
637    .cfi_rel_offset 8, 0
638
639    daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL   # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
640    move   $s1, $a3              # move managed thread pointer into s1 (rSELF)
641    move   $s8, $sp              # save sp in s8 (fp)
642
643    daddiu $t3, $a2, 24          # add 8 for ArtMethod* and 16 for stack alignment
644    dsrl   $t3, $t3, 4           # shift the frame size right 4
645    dsll   $t3, $t3, 4           # shift the frame size left 4 to align to 16 bytes
646    dsubu  $sp, $sp, $t3         # reserve stack space for argument array
647
648    daddiu $t0, $a5, 1           # t0 = shorty[1] (skip 1 for return type)
649    daddiu $t1, $a1, 4           # t1 = ptr to arg_array[4] (skip this ptr)
650    daddiu $t2, $a2, -4          # t2 = number of argument bytes remain (skip this ptr)
651    daddiu $v0, $sp, 12          # v0 points to where to copy arg_array
652    LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_fn
653    LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_fn
654    LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_fn
655    LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_fn
656    LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_fn
657    LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_fn
658
659    # copy arguments onto stack (t2 should be multiples of 4)
660    ble    $t2, $zero, call_fn   # t2 = number of argument bytes remain
6611:
662    lw     $t3, 0($t1)           # load from argument array
663    daddiu $t1, $t1, 4
664    sw     $t3, 0($v0)           # save to stack
665    daddiu $t2, -4
666    bgt    $t2, $zero, 1b        # t2 = number of argument bytes remain
667    daddiu $v0, $v0, 4
668
669call_fn:
670    # call method (a0 and a1 have been untouched)
671    lwu    $a1, 0($a1)           # make a1 = this ptr
672    sw     $a1, 8($sp)           # copy this ptr (skip 8 bytes for ArtMethod*)
673    sd     $zero, 0($sp)         # store null for ArtMethod* at bottom of frame
674    ld     $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)  # get pointer to the code
675    jalr   $t9                   # call the method
676    nop
677    move   $sp, $s8              # restore sp
678
679    # pop a4, a5, s1(rSELF), s8, ra off of the stack
680    ld     $a4, 0($sp)
681    .cfi_restore 8
682    ld     $a5, 8($sp)
683    .cfi_restore 9
684    ld     $s0, 16($sp)
685    .cfi_restore 16
686    ld     $s1, 24($sp)
687    .cfi_restore 17
688    ld     $s8, 32($sp)
689    .cfi_restore 30
690    ld     $ra, 40($sp)
691    .cfi_restore 31
692    daddiu $sp, $sp, 48
693    .cfi_adjust_cfa_offset -48
694
695    # a4 = JValue* result
696    # a5 = shorty string
697    lbu   $t1, 0($a5)           # get result type from shorty
698    li    $t2, 68               # put char 'D' into t2
699    beq   $t1, $t2, 1f          # branch if result type char == 'D'
700    li    $t3, 70               # put char 'F' into t3
701    beq   $t1, $t3, 1f          # branch if result type char == 'F'
702    sw    $v0, 0($a4)           # store the result
703    dsrl  $v1, $v0, 32
704    jalr  $zero, $ra
705    sw    $v1, 4($a4)           # store the other half of the result
7061:
707    mfc1  $v0, $f0
708    mfhc1 $v1, $f0
709    sw    $v0, 0($a4)           # store the result
710    jalr  $zero, $ra
711    sw    $v1, 4($a4)           # store the other half of the result
712END art_quick_invoke_stub
713
714    /*
715     * Invocation static stub for quick code.
716     * On entry:
717     *   a0 = method pointer
718     *   a1 = argument array that must at least contain the this ptr.
719     *   a2 = size of argument array in bytes
720     *   a3 = (managed) thread pointer
721     *   a4 = JValue* result
722     *   a5 = shorty
723     */
724ENTRY_NO_GP art_quick_invoke_static_stub
725
726    # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra, onto the stack
727    daddiu $sp, $sp, -48
728    .cfi_adjust_cfa_offset 48
729    sd     $ra, 40($sp)
730    .cfi_rel_offset 31, 40
731    sd     $s8, 32($sp)
732    .cfi_rel_offset 30, 32
733    sd     $s1, 24($sp)
734    .cfi_rel_offset 17, 24
735    sd     $s0, 16($sp)
736    .cfi_rel_offset 16, 16
737    sd     $a5, 8($sp)
738    .cfi_rel_offset 9, 8
739    sd     $a4, 0($sp)
740    .cfi_rel_offset 8, 0
741
742    daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL   # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
743    move   $s1, $a3              # move managed thread pointer into s1 (rSELF)
744    move   $s8, $sp              # save sp in s8 (fp)
745
746    daddiu $t3, $a2, 24          # add 8 for ArtMethod* and 16 for stack alignment
747    dsrl   $t3, $t3, 4           # shift the frame size right 4
748    dsll   $t3, $t3, 4           # shift the frame size left 4 to align to 16 bytes
749    dsubu  $sp, $sp, $t3         # reserve stack space for argument array
750
751    daddiu $t0, $a5, 1           # t0 = shorty[1] (skip 1 for return type)
752    move   $t1, $a1              # t1 = arg_array
753    move   $t2, $a2              # t2 = number of argument bytes remain
754    daddiu $v0, $sp, 8           # v0 points to where to copy arg_array
755    LOOP_OVER_SHORTY_LOADING_REG a1, f13, call_sfn
756    LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_sfn
757    LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_sfn
758    LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_sfn
759    LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_sfn
760    LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_sfn
761    LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_sfn
762
763    # copy arguments onto stack (t2 should be multiples of 4)
764    ble    $t2, $zero, call_sfn  # t2 = number of argument bytes remain
7651:
766    lw     $t3, 0($t1)           # load from argument array
767    daddiu $t1, $t1, 4
768    sw     $t3, 0($v0)           # save to stack
769    daddiu $t2, -4
770    bgt    $t2, $zero, 1b        # t2 = number of argument bytes remain
771    daddiu $v0, $v0, 4
772
773call_sfn:
774    # call method (a0 has been untouched)
775    sd     $zero, 0($sp)         # store null for ArtMethod* at bottom of frame
776    ld     $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)  # get pointer to the code
777    jalr   $t9                   # call the method
778    nop
779    move   $sp, $s8              # restore sp
780
781    # pop a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra off of the stack
782    ld     $a4, 0($sp)
783    .cfi_restore 8
784    ld     $a5, 8($sp)
785    .cfi_restore 9
786    ld     $s0, 16($sp)
787    .cfi_restore 16
788    ld     $s1, 24($sp)
789    .cfi_restore 17
790    ld     $s8, 32($sp)
791    .cfi_restore 30
792    ld     $ra, 40($sp)
793    .cfi_restore 31
794    daddiu $sp, $sp, 48
795    .cfi_adjust_cfa_offset -48
796
797    # a4 = JValue* result
798    # a5 = shorty string
799    lbu   $t1, 0($a5)           # get result type from shorty
800    li    $t2, 68               # put char 'D' into t2
801    beq   $t1, $t2, 1f          # branch if result type char == 'D'
802    li    $t3, 70               # put char 'F' into t3
803    beq   $t1, $t3, 1f          # branch if result type char == 'F'
804    sw    $v0, 0($a4)           # store the result
805    dsrl  $v1, $v0, 32
806    jalr  $zero, $ra
807    sw    $v1, 4($a4)           # store the other half of the result
8081:
809    mfc1  $v0, $f0
810    mfhc1 $v1, $f0
811    sw    $v0, 0($a4)           # store the result
812    jalr  $zero, $ra
813    sw    $v1, 4($a4)           # store the other half of the result
814END art_quick_invoke_static_stub
815
816    /*
817     * Entry from managed code that calls artHandleFillArrayDataFromCode and
818     * delivers exception on failure.
819     */
820    .extern artHandleFillArrayDataFromCode
821ENTRY art_quick_handle_fill_data
822    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case exception allocation triggers GC
823    ld      $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
824    jal     artHandleFillArrayDataFromCode              # (payload offset, Array*, method, Thread*)
825    move    $a3, rSELF                                  # pass Thread::Current
826    RETURN_IF_ZERO
827END art_quick_handle_fill_data
828
829    /*
830     * Entry from managed code that calls artLockObjectFromCode, may block for GC.
831     */
832    .extern artLockObjectFromCode
833ENTRY art_quick_lock_object
834    beq     $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
835    nop
836    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME     # save callee saves in case we block
837    jal     artLockObjectFromCode         # (Object* obj, Thread*)
838    move    $a1, rSELF                    # pass Thread::Current
839    RETURN_IF_ZERO
840END art_quick_lock_object
841
842    /*
843     * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
844     */
845    .extern artUnlockObjectFromCode
846ENTRY art_quick_unlock_object
847    beq     $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
848    nop
849    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case exception allocation triggers GC
850    jal     artUnlockObjectFromCode    # (Object* obj, Thread*)
851    move    $a1, rSELF                 # pass Thread::Current
852    RETURN_IF_ZERO
853END art_quick_unlock_object
854
855    /*
856     * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
857     */
858    .extern artThrowClassCastException
859ENTRY art_quick_check_cast
860    daddiu $sp, $sp, -32
861    .cfi_adjust_cfa_offset 32
862    sd     $ra, 24($sp)
863    .cfi_rel_offset 31, 24
864    sd     $t9, 16($sp)
865    sd     $a1, 8($sp)
866    sd     $a0, 0($sp)
867    jal    artIsAssignableFromCode
868    .cpreturn                       # Restore gp from t8 in branch delay slot.
869                                    # t8 may be clobbered in artIsAssignableFromCode.
870    beq    $v0, $zero, .Lthrow_class_cast_exception
871    ld     $ra, 24($sp)
872    jalr   $zero, $ra
873    daddiu $sp, $sp, 32
874    .cfi_adjust_cfa_offset -32
875.Lthrow_class_cast_exception:
876    ld     $t9, 16($sp)
877    ld     $a1, 8($sp)
878    ld     $a0, 0($sp)
879    daddiu $sp, $sp, 32
880    .cfi_adjust_cfa_offset -32
881    SETUP_GP
882    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
883    dla  $t9, artThrowClassCastException
884    jalr $zero, $t9                 # artThrowClassCastException (Class*, Class*, Thread*)
885    move $a2, rSELF                 # pass Thread::Current
886END art_quick_check_cast
887
888
889    /*
890     * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
891     * nReg is the register number for rReg.
892     */
893.macro POP_REG_NE rReg, nReg, offset, rExclude
894    .ifnc \rReg, \rExclude
895        ld \rReg, \offset($sp)      # restore rReg
896        .cfi_restore \nReg
897    .endif
898.endm
899
900    /*
901     * Macro to insert read barrier, only used in art_quick_aput_obj.
902     * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
903     * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
904     */
905.macro READ_BARRIER rDest, rObj, offset
906#ifdef USE_READ_BARRIER
907    # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 16B-aligned.
908    daddiu  $sp, $sp, -64
909    .cfi_adjust_cfa_offset 64
910    sd     $ra, 56($sp)
911    .cfi_rel_offset 31, 56
912    sd     $t9, 48($sp)
913    .cfi_rel_offset 25, 48
914    sd     $t1, 40($sp)
915    .cfi_rel_offset 13, 40
916    sd     $t0, 32($sp)
917    .cfi_rel_offset 12, 32
918    sd     $a2, 16($sp)             # padding slot at offset 24 (padding can be any slot in the 64B)
919    .cfi_rel_offset 6, 16
920    sd     $a1, 8($sp)
921    .cfi_rel_offset 5, 8
922    sd     $a0, 0($sp)
923    .cfi_rel_offset 4, 0
924
925    # move $a0, $a0                 # pass ref in a0 (no-op for now since parameter ref is unused)
926    .ifnc \rObj, $a1
927        move $a1, \rObj             # pass rObj
928    .endif
929    daddiu $a2, $zero, \offset      # pass offset
930    jal artReadBarrierSlow          # artReadBarrierSlow(ref, rObj, offset)
931    .cpreturn                       # Restore gp from t8 in branch delay slot.
932                                    # t8 may be clobbered in artReadBarrierSlow.
933    # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
934    move \rDest, $v0                # save return value in rDest
935                                    # (rDest cannot be v0 in art_quick_aput_obj)
936
937    ld     $a0, 0($sp)              # restore registers except rDest
938                                    # (rDest can only be t0 or t1 in art_quick_aput_obj)
939    .cfi_restore 4
940    ld     $a1, 8($sp)
941    .cfi_restore 5
942    ld     $a2, 16($sp)
943    .cfi_restore 6
944    POP_REG_NE $t0, 12, 32, \rDest
945    POP_REG_NE $t1, 13, 40, \rDest
946    ld     $t9, 48($sp)
947    .cfi_restore 25
948    ld     $ra, 56($sp)             # restore $ra
949    .cfi_restore 31
950    daddiu  $sp, $sp, 64
951    .cfi_adjust_cfa_offset -64
952    SETUP_GP                        # set up gp because we are not returning
953#else
954    lwu     \rDest, \offset(\rObj)
955    UNPOISON_HEAP_REF \rDest
956#endif  // USE_READ_BARRIER
957.endm
958
959    /*
960     * Entry from managed code for array put operations of objects where the value being stored
961     * needs to be checked for compatibility.
962     * a0 = array, a1 = index, a2 = value
963     */
964ENTRY art_quick_aput_obj_with_null_and_bound_check
965    bne    $a0, $zero, .Lart_quick_aput_obj_with_bound_check_gp_set
966    nop
967    b .Lart_quick_throw_null_pointer_exception_gp_set
968    nop
969END art_quick_aput_obj_with_null_and_bound_check
970
971ENTRY art_quick_aput_obj_with_bound_check
972    lwu  $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
973    sltu $t1, $a1, $t0
974    bne  $t1, $zero, .Lart_quick_aput_obj_gp_set
975    nop
976    move $a0, $a1
977    b .Lart_quick_throw_array_bounds_gp_set
978    move $a1, $t0
979END art_quick_aput_obj_with_bound_check
980
981ENTRY art_quick_aput_obj
982    beq  $a2, $zero, .Ldo_aput_null
983    nop
984    READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
985    READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
986    READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
987    bne $t1, $t0, .Lcheck_assignability  # value's type == array's component type - trivial assignability
988    nop
989.Ldo_aput:
990    dsll  $a1, $a1, 2
991    daddu $t0, $a0, $a1
992    POISON_HEAP_REF $a2
993    sw   $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
994    ld   $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
995    dsrl  $t1, $a0, 7
996    daddu $t1, $t1, $t0
997    sb   $t0, ($t1)
998    jalr $zero, $ra
999    .cpreturn                       # Restore gp from t8 in branch delay slot.
1000.Ldo_aput_null:
1001    dsll  $a1, $a1, 2
1002    daddu $t0, $a0, $a1
1003    sw   $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1004    jalr $zero, $ra
1005    .cpreturn                       # Restore gp from t8 in branch delay slot.
1006.Lcheck_assignability:
1007    daddiu $sp, $sp, -64
1008    .cfi_adjust_cfa_offset 64
1009    sd     $ra, 56($sp)
1010    .cfi_rel_offset 31, 56
1011    sd     $t9, 24($sp)
1012    sd     $a2, 16($sp)
1013    sd     $a1, 8($sp)
1014    sd     $a0, 0($sp)
1015    move   $a1, $t1
1016    move   $a0, $t0
1017    jal    artIsAssignableFromCode  # (Class*, Class*)
1018    .cpreturn                       # Restore gp from t8 in branch delay slot.
1019                                    # t8 may be clobbered in artIsAssignableFromCode.
1020    ld     $ra, 56($sp)
1021    ld     $t9, 24($sp)
1022    ld     $a2, 16($sp)
1023    ld     $a1, 8($sp)
1024    ld     $a0, 0($sp)
1025    daddiu $sp, $sp, 64
1026    .cfi_adjust_cfa_offset -64
1027    SETUP_GP
1028    bne    $v0, $zero, .Ldo_aput
1029    nop
1030    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1031    move   $a1, $a2
1032    dla  $t9, artThrowArrayStoreException
1033    jalr $zero, $t9                 # artThrowArrayStoreException(Class*, Class*, Thread*)
1034    move   $a2, rSELF               # pass Thread::Current
1035END art_quick_aput_obj
1036
1037    /*
1038     * Called by managed code to resolve a static field and load a boolean primitive value.
1039     */
1040    .extern artGetBooleanStaticFromCode
1041ENTRY art_quick_get_boolean_static
1042    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1043    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1044    jal    artGetBooleanStaticFromCode   # (uint32_t field_idx, const Method* referrer, Thread*)
1045    move   $a2, rSELF                    # pass Thread::Current
1046    RETURN_IF_NO_EXCEPTION
1047END art_quick_get_boolean_static
1048
1049    /*
1050     * Called by managed code to resolve a static field and load a byte primitive value.
1051     */
1052    .extern artGetByteStaticFromCode
1053ENTRY art_quick_get_byte_static
1054    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1055    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1056    jal    artGetByteStaticFromCode      # (uint32_t field_idx, const Method* referrer, Thread*)
1057    move   $a2, rSELF                    # pass Thread::Current
1058    RETURN_IF_NO_EXCEPTION
1059END art_quick_get_byte_static
1060
1061    /*
1062     * Called by managed code to resolve a static field and load a char primitive value.
1063     */
1064    .extern artGetCharStaticFromCode
1065ENTRY art_quick_get_char_static
1066    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1067    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1068    jal    artGetCharStaticFromCode      # (uint32_t field_idx, const Method* referrer, Thread*)
1069    move   $a2, rSELF                    # pass Thread::Current
1070    RETURN_IF_NO_EXCEPTION
1071END art_quick_get_char_static
1072
1073    /*
1074     * Called by managed code to resolve a static field and load a short primitive value.
1075     */
1076    .extern artGetShortStaticFromCode
1077ENTRY art_quick_get_short_static
1078    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1079    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1080    jal    artGetShortStaticFromCode     # (uint32_t field_idx, const Method* referrer, Thread*)
1081    move   $a2, rSELF                    # pass Thread::Current
1082    RETURN_IF_NO_EXCEPTION
1083END art_quick_get_short_static
1084
1085    /*
1086     * Called by managed code to resolve a static field and load a 32-bit primitive value.
1087     */
1088    .extern artGet32StaticFromCode
1089ENTRY art_quick_get32_static
1090    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1091    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1092    jal    artGet32StaticFromCode        # (uint32_t field_idx, const Method* referrer, Thread*)
1093    move   $a2, rSELF                    # pass Thread::Current
1094    RETURN_IF_NO_EXCEPTION
1095END art_quick_get32_static
1096
1097    /*
1098     * Called by managed code to resolve a static field and load a 64-bit primitive value.
1099     */
1100    .extern artGet64StaticFromCode
1101ENTRY art_quick_get64_static
1102    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1103    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1104    jal    artGet64StaticFromCode        # (uint32_t field_idx, const Method* referrer, Thread*)
1105    move   $a2, rSELF                    # pass Thread::Current
1106    RETURN_IF_NO_EXCEPTION
1107END art_quick_get64_static
1108
1109    /*
1110     * Called by managed code to resolve a static field and load an object reference.
1111     */
1112    .extern artGetObjStaticFromCode
1113ENTRY art_quick_get_obj_static
1114    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1115    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1116    jal    artGetObjStaticFromCode       # (uint32_t field_idx, const Method* referrer, Thread*)
1117    move   $a2, rSELF                    # pass Thread::Current
1118    RETURN_IF_NO_EXCEPTION
1119END art_quick_get_obj_static
1120
1121    /*
1122     * Called by managed code to resolve an instance field and load a boolean primitive value.
1123     */
1124    .extern artGetBooleanInstanceFromCode
1125ENTRY art_quick_get_boolean_instance
1126    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1127    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1128    jal    artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1129    move   $a3, rSELF                    # pass Thread::Current
1130    RETURN_IF_NO_EXCEPTION
1131END art_quick_get_boolean_instance
1132
1133    /*
1134     * Called by managed code to resolve an instance field and load a byte primitive value.
1135     */
1136    .extern artGetByteInstanceFromCode
1137ENTRY art_quick_get_byte_instance
1138    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1139    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1140    jal    artGetByteInstanceFromCode    # (field_idx, Object*, referrer, Thread*)
1141    move   $a3, rSELF                    # pass Thread::Current
1142    RETURN_IF_NO_EXCEPTION
1143END art_quick_get_byte_instance
1144
1145    /*
1146     * Called by managed code to resolve an instance field and load a char primitive value.
1147     */
1148    .extern artGetCharInstanceFromCode
1149ENTRY art_quick_get_char_instance
1150    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1151    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1152    jal    artGetCharInstanceFromCode    # (field_idx, Object*, referrer, Thread*)
1153    move   $a3, rSELF                    # pass Thread::Current
1154    RETURN_IF_NO_EXCEPTION
1155END art_quick_get_char_instance
1156
1157    /*
1158     * Called by managed code to resolve an instance field and load a short primitive value.
1159     */
1160    .extern artGetShortInstanceFromCode
1161ENTRY art_quick_get_short_instance
1162    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1163    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1164    jal    artGetShortInstanceFromCode   # (field_idx, Object*, referrer, Thread*)
1165    move   $a3, rSELF                    # pass Thread::Current
1166    RETURN_IF_NO_EXCEPTION
1167END art_quick_get_short_instance
1168
1169    /*
1170     * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1171     */
1172    .extern artGet32InstanceFromCode
1173ENTRY art_quick_get32_instance
1174    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1175    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1176    jal    artGet32InstanceFromCode      # (field_idx, Object*, referrer, Thread*)
1177    move   $a3, rSELF                    # pass Thread::Current
1178    RETURN_IF_NO_EXCEPTION
1179END art_quick_get32_instance
1180
1181    /*
1182     * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1183     */
1184    .extern artGet64InstanceFromCode
1185ENTRY art_quick_get64_instance
1186    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1187    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1188    jal    artGet64InstanceFromCode      # (field_idx, Object*, referrer, Thread*)
1189    move   $a3, rSELF                    # pass Thread::Current
1190    RETURN_IF_NO_EXCEPTION
1191END art_quick_get64_instance
1192
1193    /*
1194     * Called by managed code to resolve an instance field and load an object reference.
1195     */
1196    .extern artGetObjInstanceFromCode
1197ENTRY art_quick_get_obj_instance
1198    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1199    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1200    jal    artGetObjInstanceFromCode     # (field_idx, Object*, referrer, Thread*)
1201    move   $a3, rSELF                    # pass Thread::Current
1202    RETURN_IF_NO_EXCEPTION
1203END art_quick_get_obj_instance
1204
1205    /*
1206     * Called by managed code to resolve a static field and store a 8-bit primitive value.
1207     */
1208    .extern artSet8StaticFromCode
1209ENTRY art_quick_set8_static
1210    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1211    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1212    jal    artSet8StaticFromCode         # (field_idx, new_val, referrer, Thread*)
1213    move   $a3, rSELF                    # pass Thread::Current
1214    RETURN_IF_ZERO
1215END art_quick_set8_static
1216
1217    /*
1218     * Called by managed code to resolve a static field and store a 16-bit primitive value.
1219     */
1220    .extern artSet16StaticFromCode
1221ENTRY art_quick_set16_static
1222    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1223    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1224    jal    artSet16StaticFromCode        # (field_idx, new_val, referrer, Thread*)
1225    move   $a3, rSELF                    # pass Thread::Current
1226    RETURN_IF_ZERO
1227END art_quick_set16_static
1228
1229    /*
1230     * Called by managed code to resolve a static field and store a 32-bit primitive value.
1231     */
1232    .extern artSet32StaticFromCode
1233ENTRY art_quick_set32_static
1234    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1235    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1236    jal    artSet32StaticFromCode        # (field_idx, new_val, referrer, Thread*)
1237    move   $a3, rSELF                    # pass Thread::Current
1238    RETURN_IF_ZERO
1239END art_quick_set32_static
1240
1241    /*
1242     * Called by managed code to resolve a static field and store a 64-bit primitive value.
1243     */
1244    .extern artSet64StaticFromCode
1245ENTRY art_quick_set64_static
1246    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1247    move   $a2, $a1                      # pass new_val
1248    ld     $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1249    jal    artSet64StaticFromCode        # (field_idx, referrer, new_val, Thread*)
1250    move   $a3, rSELF                    # pass Thread::Current
1251    RETURN_IF_ZERO
1252END art_quick_set64_static
1253
1254    /*
1255     * Called by managed code to resolve a static field and store an object reference.
1256     */
1257    .extern artSetObjStaticFromCode
1258ENTRY art_quick_set_obj_static
1259    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1260    ld     $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1261    jal    artSetObjStaticFromCode       # (field_idx, new_val, referrer, Thread*)
1262    move   $a3, rSELF                    # pass Thread::Current
1263    RETURN_IF_ZERO
1264END art_quick_set_obj_static
1265
1266    /*
1267     * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1268     */
1269    .extern artSet8InstanceFromCode
1270ENTRY art_quick_set8_instance
1271    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1272    ld     $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1273    jal    artSet8InstanceFromCode       # (field_idx, Object*, new_val, referrer, Thread*)
1274    move   $a4, rSELF                    # pass Thread::Current
1275    RETURN_IF_ZERO
1276END art_quick_set8_instance
1277
1278    /*
1279     * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1280     */
1281    .extern artSet16InstanceFromCode
1282ENTRY art_quick_set16_instance
1283    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1284    ld     $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1285    jal    artSet16InstanceFromCode      # (field_idx, Object*, new_val, referrer, Thread*)
1286    move   $a4, rSELF                    # pass Thread::Current
1287    RETURN_IF_ZERO
1288END art_quick_set16_instance
1289
1290    /*
1291     * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1292     */
1293    .extern artSet32InstanceFromCode
1294ENTRY art_quick_set32_instance
1295    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1296    ld     $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1297    jal    artSet32InstanceFromCode      # (field_idx, Object*, new_val, referrer, Thread*)
1298    move   $a4, rSELF                    # pass Thread::Current
1299    RETURN_IF_ZERO
1300END art_quick_set32_instance
1301
1302    /*
1303     * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1304     */
1305    .extern artSet64InstanceFromCode
1306ENTRY art_quick_set64_instance
1307    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1308    ld     $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1309    jal    artSet64InstanceFromCode      # (field_idx, Object*, new_val, referrer, Thread*)
1310    move   $a4, rSELF                    # pass Thread::Current
1311    RETURN_IF_ZERO
1312END art_quick_set64_instance
1313
1314    /*
1315     * Called by managed code to resolve an instance field and store an object reference.
1316     */
1317    .extern artSetObjInstanceFromCode
1318ENTRY art_quick_set_obj_instance
1319    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME    # save callee saves in case of GC
1320    ld     $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp)  # pass referrer's Method*
1321    jal    artSetObjInstanceFromCode     # (field_idx, Object*, new_val, referrer, Thread*)
1322    move   $a4, rSELF                    # pass Thread::Current
1323    RETURN_IF_ZERO
1324END art_quick_set_obj_instance
1325
1326// Macro to facilitate adding new allocation entrypoints.
1327.macro ONE_ARG_DOWNCALL name, entrypoint, return
1328    .extern \entrypoint
1329ENTRY \name
1330    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case of GC
1331    jal     \entrypoint
1332    move    $a1, rSELF                 # pass Thread::Current
1333    \return
1334END \name
1335.endm
1336
1337// Macro to facilitate adding new allocation entrypoints.
1338.macro TWO_ARG_DOWNCALL name, entrypoint, return
1339    .extern \entrypoint
1340ENTRY \name
1341    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case of GC
1342    jal     \entrypoint
1343    move    $a2, rSELF                 # pass Thread::Current
1344    \return
1345END \name
1346.endm
1347
1348.macro THREE_ARG_DOWNCALL name, entrypoint, return
1349    .extern \entrypoint
1350ENTRY \name
1351    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case of GC
1352    jal     \entrypoint
1353    move    $a3, rSELF                 # pass Thread::Current
1354    \return
1355END \name
1356.endm
1357
1358.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1359    .extern \entrypoint
1360ENTRY \name
1361    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME  # save callee saves in case of GC
1362    jal     \entrypoint
1363    move    $a4, rSELF                 # pass Thread::Current
1364    \return
1365END \name
1366.endm
1367
1368// Generate the allocation entrypoints for each allocator.
1369GENERATE_ALL_ALLOC_ENTRYPOINTS
1370
1371    /*
1372     * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1373     * exception on error. On success the String is returned. A0 holds the string index. The fast
1374     * path check for hit in strings cache has already been performed.
1375     */
1376ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1377
1378    /*
1379     * Entry from managed code when uninitialized static storage, this stub will run the class
1380     * initializer and deliver the exception on error. On success the static storage base is
1381     * returned.
1382     */
1383ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1384
1385    /*
1386     * Entry from managed code when dex cache misses for a type_idx.
1387     */
1388ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1389
1390    /*
1391     * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1392     * miss.
1393     */
1394ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1395
1396    /*
1397     * Called by managed code when the value in rSUSPEND has been decremented to 0.
1398     */
1399    .extern artTestSuspendFromCode
1400ENTRY art_quick_test_suspend
1401    lh     $a0, THREAD_FLAGS_OFFSET(rSELF)
1402    bne    $a0, $zero, 1f
1403    daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL   # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1404    jalr   $zero, $ra
1405    .cpreturn                                 # Restore gp from t8 in branch delay slot.
14061:
1407    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME         # save callee saves for stack crawl
1408    jal    artTestSuspendFromCode             # (Thread*)
1409    move   $a0, rSELF
1410    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
1411END art_quick_test_suspend
1412
1413    /*
1414     * Called by managed code that is attempting to call a method on a proxy class. On entry
1415     * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1416     */
1417    .extern artQuickProxyInvokeHandler
1418ENTRY art_quick_proxy_invoke_handler
1419    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1420    move    $a2, rSELF             # pass Thread::Current
1421    jal     artQuickProxyInvokeHandler  # (Method* proxy method, receiver, Thread*, SP)
1422    move    $a3, $sp               # pass $sp
1423    ld      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1424    daddiu  $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE  # skip a0-a7 and f12-f19
1425    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1426    bne     $t0, $zero, 1f
1427    dmtc1   $v0, $f0               # place return value to FP return value
1428    jalr    $zero, $ra
1429    dmtc1   $v1, $f1               # place return value to FP return value
14301:
1431    DELIVER_PENDING_EXCEPTION
1432END art_quick_proxy_invoke_handler
1433
1434    /*
1435     * Called to resolve an imt conflict. t0 is a hidden argument that holds the target method's
1436     * dex method index.
1437     */
1438ENTRY art_quick_imt_conflict_trampoline
1439    move    $a0, $t0
1440    INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
1441END art_quick_imt_conflict_trampoline
1442
1443    .extern artQuickResolutionTrampoline
1444ENTRY art_quick_resolution_trampoline
1445    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1446    move    $a2, rSELF             # pass Thread::Current
1447    jal     artQuickResolutionTrampoline  # (Method* called, receiver, Thread*, SP)
1448    move    $a3, $sp               # pass $sp
1449    beq     $v0, $zero, 1f
1450    ld      $a0, 0($sp)            # load resolved method in $a0
1451                                   # artQuickResolutionTrampoline puts resolved method in *SP
1452    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1453    move    $t9, $v0               # code pointer must be in $t9 to generate the global pointer
1454    jalr    $zero, $t9             # tail call to method
1455    nop
14561:
1457    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1458    DELIVER_PENDING_EXCEPTION
1459END art_quick_resolution_trampoline
1460
1461    .extern artQuickGenericJniTrampoline
1462    .extern artQuickGenericJniEndTrampoline
1463ENTRY art_quick_generic_jni_trampoline
1464    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1465    move    $s8, $sp               # save $sp
1466
1467    # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1468    move    $a0, rSELF             # pass Thread::Current
1469    move    $a1, $sp               # pass $sp
1470    jal     artQuickGenericJniTrampoline   # (Thread*, SP)
1471    daddiu  $sp, $sp, -5120        # reserve space on the stack
1472
1473    # The C call will have registered the complete save-frame on success.
1474    # The result of the call is:
1475    # v0: ptr to native code, 0 on error.
1476    # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1477    beq     $v0, $zero, 1f         # check entry error
1478    move    $t9, $v0               # save the code ptr
1479    move    $sp, $v1               # release part of the alloca
1480
1481    # Load parameters from stack into registers
1482    ld      $a0,   0($sp)
1483    ld      $a1,   8($sp)
1484    ld      $a2,  16($sp)
1485    ld      $a3,  24($sp)
1486    ld      $a4,  32($sp)
1487    ld      $a5,  40($sp)
1488    ld      $a6,  48($sp)
1489    ld      $a7,  56($sp)
1490    # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1491    l.d     $f12,  0($sp)
1492    l.d     $f13,  8($sp)
1493    l.d     $f14, 16($sp)
1494    l.d     $f15, 24($sp)
1495    l.d     $f16, 32($sp)
1496    l.d     $f17, 40($sp)
1497    l.d     $f18, 48($sp)
1498    l.d     $f19, 56($sp)
1499    jalr    $t9                    # native call
1500    daddiu  $sp, $sp, 64
1501
1502    # result sign extension is handled in C code
1503    # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1504    move    $a0, rSELF             # pass Thread::Current
1505    move    $a1, $v0
1506    jal     artQuickGenericJniEndTrampoline
1507    dmfc1   $a2, $f0
1508
1509    ld      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1510    bne     $t0, $zero, 1f         # check for pending exceptions
1511    move    $sp, $s8               # tear down the alloca
1512
1513    # tear dpown the callee-save frame
1514    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1515
1516    jalr    $zero, $ra
1517    dmtc1   $v0, $f0               # place return value to FP return value
1518
15191:
1520    ld      $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
1521    # This will create a new save-all frame, required by the runtime.
1522    DELIVER_PENDING_EXCEPTION
1523END art_quick_generic_jni_trampoline
1524
1525    .extern artQuickToInterpreterBridge
1526ENTRY art_quick_to_interpreter_bridge
1527    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1528    move    $a1, rSELF             # pass Thread::Current
1529    jal     artQuickToInterpreterBridge    # (Method* method, Thread*, SP)
1530    move    $a2, $sp               # pass $sp
1531    ld      $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1532    daddiu  $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE  # skip a0-a7 and f12-f19
1533    RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1534    bne     $t0, $zero, 1f
1535    dmtc1   $v0, $f0               # place return value to FP return value
1536    jalr    $zero, $ra
1537    dmtc1   $v1, $f1               # place return value to FP return value
15381:
1539    DELIVER_PENDING_EXCEPTION
1540END art_quick_to_interpreter_bridge
1541
1542    /*
1543     * Routine that intercepts method calls and returns.
1544     */
1545    .extern artInstrumentationMethodEntryFromCode
1546    .extern artInstrumentationMethodExitFromCode
1547ENTRY art_quick_instrumentation_entry
1548    SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1549    daddiu   $sp, $sp, -16     # space for saving arg0
1550    .cfi_adjust_cfa_offset 16
1551    sd       $a0, 0($sp)       # save arg0
1552    move     $a3, $ra          # pass $ra
1553    jal      artInstrumentationMethodEntryFromCode  # (Method*, Object*, Thread*, RA)
1554    move     $a2, rSELF        # pass Thread::Current
1555    move     $t9, $v0          # $t9 holds reference to code
1556    ld       $a0, 0($sp)       # restore arg0
1557    daddiu   $sp, $sp, 16      # remove args
1558    .cfi_adjust_cfa_offset -16
1559    RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1560    jalr     $t9               # call method
1561    nop
1562END art_quick_instrumentation_entry
1563    /* intentional fallthrough */
1564    .global art_quick_instrumentation_exit
1565art_quick_instrumentation_exit:
1566    .cfi_startproc
1567    SETUP_GP
1568    move     $ra, $zero        # link register is to here, so clobber with 0 for later checks
1569    SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1570    move     $t0, $sp          # remember bottom of caller's frame
1571    daddiu   $sp, $sp, -16     # save return values and set up args
1572    .cfi_adjust_cfa_offset 16
1573    sd       $v0, 0($sp)
1574    .cfi_rel_offset 2, 0
1575    s.d      $f0, 8($sp)
1576    mov.d    $f15, $f0         # pass fpr result
1577    move     $a2, $v0          # pass gpr result
1578    move     $a1, $t0          # pass $sp
1579    move     $a0, rSELF        # pass Thread::Current
1580    jal      artInstrumentationMethodExitFromCode  # (Thread*, SP, gpr_res, fpr_res)
1581    .cpreturn                  # Restore gp from t8 in branch delay slot. gp is not used anymore,
1582                               # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
1583
1584    move     $t9, $v0          # set aside returned link register
1585    move     $ra, $v1          # set link register for deoptimization
1586    ld       $v0, 0($sp)       # restore return values
1587    l.d      $f0, 8($sp)
1588    jalr     $zero, $t9        # return
1589    daddiu   $sp, $sp, 16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE  # 16 bytes of saved values + ref_only callee save frame
1590    .cfi_adjust_cfa_offset -(16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1591END art_quick_instrumentation_exit
1592
1593    /*
1594     * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1595     * will long jump to the upcall with a special exception of -1.
1596     */
1597    .extern artDeoptimize
1598    .extern artEnterInterpreterFromDeoptimize
1599ENTRY art_quick_deoptimize
1600    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1601    jal      artDeoptimize     # artDeoptimize(Thread*, SP)
1602                               # Returns caller method's frame size.
1603    move     $a0, rSELF        # pass Thread::current
1604END art_quick_deoptimize
1605
1606    /*
1607     * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
1608     * will long jump to the upcall with a special exception of -1.
1609     */
1610    .extern artDeoptimizeFromCompiledCode
1611ENTRY art_quick_deoptimize_from_compiled_code
1612    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1613    jal      artDeoptimizeFromCompiledCode    # artDeoptimizeFromCompiledCode(Thread*, SP)
1614                                              # Returns caller method's frame size.
1615    move     $a0, rSELF                       # pass Thread::current
1616END art_quick_deoptimize_from_compiled_code
1617
1618UNIMPLEMENTED art_quick_indexof
1619UNIMPLEMENTED art_quick_string_compareto
1620