blob: 78ac748e322ab39a30879ffde0eee21be4753cdb [file] [log] [blame]
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001/*
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 /*
Goran Jakovljevic04568812015-04-23 15:27:23 +020030 * 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 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -080043 * 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
Goran Jakovljevic04568812015-04-23 15:27:23 +020060 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.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080062 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
Lazar Trsic84bc06e2015-06-10 16:05:46 +020090 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
91 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +020092 ld $t1, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t1)
93 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080094 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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200117 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.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800119 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
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200132 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
133 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200134 ld $t1, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t1)
135 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800136 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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200144 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800145 .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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200160 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800161.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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200168 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800169 .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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200182 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800183 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
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800191.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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200204 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.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800206 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.
Douglas Leung8223b802015-04-28 17:22:29 -0700242 # 1x8 bytes padding + Method*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800243.endm
244
Douglas Leung8223b802015-04-28 17:22:29 -0700245 /*
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 */
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800251.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
252 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
253 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200254 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
255 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200256 ld $t1, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t1)
257 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800258 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
259.endm
260
Douglas Leung8223b802015-04-28 17:22:29 -0700261.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
262 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Mathieu Chartiere401d142015-04-22 13:56:20 -0700263 sd $a0, 0($sp) # Place Method* at bottom of stack.
Douglas Leung8223b802015-04-28 17:22:29 -0700264 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
265.endm
266
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800267.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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200272 ld $t8, 184($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800273 .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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200311 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800312 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
Goran Jakovljevic04568812015-04-23 15:27:23 +0200322 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800323 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 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100361 * On stack replacement stub.
362 * On entry:
363 * a0 = stack to copy
364 * a1 = size of stack
365 * a2 = pc to call
366 * a3 = JValue* result
367 * a4 = shorty
368 * a5 = thread
369 */
370ENTRY art_quick_osr_stub
371 move $t0, $sp # save stack pointer
372 daddiu $t1, $sp, -112 # reserve stack space
373 dsrl $t1, $t1, 4 # enforce 16 byte stack alignment
374 dsll $sp, $t1, 4 # update stack pointer
375
376 // Save callee general purpose registers, SP, T8(GP), RA, A3, and A4 (8x14 bytes)
377 sd $ra, 104($sp)
378 .cfi_rel_offset 31, 104
379 sd $s8, 96($sp)
380 .cfi_rel_offset 30, 96
381 sd $t0, 88($sp) # save original stack pointer stored in t0
382 .cfi_rel_offset 29, 88
383 sd $t8, 80($sp) # t8 holds caller's gp, now save it to the stack.
384 .cfi_rel_offset 28, 80 # Value from gp is pushed, so set the cfi offset accordingly.
385 sd $s7, 72($sp)
386 .cfi_rel_offset 23, 72
387 sd $s6, 64($sp)
388 .cfi_rel_offset 22, 64
389 sd $s5, 56($sp)
390 .cfi_rel_offset 21, 56
391 sd $s4, 48($sp)
392 .cfi_rel_offset 20, 48
393 sd $s3, 40($sp)
394 .cfi_rel_offset 19, 40
395 sd $s2, 32($sp)
396 .cfi_rel_offset 18, 32
397 sd $s1, 24($sp)
398 .cfi_rel_offset 17, 24
399 sd $s0, 16($sp)
400 .cfi_rel_offset 16, 16
401 sd $a4, 8($sp)
402 .cfi_rel_offset 8, 8
403 sd $a3, 0($sp)
404 .cfi_rel_offset 7, 0
405 move rSELF, $a5 # Save managed thread pointer into rSELF
406
407 daddiu $sp, $sp, -16
408 jal .Losr_entry
409 sd $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
410 daddiu $sp, $sp, 16
411
412 // Restore return value address and shorty address
413 ld $a4, 8($sp) # shorty address
414 .cfi_restore 8
415 ld $a3, 0($sp) # result value address
416 .cfi_restore 7
417
418 lbu $t1, 0($a4) # load return type
419 li $t2, 'D' # put char 'D' into t2
420 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'D'
421 li $t2, 'F' # put char 'F' into t2
422 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'F'
423 nop
424 b .Losr_exit
425 dsrl $v1, $v0, 32 # put high half of result in v1
426.Losr_fp_result:
427 mfc1 $v0, $f0
428 mfhc1 $v1, $f0 # put high half of FP result in v1
429.Losr_exit:
430 sw $v0, 0($a3) # store low half of result
431 sw $v1, 4($a3) # store high half of result
432
433 // Restore callee registers
434 ld $ra, 104($sp)
435 .cfi_restore 31
436 ld $s8, 96($sp)
437 .cfi_restore 30
438 ld $t0, 88($sp) # save SP into t0 for now
439 .cfi_restore 29
440 ld $t8, 80($sp) # Restore gp back to it's temp storage.
441 .cfi_restore 28
442 ld $s7, 72($sp)
443 .cfi_restore 23
444 ld $s6, 64($sp)
445 .cfi_restore 22
446 ld $s5, 56($sp)
447 .cfi_restore 21
448 ld $s4, 48($sp)
449 .cfi_restore 20
450 ld $s3, 40($sp)
451 .cfi_restore 19
452 ld $s2, 32($sp)
453 .cfi_restore 18
454 ld $s1, 24($sp)
455 .cfi_restore 17
456 ld $s0, 16($sp)
457 .cfi_restore 16
458 jalr $zero, $ra
459 move $sp, $t0
460
461.Losr_entry:
462 dsubu $sp, $sp, $a1 # Reserve space for callee stack
463 daddiu $a1, $a1, -8
464 daddu $t0, $a1, $sp
465 sw $ra, 0($t0) # Store low half of RA per compiler ABI
466 dsrl $t1, $ra, 32
467 sw $t1, 4($t0) # Store high half of RA per compiler ABI
468
469 // Copy arguments into callee stack
470 // Use simple copy routine for now.
471 // 4 bytes per slot.
472 // a0 = source address
473 // a1 = args length in bytes (does not include 8 bytes for RA)
474 // sp = destination address
475 beqz $a1, .Losr_loop_exit
476 daddiu $a1, $a1, -4
477 daddu $t1, $a0, $a1
478 daddu $t2, $sp, $a1
479.Losr_loop_entry:
480 lw $t0, 0($t1)
481 daddiu $t1, $t1, -4
482 sw $t0, 0($t2)
483 bne $sp, $t2, .Losr_loop_entry
484 daddiu $t2, $t2, -4
485
486.Losr_loop_exit:
487 move $t9, $a2
488 jalr $zero, $t9 # Jump to the OSR entry point.
489 nop
490END art_quick_osr_stub
491
492 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800493 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
494 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
495 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200496ENTRY_NO_GP art_quick_do_long_jump
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800497 l.d $f0, 0($a1)
498 l.d $f1, 8($a1)
499 l.d $f2, 16($a1)
500 l.d $f3, 24($a1)
501 l.d $f4, 32($a1)
502 l.d $f5, 40($a1)
503 l.d $f6, 48($a1)
504 l.d $f7, 56($a1)
505 l.d $f8, 64($a1)
506 l.d $f9, 72($a1)
507 l.d $f10, 80($a1)
508 l.d $f11, 88($a1)
509 l.d $f12, 96($a1)
510 l.d $f13, 104($a1)
511 l.d $f14, 112($a1)
512 l.d $f15, 120($a1)
513 l.d $f16, 128($a1)
514 l.d $f17, 136($a1)
515 l.d $f18, 144($a1)
516 l.d $f19, 152($a1)
517 l.d $f20, 160($a1)
518 l.d $f21, 168($a1)
519 l.d $f22, 176($a1)
520 l.d $f23, 184($a1)
521 l.d $f24, 192($a1)
522 l.d $f25, 200($a1)
523 l.d $f26, 208($a1)
524 l.d $f27, 216($a1)
525 l.d $f28, 224($a1)
526 l.d $f29, 232($a1)
527 l.d $f30, 240($a1)
528 l.d $f31, 248($a1)
529 .set push
530 .set nomacro
531 .set noat
532# no need to load zero
533 ld $at, 8($a0)
534 .set pop
535 ld $v0, 16($a0)
536 ld $v1, 24($a0)
537# a0 has to be loaded last
538 ld $a1, 40($a0)
539 ld $a2, 48($a0)
540 ld $a3, 56($a0)
541 ld $a4, 64($a0)
542 ld $a5, 72($a0)
543 ld $a6, 80($a0)
544 ld $a7, 88($a0)
545 ld $t0, 96($a0)
546 ld $t1, 104($a0)
547 ld $t2, 112($a0)
548 ld $t3, 120($a0)
549 ld $s0, 128($a0)
550 ld $s1, 136($a0)
551 ld $s2, 144($a0)
552 ld $s3, 152($a0)
553 ld $s4, 160($a0)
554 ld $s5, 168($a0)
555 ld $s6, 176($a0)
556 ld $s7, 184($a0)
557 ld $t8, 192($a0)
558 ld $t9, 200($a0)
559# no need to load k0, k1
560 ld $gp, 224($a0)
561 ld $sp, 232($a0)
562 ld $s8, 240($a0)
563 ld $ra, 248($a0)
564 ld $a0, 32($a0)
565 move $v0, $zero # clear result registers v0 and v1
Andreas Gampedbf056d2015-09-25 08:24:13 -0700566 jalr $zero, $t9 # do long jump (do not use ra, it must not be clobbered)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800567 move $v1, $zero
568END art_quick_do_long_jump
569
Maja Gagic6ea651f2015-02-24 16:55:04 +0100570 /*
571 * Called by managed code, saves most registers (forms basis of long jump
572 * context) and passes the bottom of the stack.
573 * artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200574 * the bottom of the thread. On entry a0 holds Throwable*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100575 */
576ENTRY art_quick_deliver_exception
577 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
578 dla $t9, artDeliverExceptionFromCode
579 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
580 move $a1, rSELF # pass Thread::Current
581END art_quick_deliver_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800582
Maja Gagic6ea651f2015-02-24 16:55:04 +0100583 /*
584 * Called by managed code to create and deliver a NullPointerException
585 */
586 .extern artThrowNullPointerExceptionFromCode
587ENTRY art_quick_throw_null_pointer_exception
588.Lart_quick_throw_null_pointer_exception_gp_set:
589 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
590 dla $t9, artThrowNullPointerExceptionFromCode
591 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
592 move $a0, rSELF # pass Thread::Current
593END art_quick_throw_null_pointer_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800594
Maja Gagic6ea651f2015-02-24 16:55:04 +0100595 /*
596 * Called by managed code to create and deliver an ArithmeticException
597 */
598 .extern artThrowDivZeroFromCode
599ENTRY art_quick_throw_div_zero
600 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
601 dla $t9, artThrowDivZeroFromCode
602 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
603 move $a0, rSELF # pass Thread::Current
604END art_quick_throw_div_zero
605
606 /*
607 * Called by managed code to create and deliver an
608 * ArrayIndexOutOfBoundsException
609 */
610 .extern artThrowArrayBoundsFromCode
611ENTRY art_quick_throw_array_bounds
612.Lart_quick_throw_array_bounds_gp_set:
613 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
614 dla $t9, artThrowArrayBoundsFromCode
615 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
616 move $a2, rSELF # pass Thread::Current
617END art_quick_throw_array_bounds
618
619 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100620 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
621 * as if thrown from a call to String.charAt().
622 */
623 .extern artThrowStringBoundsFromCode
624ENTRY art_quick_throw_string_bounds
625.Lart_quick_throw_string_bounds_gp_set:
626 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
627 dla $t9, artThrowStringBoundsFromCode
628 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
629 move $a2, rSELF # pass Thread::Current
630END art_quick_throw_string_bounds
631
632 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100633 * Called by managed code to create and deliver a StackOverflowError.
634 */
635 .extern artThrowStackOverflowFromCode
636ENTRY art_quick_throw_stack_overflow
637 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
638 dla $t9, artThrowStackOverflowFromCode
639 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
640 move $a0, rSELF # pass Thread::Current
641END art_quick_throw_stack_overflow
642
643 /*
644 * Called by managed code to create and deliver a NoSuchMethodError.
645 */
646 .extern artThrowNoSuchMethodFromCode
647ENTRY art_quick_throw_no_such_method
648 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
649 dla $t9, artThrowNoSuchMethodFromCode
650 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
651 move $a1, rSELF # pass Thread::Current
652END art_quick_throw_no_such_method
653
654 /*
655 * All generated callsites for interface invokes and invocation slow paths will load arguments
656 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
657 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
658 * stack and call the appropriate C helper.
659 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
660 *
661 * The helper will attempt to locate the target and return a 128-bit result in $v0/$v1 consisting
662 * of the target Method* in $v0 and method->code_ in $v1.
663 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700664 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
Maja Gagic6ea651f2015-02-24 16:55:04 +0100665 * thread and we branch to another stub to deliver it.
666 *
667 * On success this wrapper will restore arguments and *jump* to the target, leaving the ra
668 * pointing back to the original caller.
669 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700670.macro INVOKE_TRAMPOLINE_BODY cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100671 .extern \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100672 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100673 move $a2, rSELF # pass Thread::Current
674 jal \cxx_name # (method_idx, this, Thread*, $sp)
675 move $a3, $sp # pass $sp
Maja Gagic6ea651f2015-02-24 16:55:04 +0100676 move $a0, $v0 # save target Method*
677 move $t9, $v1 # save $v0->code_
678 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
679 beq $v0, $zero, 1f
680 nop
681 jalr $zero, $t9
682 nop
6831:
684 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700685.endm
686.macro INVOKE_TRAMPOLINE c_name, cxx_name
687ENTRY \c_name
688 INVOKE_TRAMPOLINE_BODY \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100689END \c_name
690.endm
691
Maja Gagic6ea651f2015-02-24 16:55:04 +0100692INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
693
694INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
695INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
696INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
697INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800698
699 # On entry:
700 # t0 = shorty
701 # t1 = ptr to arg_array
702 # t2 = number of argument bytes remain
703 # v0 = ptr to stack frame where to copy arg_array
704 # This macro modifies t3, t9 and v0
705.macro LOOP_OVER_SHORTY_LOADING_REG gpu, fpu, label
706 lbu $t3, 0($t0) # get argument type from shorty
707 beqz $t3, \label
708 daddiu $t0, 1
709 li $t9, 68 # put char 'D' into t9
710 beq $t9, $t3, 1f # branch if result type char == 'D'
711 li $t9, 70 # put char 'F' into t9
712 beq $t9, $t3, 2f # branch if result type char == 'F'
713 li $t9, 74 # put char 'J' into t9
714 beq $t9, $t3, 3f # branch if result type char == 'J'
715 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +0100716 lw $\gpu, 0($t1)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800717 sw $\gpu, 0($v0)
718 daddiu $v0, 4
719 daddiu $t1, 4
720 b 4f
721 daddiu $t2, -4 # delay slot
722
7231: # found double
724 lwu $t3, 0($t1)
725 mtc1 $t3, $\fpu
726 sw $t3, 0($v0)
727 lwu $t3, 4($t1)
728 mthc1 $t3, $\fpu
729 sw $t3, 4($v0)
730 daddiu $v0, 8
731 daddiu $t1, 8
732 b 4f
733 daddiu $t2, -8 # delay slot
734
7352: # found float
736 lwu $t3, 0($t1)
737 mtc1 $t3, $\fpu
738 sw $t3, 0($v0)
739 daddiu $v0, 4
740 daddiu $t1, 4
741 b 4f
742 daddiu $t2, -4 # delay slot
743
7443: # found long (8 bytes)
745 lwu $t3, 0($t1)
746 sw $t3, 0($v0)
747 lwu $t9, 4($t1)
748 sw $t9, 4($v0)
749 dsll $t9, $t9, 32
750 or $\gpu, $t9, $t3
751 daddiu $v0, 8
752 daddiu $t1, 8
753 daddiu $t2, -8
7544:
755.endm
756
757 /*
758 * Invocation stub for quick code.
759 * On entry:
760 * a0 = method pointer
761 * a1 = argument array that must at least contain the this ptr.
762 * a2 = size of argument array in bytes
763 * a3 = (managed) thread pointer
764 * a4 = JValue* result
765 * a5 = shorty
766 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200767ENTRY_NO_GP art_quick_invoke_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800768 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra onto the stack
769 daddiu $sp, $sp, -48
770 .cfi_adjust_cfa_offset 48
771 sd $ra, 40($sp)
772 .cfi_rel_offset 31, 40
773 sd $s8, 32($sp)
774 .cfi_rel_offset 30, 32
775 sd $s1, 24($sp)
776 .cfi_rel_offset 17, 24
777 sd $s0, 16($sp)
778 .cfi_rel_offset 16, 16
779 sd $a5, 8($sp)
780 .cfi_rel_offset 9, 8
781 sd $a4, 0($sp)
782 .cfi_rel_offset 8, 0
783
784 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
785 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
786 move $s8, $sp # save sp in s8 (fp)
787
Mathieu Chartiere401d142015-04-22 13:56:20 -0700788 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800789 dsrl $t3, $t3, 4 # shift the frame size right 4
790 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
791 dsubu $sp, $sp, $t3 # reserve stack space for argument array
792
793 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
794 daddiu $t1, $a1, 4 # t1 = ptr to arg_array[4] (skip this ptr)
795 daddiu $t2, $a2, -4 # t2 = number of argument bytes remain (skip this ptr)
Nikola Veljkovic80f7a572015-06-02 17:27:53 +0200796 daddiu $v0, $sp, 12 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800797 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_fn
798 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_fn
799 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_fn
800 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_fn
801 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_fn
802 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_fn
803
804 # copy arguments onto stack (t2 should be multiples of 4)
805 ble $t2, $zero, call_fn # t2 = number of argument bytes remain
8061:
807 lw $t3, 0($t1) # load from argument array
808 daddiu $t1, $t1, 4
809 sw $t3, 0($v0) # save to stack
810 daddiu $t2, -4
811 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
812 daddiu $v0, $v0, 4
813
814call_fn:
815 # call method (a0 and a1 have been untouched)
816 lwu $a1, 0($a1) # make a1 = this ptr
Mathieu Chartiere401d142015-04-22 13:56:20 -0700817 sw $a1, 8($sp) # copy this ptr (skip 8 bytes for ArtMethod*)
818 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
819 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800820 jalr $t9 # call the method
821 nop
822 move $sp, $s8 # restore sp
823
824 # pop a4, a5, s1(rSELF), s8, ra off of the stack
825 ld $a4, 0($sp)
826 .cfi_restore 8
827 ld $a5, 8($sp)
828 .cfi_restore 9
829 ld $s0, 16($sp)
830 .cfi_restore 16
831 ld $s1, 24($sp)
832 .cfi_restore 17
833 ld $s8, 32($sp)
834 .cfi_restore 30
835 ld $ra, 40($sp)
836 .cfi_restore 31
837 daddiu $sp, $sp, 48
838 .cfi_adjust_cfa_offset -48
839
840 # a4 = JValue* result
841 # a5 = shorty string
842 lbu $t1, 0($a5) # get result type from shorty
843 li $t2, 68 # put char 'D' into t2
844 beq $t1, $t2, 1f # branch if result type char == 'D'
845 li $t3, 70 # put char 'F' into t3
846 beq $t1, $t3, 1f # branch if result type char == 'F'
847 sw $v0, 0($a4) # store the result
848 dsrl $v1, $v0, 32
849 jalr $zero, $ra
850 sw $v1, 4($a4) # store the other half of the result
8511:
852 mfc1 $v0, $f0
853 mfhc1 $v1, $f0
854 sw $v0, 0($a4) # store the result
855 jalr $zero, $ra
856 sw $v1, 4($a4) # store the other half of the result
857END art_quick_invoke_stub
858
859 /*
860 * Invocation static stub for quick code.
861 * On entry:
862 * a0 = method pointer
863 * a1 = argument array that must at least contain the this ptr.
864 * a2 = size of argument array in bytes
865 * a3 = (managed) thread pointer
866 * a4 = JValue* result
867 * a5 = shorty
868 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200869ENTRY_NO_GP art_quick_invoke_static_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800870
871 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra, onto the stack
872 daddiu $sp, $sp, -48
873 .cfi_adjust_cfa_offset 48
874 sd $ra, 40($sp)
875 .cfi_rel_offset 31, 40
876 sd $s8, 32($sp)
877 .cfi_rel_offset 30, 32
878 sd $s1, 24($sp)
879 .cfi_rel_offset 17, 24
880 sd $s0, 16($sp)
881 .cfi_rel_offset 16, 16
882 sd $a5, 8($sp)
883 .cfi_rel_offset 9, 8
884 sd $a4, 0($sp)
885 .cfi_rel_offset 8, 0
886
887 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
888 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
889 move $s8, $sp # save sp in s8 (fp)
890
Mathieu Chartiere401d142015-04-22 13:56:20 -0700891 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800892 dsrl $t3, $t3, 4 # shift the frame size right 4
893 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
894 dsubu $sp, $sp, $t3 # reserve stack space for argument array
895
896 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
897 move $t1, $a1 # t1 = arg_array
898 move $t2, $a2 # t2 = number of argument bytes remain
Mathieu Chartiere401d142015-04-22 13:56:20 -0700899 daddiu $v0, $sp, 8 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800900 LOOP_OVER_SHORTY_LOADING_REG a1, f13, call_sfn
901 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_sfn
902 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_sfn
903 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_sfn
904 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_sfn
905 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_sfn
906 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_sfn
907
908 # copy arguments onto stack (t2 should be multiples of 4)
909 ble $t2, $zero, call_sfn # t2 = number of argument bytes remain
9101:
911 lw $t3, 0($t1) # load from argument array
912 daddiu $t1, $t1, 4
913 sw $t3, 0($v0) # save to stack
914 daddiu $t2, -4
915 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
916 daddiu $v0, $v0, 4
917
918call_sfn:
919 # call method (a0 has been untouched)
Mathieu Chartiere401d142015-04-22 13:56:20 -0700920 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
921 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800922 jalr $t9 # call the method
923 nop
924 move $sp, $s8 # restore sp
925
926 # pop a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra off of the stack
927 ld $a4, 0($sp)
928 .cfi_restore 8
929 ld $a5, 8($sp)
930 .cfi_restore 9
931 ld $s0, 16($sp)
932 .cfi_restore 16
933 ld $s1, 24($sp)
934 .cfi_restore 17
935 ld $s8, 32($sp)
936 .cfi_restore 30
937 ld $ra, 40($sp)
938 .cfi_restore 31
939 daddiu $sp, $sp, 48
940 .cfi_adjust_cfa_offset -48
941
942 # a4 = JValue* result
943 # a5 = shorty string
944 lbu $t1, 0($a5) # get result type from shorty
945 li $t2, 68 # put char 'D' into t2
946 beq $t1, $t2, 1f # branch if result type char == 'D'
947 li $t3, 70 # put char 'F' into t3
948 beq $t1, $t3, 1f # branch if result type char == 'F'
949 sw $v0, 0($a4) # store the result
950 dsrl $v1, $v0, 32
951 jalr $zero, $ra
952 sw $v1, 4($a4) # store the other half of the result
9531:
954 mfc1 $v0, $f0
955 mfhc1 $v1, $f0
956 sw $v0, 0($a4) # store the result
957 jalr $zero, $ra
958 sw $v1, 4($a4) # store the other half of the result
959END art_quick_invoke_static_stub
960
Maja Gagic6ea651f2015-02-24 16:55:04 +0100961 /*
962 * Entry from managed code that calls artHandleFillArrayDataFromCode and
963 * delivers exception on failure.
964 */
965 .extern artHandleFillArrayDataFromCode
966ENTRY art_quick_handle_fill_data
967 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Mathieu Chartiere401d142015-04-22 13:56:20 -0700968 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100969 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*)
970 move $a3, rSELF # pass Thread::Current
971 RETURN_IF_ZERO
972END art_quick_handle_fill_data
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800973
Maja Gagic6ea651f2015-02-24 16:55:04 +0100974 /*
975 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
976 */
977 .extern artLockObjectFromCode
978ENTRY art_quick_lock_object
979 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
980 nop
981 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
982 jal artLockObjectFromCode # (Object* obj, Thread*)
983 move $a1, rSELF # pass Thread::Current
984 RETURN_IF_ZERO
985END art_quick_lock_object
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800986
Andreas Gampec7ed09b2016-04-25 20:08:55 -0700987ENTRY art_quick_lock_object_no_inline
988 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
989 nop
990 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
991 jal artLockObjectFromCode # (Object* obj, Thread*)
992 move $a1, rSELF # pass Thread::Current
993 RETURN_IF_ZERO
994END art_quick_lock_object_no_inline
995
Maja Gagic6ea651f2015-02-24 16:55:04 +0100996 /*
997 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
998 */
999 .extern artUnlockObjectFromCode
1000ENTRY art_quick_unlock_object
1001 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1002 nop
1003 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
1004 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1005 move $a1, rSELF # pass Thread::Current
1006 RETURN_IF_ZERO
1007END art_quick_unlock_object
1008
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001009ENTRY art_quick_unlock_object_no_inline
1010 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1011 nop
1012 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
1013 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1014 move $a1, rSELF # pass Thread::Current
1015 RETURN_IF_ZERO
1016END art_quick_unlock_object_no_inline
1017
Maja Gagic6ea651f2015-02-24 16:55:04 +01001018 /*
1019 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1020 */
1021 .extern artThrowClassCastException
1022ENTRY art_quick_check_cast
1023 daddiu $sp, $sp, -32
1024 .cfi_adjust_cfa_offset 32
1025 sd $ra, 24($sp)
1026 .cfi_rel_offset 31, 24
1027 sd $t9, 16($sp)
1028 sd $a1, 8($sp)
1029 sd $a0, 0($sp)
1030 jal artIsAssignableFromCode
Goran Jakovljevic04568812015-04-23 15:27:23 +02001031 .cpreturn # Restore gp from t8 in branch delay slot.
1032 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001033 beq $v0, $zero, .Lthrow_class_cast_exception
1034 ld $ra, 24($sp)
1035 jalr $zero, $ra
1036 daddiu $sp, $sp, 32
1037 .cfi_adjust_cfa_offset -32
1038.Lthrow_class_cast_exception:
1039 ld $t9, 16($sp)
1040 ld $a1, 8($sp)
1041 ld $a0, 0($sp)
1042 daddiu $sp, $sp, 32
1043 .cfi_adjust_cfa_offset -32
Goran Jakovljevic04568812015-04-23 15:27:23 +02001044 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001045 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1046 dla $t9, artThrowClassCastException
1047 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
1048 move $a2, rSELF # pass Thread::Current
1049END art_quick_check_cast
1050
Man Cao1aee9002015-07-14 22:31:42 -07001051
1052 /*
1053 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1054 * nReg is the register number for rReg.
1055 */
1056.macro POP_REG_NE rReg, nReg, offset, rExclude
1057 .ifnc \rReg, \rExclude
1058 ld \rReg, \offset($sp) # restore rReg
1059 .cfi_restore \nReg
1060 .endif
1061.endm
1062
1063 /*
1064 * Macro to insert read barrier, only used in art_quick_aput_obj.
1065 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1066 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1067 */
1068.macro READ_BARRIER rDest, rObj, offset
1069#ifdef USE_READ_BARRIER
1070 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 16B-aligned.
1071 daddiu $sp, $sp, -64
1072 .cfi_adjust_cfa_offset 64
1073 sd $ra, 56($sp)
1074 .cfi_rel_offset 31, 56
1075 sd $t9, 48($sp)
1076 .cfi_rel_offset 25, 48
1077 sd $t1, 40($sp)
1078 .cfi_rel_offset 13, 40
1079 sd $t0, 32($sp)
1080 .cfi_rel_offset 12, 32
1081 sd $a2, 16($sp) # padding slot at offset 24 (padding can be any slot in the 64B)
1082 .cfi_rel_offset 6, 16
1083 sd $a1, 8($sp)
1084 .cfi_rel_offset 5, 8
1085 sd $a0, 0($sp)
1086 .cfi_rel_offset 4, 0
1087
Man Cao63069212015-08-21 15:51:39 -07001088 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001089 .ifnc \rObj, $a1
1090 move $a1, \rObj # pass rObj
1091 .endif
1092 daddiu $a2, $zero, \offset # pass offset
1093 jal artReadBarrierSlow # artReadBarrierSlow(ref, rObj, offset)
1094 .cpreturn # Restore gp from t8 in branch delay slot.
1095 # t8 may be clobbered in artReadBarrierSlow.
1096 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1097 move \rDest, $v0 # save return value in rDest
1098 # (rDest cannot be v0 in art_quick_aput_obj)
1099
1100 ld $a0, 0($sp) # restore registers except rDest
1101 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1102 .cfi_restore 4
1103 ld $a1, 8($sp)
1104 .cfi_restore 5
1105 ld $a2, 16($sp)
1106 .cfi_restore 6
1107 POP_REG_NE $t0, 12, 32, \rDest
1108 POP_REG_NE $t1, 13, 40, \rDest
1109 ld $t9, 48($sp)
1110 .cfi_restore 25
1111 ld $ra, 56($sp) # restore $ra
1112 .cfi_restore 31
1113 daddiu $sp, $sp, 64
1114 .cfi_adjust_cfa_offset -64
1115 SETUP_GP # set up gp because we are not returning
1116#else
1117 lwu \rDest, \offset(\rObj)
1118 UNPOISON_HEAP_REF \rDest
1119#endif // USE_READ_BARRIER
1120.endm
1121
Maja Gagic6ea651f2015-02-24 16:55:04 +01001122 /*
1123 * Entry from managed code for array put operations of objects where the value being stored
1124 * needs to be checked for compatibility.
1125 * a0 = array, a1 = index, a2 = value
1126 */
1127ENTRY art_quick_aput_obj_with_null_and_bound_check
1128 bne $a0, $zero, .Lart_quick_aput_obj_with_bound_check_gp_set
1129 nop
1130 b .Lart_quick_throw_null_pointer_exception_gp_set
1131 nop
1132END art_quick_aput_obj_with_null_and_bound_check
1133
1134ENTRY art_quick_aput_obj_with_bound_check
1135 lwu $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
1136 sltu $t1, $a1, $t0
1137 bne $t1, $zero, .Lart_quick_aput_obj_gp_set
1138 nop
1139 move $a0, $a1
1140 b .Lart_quick_throw_array_bounds_gp_set
1141 move $a1, $t0
1142END art_quick_aput_obj_with_bound_check
1143
1144ENTRY art_quick_aput_obj
1145 beq $a2, $zero, .Ldo_aput_null
1146 nop
Man Cao1aee9002015-07-14 22:31:42 -07001147 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1148 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1149 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Maja Gagic6ea651f2015-02-24 16:55:04 +01001150 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
1151 nop
1152.Ldo_aput:
1153 dsll $a1, $a1, 2
1154 daddu $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001155 POISON_HEAP_REF $a2
Maja Gagic6ea651f2015-02-24 16:55:04 +01001156 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1157 ld $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1158 dsrl $t1, $a0, 7
1159 daddu $t1, $t1, $t0
1160 sb $t0, ($t1)
1161 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001162 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001163.Ldo_aput_null:
1164 dsll $a1, $a1, 2
1165 daddu $t0, $a0, $a1
1166 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1167 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001168 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001169.Lcheck_assignability:
1170 daddiu $sp, $sp, -64
1171 .cfi_adjust_cfa_offset 64
1172 sd $ra, 56($sp)
1173 .cfi_rel_offset 31, 56
1174 sd $t9, 24($sp)
1175 sd $a2, 16($sp)
1176 sd $a1, 8($sp)
1177 sd $a0, 0($sp)
1178 move $a1, $t1
1179 move $a0, $t0
1180 jal artIsAssignableFromCode # (Class*, Class*)
Goran Jakovljevic04568812015-04-23 15:27:23 +02001181 .cpreturn # Restore gp from t8 in branch delay slot.
1182 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001183 ld $ra, 56($sp)
1184 ld $t9, 24($sp)
1185 ld $a2, 16($sp)
1186 ld $a1, 8($sp)
1187 ld $a0, 0($sp)
1188 daddiu $sp, $sp, 64
1189 .cfi_adjust_cfa_offset -64
Goran Jakovljevic04568812015-04-23 15:27:23 +02001190 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001191 bne $v0, $zero, .Ldo_aput
1192 nop
1193 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1194 move $a1, $a2
1195 dla $t9, artThrowArrayStoreException
1196 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
1197 move $a2, rSELF # pass Thread::Current
1198END art_quick_aput_obj
1199
1200 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001201 * Called by managed code to resolve a static field and load a boolean primitive value.
1202 */
1203 .extern artGetBooleanStaticFromCode
1204ENTRY art_quick_get_boolean_static
1205 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001206 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001207 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1208 move $a2, rSELF # pass Thread::Current
1209 RETURN_IF_NO_EXCEPTION
1210END art_quick_get_boolean_static
1211
1212 /*
1213 * Called by managed code to resolve a static field and load a byte primitive value.
1214 */
1215 .extern artGetByteStaticFromCode
1216ENTRY art_quick_get_byte_static
1217 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001218 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001219 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1220 move $a2, rSELF # pass Thread::Current
1221 RETURN_IF_NO_EXCEPTION
1222END art_quick_get_byte_static
1223
1224 /*
1225 * Called by managed code to resolve a static field and load a char primitive value.
1226 */
1227 .extern artGetCharStaticFromCode
1228ENTRY art_quick_get_char_static
1229 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001230 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001231 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1232 move $a2, rSELF # pass Thread::Current
1233 RETURN_IF_NO_EXCEPTION
1234END art_quick_get_char_static
1235
1236 /*
1237 * Called by managed code to resolve a static field and load a short primitive value.
1238 */
1239 .extern artGetShortStaticFromCode
1240ENTRY art_quick_get_short_static
1241 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001242 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001243 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1244 move $a2, rSELF # pass Thread::Current
1245 RETURN_IF_NO_EXCEPTION
1246END art_quick_get_short_static
1247
1248 /*
1249 * Called by managed code to resolve a static field and load a 32-bit primitive value.
1250 */
1251 .extern artGet32StaticFromCode
1252ENTRY art_quick_get32_static
1253 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001254 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001255 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1256 move $a2, rSELF # pass Thread::Current
1257 RETURN_IF_NO_EXCEPTION
1258END art_quick_get32_static
1259
1260 /*
1261 * Called by managed code to resolve a static field and load a 64-bit primitive value.
1262 */
1263 .extern artGet64StaticFromCode
1264ENTRY art_quick_get64_static
1265 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001266 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001267 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1268 move $a2, rSELF # pass Thread::Current
1269 RETURN_IF_NO_EXCEPTION
1270END art_quick_get64_static
1271
1272 /*
1273 * Called by managed code to resolve a static field and load an object reference.
1274 */
1275 .extern artGetObjStaticFromCode
1276ENTRY art_quick_get_obj_static
1277 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001278 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001279 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1280 move $a2, rSELF # pass Thread::Current
1281 RETURN_IF_NO_EXCEPTION
1282END art_quick_get_obj_static
1283
1284 /*
1285 * Called by managed code to resolve an instance field and load a boolean primitive value.
1286 */
1287 .extern artGetBooleanInstanceFromCode
1288ENTRY art_quick_get_boolean_instance
1289 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001290 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001291 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1292 move $a3, rSELF # pass Thread::Current
1293 RETURN_IF_NO_EXCEPTION
1294END art_quick_get_boolean_instance
1295
1296 /*
1297 * Called by managed code to resolve an instance field and load a byte primitive value.
1298 */
1299 .extern artGetByteInstanceFromCode
1300ENTRY art_quick_get_byte_instance
1301 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001302 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001303 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1304 move $a3, rSELF # pass Thread::Current
1305 RETURN_IF_NO_EXCEPTION
1306END art_quick_get_byte_instance
1307
1308 /*
1309 * Called by managed code to resolve an instance field and load a char primitive value.
1310 */
1311 .extern artGetCharInstanceFromCode
1312ENTRY art_quick_get_char_instance
1313 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001314 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001315 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1316 move $a3, rSELF # pass Thread::Current
1317 RETURN_IF_NO_EXCEPTION
1318END art_quick_get_char_instance
1319
1320 /*
1321 * Called by managed code to resolve an instance field and load a short primitive value.
1322 */
1323 .extern artGetShortInstanceFromCode
1324ENTRY art_quick_get_short_instance
1325 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001326 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001327 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1328 move $a3, rSELF # pass Thread::Current
1329 RETURN_IF_NO_EXCEPTION
1330END art_quick_get_short_instance
1331
1332 /*
1333 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1334 */
1335 .extern artGet32InstanceFromCode
1336ENTRY art_quick_get32_instance
1337 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001338 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001339 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1340 move $a3, rSELF # pass Thread::Current
1341 RETURN_IF_NO_EXCEPTION
1342END art_quick_get32_instance
1343
1344 /*
1345 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1346 */
1347 .extern artGet64InstanceFromCode
1348ENTRY art_quick_get64_instance
1349 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001350 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001351 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1352 move $a3, rSELF # pass Thread::Current
1353 RETURN_IF_NO_EXCEPTION
1354END art_quick_get64_instance
1355
1356 /*
1357 * Called by managed code to resolve an instance field and load an object reference.
1358 */
1359 .extern artGetObjInstanceFromCode
1360ENTRY art_quick_get_obj_instance
1361 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001362 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001363 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1364 move $a3, rSELF # pass Thread::Current
1365 RETURN_IF_NO_EXCEPTION
1366END art_quick_get_obj_instance
1367
1368 /*
1369 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1370 */
1371 .extern artSet8StaticFromCode
1372ENTRY art_quick_set8_static
1373 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001374 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001375 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
1376 move $a3, rSELF # pass Thread::Current
1377 RETURN_IF_ZERO
1378END art_quick_set8_static
1379
1380 /*
1381 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1382 */
1383 .extern artSet16StaticFromCode
1384ENTRY art_quick_set16_static
1385 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001386 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001387 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*)
1388 move $a3, rSELF # pass Thread::Current
1389 RETURN_IF_ZERO
1390END art_quick_set16_static
1391
1392 /*
1393 * Called by managed code to resolve a static field and store a 32-bit primitive value.
1394 */
1395 .extern artSet32StaticFromCode
1396ENTRY art_quick_set32_static
1397 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001398 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001399 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
1400 move $a3, rSELF # pass Thread::Current
1401 RETURN_IF_ZERO
1402END art_quick_set32_static
1403
1404 /*
1405 * Called by managed code to resolve a static field and store a 64-bit primitive value.
1406 */
1407 .extern artSet64StaticFromCode
1408ENTRY art_quick_set64_static
1409 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001410 # a2 contains the new val
Mathieu Chartiere401d142015-04-22 13:56:20 -07001411 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001412 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
1413 move $a3, rSELF # pass Thread::Current
1414 RETURN_IF_ZERO
1415END art_quick_set64_static
1416
1417 /*
1418 * Called by managed code to resolve a static field and store an object reference.
1419 */
1420 .extern artSetObjStaticFromCode
1421ENTRY art_quick_set_obj_static
1422 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001423 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001424 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
1425 move $a3, rSELF # pass Thread::Current
1426 RETURN_IF_ZERO
1427END art_quick_set_obj_static
1428
1429 /*
1430 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1431 */
1432 .extern artSet8InstanceFromCode
1433ENTRY art_quick_set8_instance
1434 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001435 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001436 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1437 move $a4, rSELF # pass Thread::Current
1438 RETURN_IF_ZERO
1439END art_quick_set8_instance
1440
1441 /*
1442 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1443 */
1444 .extern artSet16InstanceFromCode
1445ENTRY art_quick_set16_instance
1446 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001447 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001448 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1449 move $a4, rSELF # pass Thread::Current
1450 RETURN_IF_ZERO
1451END art_quick_set16_instance
1452
1453 /*
1454 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1455 */
1456 .extern artSet32InstanceFromCode
1457ENTRY art_quick_set32_instance
1458 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001459 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001460 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1461 move $a4, rSELF # pass Thread::Current
1462 RETURN_IF_ZERO
1463END art_quick_set32_instance
1464
1465 /*
1466 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1467 */
1468 .extern artSet64InstanceFromCode
1469ENTRY art_quick_set64_instance
1470 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001471 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001472 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1473 move $a4, rSELF # pass Thread::Current
1474 RETURN_IF_ZERO
1475END art_quick_set64_instance
1476
1477 /*
1478 * Called by managed code to resolve an instance field and store an object reference.
1479 */
1480 .extern artSetObjInstanceFromCode
1481ENTRY art_quick_set_obj_instance
1482 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001483 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001484 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1485 move $a4, rSELF # pass Thread::Current
1486 RETURN_IF_ZERO
1487END art_quick_set_obj_instance
1488
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001489// Macro to facilitate adding new allocation entrypoints.
1490.macro ONE_ARG_DOWNCALL name, entrypoint, return
1491 .extern \entrypoint
1492ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001493 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001494 jal \entrypoint
1495 move $a1, rSELF # pass Thread::Current
1496 \return
1497END \name
1498.endm
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001499
1500// Macro to facilitate adding new allocation entrypoints.
1501.macro TWO_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001502 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001503ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001504 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1505 jal \entrypoint
1506 move $a2, rSELF # pass Thread::Current
1507 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001508END \name
1509.endm
1510
1511.macro THREE_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001512 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001513ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001514 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1515 jal \entrypoint
1516 move $a3, rSELF # pass Thread::Current
1517 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001518END \name
1519.endm
1520
Vladimir Markoe85e1232015-04-28 14:14:58 +01001521.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1522 .extern \entrypoint
1523ENTRY \name
1524 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1525 jal \entrypoint
1526 move $a4, rSELF # pass Thread::Current
1527 \return
1528END \name
1529.endm
1530
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001531// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001532GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001533
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001534// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1535ENTRY art_quick_alloc_object_rosalloc
1536
1537 # Fast path rosalloc allocation
1538 # a0: type_idx
1539 # a1: ArtMethod*
1540 # s1: Thread::Current
1541 # -----------------------------
1542 # t0: class
1543 # t1: object size
1544 # t2: rosalloc run
1545 # t3: thread stack top offset
1546 # a4: thread stack bottom offset
1547 # v0: free list head
1548 #
1549 # a5, a6 : temps
1550
1551 ld $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_64($a1) # Load dex cache resolved types array.
1552
1553 dsll $a5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1554 daddu $a5, $t0, $a5 # Compute the index.
1555 lwu $t0, 0($a5) # Load class (t0).
1556 beqzc $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1557
1558 li $a6, MIRROR_CLASS_STATUS_INITIALIZED
1559 lwu $a5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1560 bnec $a5, $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1561
1562 # Add a fake dependence from the following access flag and size loads to the status load. This
1563 # is to prevent those loads from being reordered above the status load and reading wrong values.
1564 xor $a5, $a5, $a5
1565 daddu $t0, $t0, $a5
1566
1567 lwu $a5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1568 li $a6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1569 and $a6, $a5, $a6
1570 bnezc $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1571
1572 ld $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation stack
1573 ld $a4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # has any room left.
1574 bgeuc $t3, $a4, .Lart_quick_alloc_object_rosalloc_slow_path
1575
1576 lwu $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1577 li $a5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1578 # allocation.
1579 bltuc $a5, $t1, .Lart_quick_alloc_object_rosalloc_slow_path
1580
1581 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1582 # quantum size and divide by the quantum size and subtract by 1.
1583 daddiu $t1, $t1, -1 # Decrease obj size and shift right by
1584 dsrl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # quantum.
1585
1586 dsll $t2, $t1, POINTER_SIZE_SHIFT
1587 daddu $t2, $t2, $s1
1588 ld $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1589
1590 # Load the free list head (v0).
1591 # NOTE: this will be the return val.
1592 ld $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1593 beqzc $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1594
1595 # Load the next pointer of the head and update the list head with the next pointer.
1596 ld $a5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1597 sd $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1598
1599 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1600 # asserted to match.
1601
1602#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1603#error "Class pointer needs to overwrite next pointer."
1604#endif
1605
1606 POISON_HEAP_REF $t0
1607 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1608
1609 # Push the new object onto the thread local allocation stack and increment the thread local
1610 # allocation stack top.
1611 sd $v0, 0($t3)
1612 daddiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1613 sd $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1614
1615 # Decrement the size of the free list.
1616 lw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1617 addiu $a5, $a5, -1
1618 sw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1619
1620 sync # Fence.
1621
1622 jalr $zero, $ra
1623 .cpreturn # Restore gp from t8 in branch delay slot.
1624
1625.Lart_quick_alloc_object_rosalloc_slow_path:
1626 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1627 jal artAllocObjectFromCodeRosAlloc
1628 move $a2 ,$s1 # Pass self as argument.
1629 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1630
1631END art_quick_alloc_object_rosalloc
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001632
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001633GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1634GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1635
Maja Gagic6ea651f2015-02-24 16:55:04 +01001636 /*
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001637 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1638 * exception on error. On success the String is returned. A0 holds the string index. The fast
1639 * path check for hit in strings cache has already been performed.
1640 */
1641ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1642
1643 /*
1644 * Entry from managed code when uninitialized static storage, this stub will run the class
1645 * initializer and deliver the exception on error. On success the static storage base is
1646 * returned.
1647 */
1648ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1649
1650 /*
1651 * Entry from managed code when dex cache misses for a type_idx.
1652 */
1653ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1654
1655 /*
1656 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1657 * miss.
1658 */
1659ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1660
1661 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001662 * Called by managed code when the value in rSUSPEND has been decremented to 0.
1663 */
1664 .extern artTestSuspendFromCode
1665ENTRY art_quick_test_suspend
1666 lh $a0, THREAD_FLAGS_OFFSET(rSELF)
1667 bne $a0, $zero, 1f
1668 daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1669 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001670 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +010016711:
1672 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves for stack crawl
1673 jal artTestSuspendFromCode # (Thread*)
1674 move $a0, rSELF
1675 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
1676END art_quick_test_suspend
Douglas Leung6461d192015-01-30 18:13:58 -08001677
1678 /*
1679 * Called by managed code that is attempting to call a method on a proxy class. On entry
1680 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1681 */
1682 .extern artQuickProxyInvokeHandler
1683ENTRY art_quick_proxy_invoke_handler
Douglas Leung8223b802015-04-28 17:22:29 -07001684 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
Douglas Leung6461d192015-01-30 18:13:58 -08001685 move $a2, rSELF # pass Thread::Current
1686 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
1687 move $a3, $sp # pass $sp
1688 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1689 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
1690 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1691 bne $t0, $zero, 1f
1692 dmtc1 $v0, $f0 # place return value to FP return value
1693 jalr $zero, $ra
1694 dmtc1 $v1, $f1 # place return value to FP return value
16951:
1696 DELIVER_PENDING_EXCEPTION
1697END art_quick_proxy_invoke_handler
1698
Maja Gagic6ea651f2015-02-24 16:55:04 +01001699 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001700 * Called to resolve an imt conflict.
1701 * a0 is the conflict ArtMethod.
1702 * t0 is a hidden argument that holds the target interface method's dex method index.
1703 *
1704 * Mote that this stub writes to a0, t0 and t1.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001705 */
1706ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001707 ld $t1, 0($sp) # Load referrer.
1708 ld $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_64($t1) # Load dex cache methods array.
1709 dsll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1710 daddu $t0, $t1, $t0 # Add offset to base.
1711 ld $t0, 0($t0) # Load interface method.
1712 ld $a0, ART_METHOD_JNI_OFFSET_64($a0) # Load ImtConflictTable.
1713
1714.Limt_table_iterate:
1715 ld $t1, 0($a0) # Load next entry in ImtConflictTable.
1716 # Branch if found.
1717 beq $t1, $t0, .Limt_table_found
1718 nop
1719 # If the entry is null, the interface method is not in the ImtConflictTable.
1720 beqzc $t1, .Lconflict_trampoline
1721 # Iterate over the entries of the ImtConflictTable.
1722 daddiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1723 bc .Limt_table_iterate
1724
1725.Limt_table_found:
1726 # We successfully hit an entry in the table. Load the target method and jump to it.
1727 ld $a0, __SIZEOF_POINTER__($a0)
1728 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)
1729 jr $t9
1730 .cpreturn # Restore gp from t8 in branch delay slot.
1731
1732.Lconflict_trampoline:
1733 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001734 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Maja Gagic6ea651f2015-02-24 16:55:04 +01001735END art_quick_imt_conflict_trampoline
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001736
1737 .extern artQuickResolutionTrampoline
1738ENTRY art_quick_resolution_trampoline
1739 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1740 move $a2, rSELF # pass Thread::Current
1741 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
1742 move $a3, $sp # pass $sp
1743 beq $v0, $zero, 1f
Mathieu Chartiere401d142015-04-22 13:56:20 -07001744 ld $a0, 0($sp) # load resolved method in $a0
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001745 # artQuickResolutionTrampoline puts resolved method in *SP
1746 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1747 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
1748 jalr $zero, $t9 # tail call to method
1749 nop
17501:
1751 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1752 DELIVER_PENDING_EXCEPTION
1753END art_quick_resolution_trampoline
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001754
1755 .extern artQuickGenericJniTrampoline
1756 .extern artQuickGenericJniEndTrampoline
1757ENTRY art_quick_generic_jni_trampoline
Douglas Leung8223b802015-04-28 17:22:29 -07001758 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001759 move $s8, $sp # save $sp
1760
1761 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1762 move $a0, rSELF # pass Thread::Current
1763 move $a1, $sp # pass $sp
1764 jal artQuickGenericJniTrampoline # (Thread*, SP)
1765 daddiu $sp, $sp, -5120 # reserve space on the stack
1766
1767 # The C call will have registered the complete save-frame on success.
1768 # The result of the call is:
1769 # v0: ptr to native code, 0 on error.
1770 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1771 beq $v0, $zero, 1f # check entry error
1772 move $t9, $v0 # save the code ptr
1773 move $sp, $v1 # release part of the alloca
1774
1775 # Load parameters from stack into registers
1776 ld $a0, 0($sp)
1777 ld $a1, 8($sp)
1778 ld $a2, 16($sp)
1779 ld $a3, 24($sp)
1780 ld $a4, 32($sp)
1781 ld $a5, 40($sp)
1782 ld $a6, 48($sp)
1783 ld $a7, 56($sp)
1784 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1785 l.d $f12, 0($sp)
1786 l.d $f13, 8($sp)
1787 l.d $f14, 16($sp)
1788 l.d $f15, 24($sp)
1789 l.d $f16, 32($sp)
1790 l.d $f17, 40($sp)
1791 l.d $f18, 48($sp)
1792 l.d $f19, 56($sp)
1793 jalr $t9 # native call
1794 daddiu $sp, $sp, 64
1795
1796 # result sign extension is handled in C code
1797 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1798 move $a0, rSELF # pass Thread::Current
1799 move $a1, $v0
1800 jal artQuickGenericJniEndTrampoline
1801 dmfc1 $a2, $f0
1802
1803 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001804 bne $t0, $zero, 1f # check for pending exceptions
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001805 move $sp, $s8 # tear down the alloca
1806
1807 # tear dpown the callee-save frame
1808 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1809
1810 jalr $zero, $ra
1811 dmtc1 $v0, $f0 # place return value to FP return value
1812
18131:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001814 ld $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
1815 # This will create a new save-all frame, required by the runtime.
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001816 DELIVER_PENDING_EXCEPTION
1817END art_quick_generic_jni_trampoline
1818
1819 .extern artQuickToInterpreterBridge
1820ENTRY art_quick_to_interpreter_bridge
1821 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1822 move $a1, rSELF # pass Thread::Current
1823 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
1824 move $a2, $sp # pass $sp
1825 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1826 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
1827 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1828 bne $t0, $zero, 1f
1829 dmtc1 $v0, $f0 # place return value to FP return value
1830 jalr $zero, $ra
1831 dmtc1 $v1, $f1 # place return value to FP return value
18321:
1833 DELIVER_PENDING_EXCEPTION
1834END art_quick_to_interpreter_bridge
1835
1836 /*
1837 * Routine that intercepts method calls and returns.
1838 */
1839 .extern artInstrumentationMethodEntryFromCode
1840 .extern artInstrumentationMethodExitFromCode
1841ENTRY art_quick_instrumentation_entry
1842 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1843 daddiu $sp, $sp, -16 # space for saving arg0
1844 .cfi_adjust_cfa_offset 16
1845 sd $a0, 0($sp) # save arg0
1846 move $a3, $ra # pass $ra
1847 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, RA)
1848 move $a2, rSELF # pass Thread::Current
1849 move $t9, $v0 # $t9 holds reference to code
1850 ld $a0, 0($sp) # restore arg0
1851 daddiu $sp, $sp, 16 # remove args
1852 .cfi_adjust_cfa_offset -16
1853 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1854 jalr $t9 # call method
1855 nop
1856END art_quick_instrumentation_entry
1857 /* intentional fallthrough */
1858 .global art_quick_instrumentation_exit
1859art_quick_instrumentation_exit:
1860 .cfi_startproc
Goran Jakovljevic04568812015-04-23 15:27:23 +02001861 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001862 move $ra, $zero # link register is to here, so clobber with 0 for later checks
1863 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1864 move $t0, $sp # remember bottom of caller's frame
1865 daddiu $sp, $sp, -16 # save return values and set up args
1866 .cfi_adjust_cfa_offset 16
1867 sd $v0, 0($sp)
1868 .cfi_rel_offset 2, 0
1869 s.d $f0, 8($sp)
1870 mov.d $f15, $f0 # pass fpr result
1871 move $a2, $v0 # pass gpr result
1872 move $a1, $t0 # pass $sp
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001873 move $a0, rSELF # pass Thread::Current
Goran Jakovljevic04568812015-04-23 15:27:23 +02001874 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
1875 .cpreturn # Restore gp from t8 in branch delay slot. gp is not used anymore,
1876 # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
1877
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001878 move $t9, $v0 # set aside returned link register
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001879 move $ra, $v1 # set link register for deoptimization
1880 ld $v0, 0($sp) # restore return values
1881 l.d $f0, 8($sp)
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001882 jalr $zero, $t9 # return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001883 daddiu $sp, $sp, 16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE # 16 bytes of saved values + ref_only callee save frame
1884 .cfi_adjust_cfa_offset -(16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
1885END art_quick_instrumentation_exit
1886
Maja Gagic6ea651f2015-02-24 16:55:04 +01001887 /*
1888 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1889 * will long jump to the upcall with a special exception of -1.
1890 */
1891 .extern artDeoptimize
1892 .extern artEnterInterpreterFromDeoptimize
1893ENTRY art_quick_deoptimize
1894 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1895 jal artDeoptimize # artDeoptimize(Thread*, SP)
1896 # Returns caller method's frame size.
1897 move $a0, rSELF # pass Thread::current
1898END art_quick_deoptimize
1899
Sebastien Hertz07474662015-08-25 15:12:33 +00001900 /*
1901 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
1902 * will long jump to the upcall with a special exception of -1.
1903 */
1904 .extern artDeoptimizeFromCompiledCode
1905ENTRY art_quick_deoptimize_from_compiled_code
1906 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1907 jal artDeoptimizeFromCompiledCode # artDeoptimizeFromCompiledCode(Thread*, SP)
1908 # Returns caller method's frame size.
1909 move $a0, rSELF # pass Thread::current
1910END art_quick_deoptimize_from_compiled_code
1911
Chris Larsen9701c2e2015-09-04 17:22:47 -07001912 .set push
1913 .set noat
1914/* java.lang.String.compareTo(String anotherString) */
1915ENTRY_NO_GP art_quick_string_compareto
1916/* $a0 holds address of "this" */
1917/* $a1 holds address of "anotherString" */
1918 beq $a0,$a1,9f # this and anotherString are the same object
1919 move $v0,$zero
1920
1921 lw $a2,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
1922 lw $a3,MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
Chris Larsencf283da2016-01-19 16:45:35 -08001923 MINu $t2, $a2, $a3
1924# $t2 now holds min(this.length(),anotherString.length())
Chris Larsen9701c2e2015-09-04 17:22:47 -07001925
1926 beqz $t2,9f # while min(this.length(),anotherString.length())-i != 0
1927 subu $v0,$a2,$a3 # if $t2==0 return
1928 # (this.length() - anotherString.length())
19291:
1930 lhu $t0,MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
1931 lhu $t1,MIRROR_STRING_VALUE_OFFSET($a1)
1932 bne $t0,$t1,9f # if this.charAt(i) != anotherString.charAt(i)
1933 subu $v0,$t0,$t1 # return (this.charAt(i) - anotherString.charAt(i))
1934 daddiu $a0,$a0,2 # point at this.charAt(i++)
1935 subu $t2,$t2,1 # new value of
1936 # min(this.length(),anotherString.length())-i
1937 bnez $t2,1b
1938 daddiu $a1,$a1,2 # point at anotherString.charAt(i++)
1939 subu $v0,$a2,$a3
1940
19419:
1942 j $ra
1943 nop
1944END art_quick_string_compareto
1945
1946/* java.lang.String.indexOf(int ch, int fromIndex=0) */
1947ENTRY_NO_GP art_quick_indexof
1948/* $a0 holds address of "this" */
Chris Larsencf283da2016-01-19 16:45:35 -08001949/* $a1 holds "ch" */
1950/* $a2 holds "fromIndex" */
Chris Larsen9701c2e2015-09-04 17:22:47 -07001951 lw $t0,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08001952 slt $at, $a2, $zero # if fromIndex < 0
1953 seleqz $a2, $a2, $at # fromIndex = 0;
1954 subu $t0,$t0,$a2 # this.length() - fromIndex
1955 blez $t0,6f # if this.length()-fromIndex <= 0
Chris Larsen9701c2e2015-09-04 17:22:47 -07001956 li $v0,-1 # return -1;
1957
1958 sll $v0,$a2,1 # $a0 += $a2 * 2
1959 daddu $a0,$a0,$v0 # " " " " "
Chris Larsencf283da2016-01-19 16:45:35 -08001960 move $v0,$a2 # Set i to fromIndex.
Chris Larsen9701c2e2015-09-04 17:22:47 -07001961
19621:
1963 lhu $t3,MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
1964 beq $t3,$a1,6f # return i;
1965 daddu $a0,$a0,2 # i++
1966 subu $t0,$t0,1 # this.length() - i
1967 bnez $t0,1b # while this.length() - i > 0
1968 addu $v0,$v0,1 # i++
1969
1970 li $v0,-1 # if this.length() - i <= 0
1971 # return -1;
1972
19736:
1974 j $ra
1975 nop
1976END art_quick_indexof
1977
1978 .set pop