blob: 4d5004f444d4f1b0c05c36f78d713f3678905ffc [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogers7655f292013-07-29 11:07:13 -070017#include "asm_support_mips.S"
buzbee5bc5a7b2012-03-07 15:52:59 -080018
Mathieu Chartier7410f292013-11-24 13:17:35 -080019#include "arch/quick_alloc_entrypoints.S"
20
jeffhao07030602012-09-26 14:33:14 -070021 .set noreorder
buzbee5bc5a7b2012-03-07 15:52:59 -080022 .balign 4
23
24 /* Deliver the given exception */
25 .extern artDeliverExceptionFromCode
26 /* Deliver an exception pending on a thread */
jeffhao8161c032012-10-31 15:50:00 -070027 .extern artDeliverPendingExceptionFromCode
buzbee5bc5a7b2012-03-07 15:52:59 -080028
Douglas Leung735b8552014-10-31 12:21:40 -070029#define ARG_SLOT_SIZE 32 // space for a0-a3 plus 4 more words
30
buzbee5bc5a7b2012-03-07 15:52:59 -080031 /*
32 * Macro that sets up the callee save frame to conform with
33 * Runtime::CreateCalleeSaveMethod(kSaveAll)
Douglas Leung735b8552014-10-31 12:21:40 -070034 * Callee-save: $s0-$s8 + $gp + $ra, 11 total + 1 word for Method*
35 * Clobbers $t0 and $sp
36 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
37 * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080038 */
Ian Rogers57b86d42012-03-27 16:05:41 -070039.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Andreas Gampea4e0e672015-05-27 18:31:42 -070040 addiu $sp, $sp, -96
41 .cfi_adjust_cfa_offset 96
Andreas Gampe5c1e4352014-04-21 19:28:24 -070042
43 // Ugly compile-time check, but we only have the preprocessor.
Andreas Gampea4e0e672015-05-27 18:31:42 -070044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 96)
Andreas Gampe5c1e4352014-04-21 19:28:24 -070045#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS) size not as expected."
46#endif
47
Andreas Gampea4e0e672015-05-27 18:31:42 -070048 sw $ra, 92($sp)
49 .cfi_rel_offset 31, 92
50 sw $s8, 88($sp)
51 .cfi_rel_offset 30, 88
52 sw $gp, 84($sp)
53 .cfi_rel_offset 28, 84
54 sw $s7, 80($sp)
55 .cfi_rel_offset 23, 80
56 sw $s6, 76($sp)
57 .cfi_rel_offset 22, 76
58 sw $s5, 72($sp)
59 .cfi_rel_offset 21, 72
60 sw $s4, 68($sp)
61 .cfi_rel_offset 20, 68
62 sw $s3, 64($sp)
63 .cfi_rel_offset 19, 64
64 sw $s2, 60($sp)
65 .cfi_rel_offset 18, 60
66 sw $s1, 56($sp)
67 .cfi_rel_offset 17, 56
68 sw $s0, 52($sp)
69 .cfi_rel_offset 16, 52
70
71 SDu $f30, $f31, 44, $sp, $t1
72 SDu $f28, $f29, 36, $sp, $t1
73 SDu $f26, $f27, 28, $sp, $t1
74 SDu $f24, $f25, 20, $sp, $t1
75 SDu $f22, $f23, 12, $sp, $t1
76 SDu $f20, $f21, 4, $sp, $t1
77
Douglas Leung735b8552014-10-31 12:21:40 -070078 # 1 word for holding Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070079
Douglas Leung4af77b72014-10-22 16:32:28 -070080 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
81 lw $t0, 0($t0)
Douglas Leung4af77b72014-10-22 16:32:28 -070082 lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070083 sw $t0, 0($sp) # Place Method* at bottom of stack.
84 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -070085 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
86 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -080087.endm
88
89 /*
90 * Macro that sets up the callee save frame to conform with
91 * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes non-moving GC.
92 * Does not include rSUSPEND or rSELF
Douglas Leung735b8552014-10-31 12:21:40 -070093 * callee-save: $s2-$s8 + $gp + $ra, 9 total + 2 words padding + 1 word to hold Method*
94 * Clobbers $t0 and $sp
95 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
96 * Reserves FRAME_SIZE_REFS_ONLY_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080097 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070098.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -070099 addiu $sp, $sp, -48
100 .cfi_adjust_cfa_offset 48
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700101
102 // Ugly compile-time check, but we only have the preprocessor.
Douglas Leung735b8552014-10-31 12:21:40 -0700103#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 48)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700104#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS) size not as expected."
105#endif
106
Douglas Leung735b8552014-10-31 12:21:40 -0700107 sw $ra, 44($sp)
108 .cfi_rel_offset 31, 44
109 sw $s8, 40($sp)
110 .cfi_rel_offset 30, 40
111 sw $gp, 36($sp)
112 .cfi_rel_offset 28, 36
113 sw $s7, 32($sp)
114 .cfi_rel_offset 23, 32
115 sw $s6, 28($sp)
116 .cfi_rel_offset 22, 28
117 sw $s5, 24($sp)
118 .cfi_rel_offset 21, 24
119 sw $s4, 20($sp)
120 .cfi_rel_offset 20, 20
121 sw $s3, 16($sp)
122 .cfi_rel_offset 19, 16
123 sw $s2, 12($sp)
124 .cfi_rel_offset 18, 12
125 # 2 words for alignment and bottom word will hold Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700126
Douglas Leung4af77b72014-10-22 16:32:28 -0700127 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
128 lw $t0, 0($t0)
Douglas Leung4af77b72014-10-22 16:32:28 -0700129 lw $t0, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700130 sw $t0, 0($sp) # Place Method* at bottom of stack.
131 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700132 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
133 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800134.endm
135
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700136.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -0700137 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
138 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
139 lw $ra, 44($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800140 .cfi_restore 31
Douglas Leung735b8552014-10-31 12:21:40 -0700141 lw $s8, 40($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800142 .cfi_restore 30
Douglas Leung735b8552014-10-31 12:21:40 -0700143 lw $gp, 36($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800144 .cfi_restore 28
Douglas Leung735b8552014-10-31 12:21:40 -0700145 lw $s7, 32($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800146 .cfi_restore 23
Douglas Leung735b8552014-10-31 12:21:40 -0700147 lw $s6, 28($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800148 .cfi_restore 22
Douglas Leung735b8552014-10-31 12:21:40 -0700149 lw $s5, 24($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800150 .cfi_restore 21
Douglas Leung735b8552014-10-31 12:21:40 -0700151 lw $s4, 20($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800152 .cfi_restore 20
Douglas Leung735b8552014-10-31 12:21:40 -0700153 lw $s3, 16($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800154 .cfi_restore 19
Douglas Leung735b8552014-10-31 12:21:40 -0700155 lw $s2, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800156 .cfi_restore 18
Douglas Leung735b8552014-10-31 12:21:40 -0700157 addiu $sp, $sp, 48
158 .cfi_adjust_cfa_offset -48
buzbee5bc5a7b2012-03-07 15:52:59 -0800159.endm
160
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700161.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Douglas Leung735b8552014-10-31 12:21:40 -0700162 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
Andreas Gampe8d365912015-01-13 11:32:32 -0800163 jalr $zero, $ra
Douglas Leung735b8552014-10-31 12:21:40 -0700164 nop
buzbee5bc5a7b2012-03-07 15:52:59 -0800165.endm
166
167 /*
168 * Macro that sets up the callee save frame to conform with
Douglas Leung735b8552014-10-31 12:21:40 -0700169 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs).
Jeff Hao1f3bc2f2013-04-30 15:17:19 -0700170 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
buzbee5bc5a7b2012-03-07 15:52:59 -0800171 */
Douglas Leung735b8552014-10-31 12:21:40 -0700172.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000173 addiu $sp, $sp, -64
174 .cfi_adjust_cfa_offset 64
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700175
176 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000177#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 64)
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700178#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS) size not as expected."
179#endif
180
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000181 sw $ra, 60($sp)
182 .cfi_rel_offset 31, 60
183 sw $s8, 56($sp)
184 .cfi_rel_offset 30, 56
185 sw $gp, 52($sp)
186 .cfi_rel_offset 28, 52
187 sw $s7, 48($sp)
188 .cfi_rel_offset 23, 48
189 sw $s6, 44($sp)
190 .cfi_rel_offset 22, 44
191 sw $s5, 40($sp)
192 .cfi_rel_offset 21, 40
193 sw $s4, 36($sp)
194 .cfi_rel_offset 20, 36
195 sw $s3, 32($sp)
196 .cfi_rel_offset 19, 32
197 sw $s2, 28($sp)
198 .cfi_rel_offset 18, 28
199 sw $a3, 24($sp)
200 .cfi_rel_offset 7, 24
201 sw $a2, 20($sp)
202 .cfi_rel_offset 6, 20
203 sw $a1, 16($sp)
204 .cfi_rel_offset 5, 16
jeffhaofa147e22012-10-12 17:03:32 -0700205 # bottom will hold Method*
Douglas Leung735b8552014-10-31 12:21:40 -0700206.endm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700207
Douglas Leung735b8552014-10-31 12:21:40 -0700208 /*
209 * Macro that sets up the callee save frame to conform with
210 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000211 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700212 * Clobbers $t0 and $sp
213 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
214 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
215 */
216.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
217 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
Douglas Leung4af77b72014-10-22 16:32:28 -0700218 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
219 lw $t0, 0($t0)
Douglas Leung4af77b72014-10-22 16:32:28 -0700220 lw $t0, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700221 sw $t0, 0($sp) # Place Method* at bottom of stack.
222 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700223 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
224 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
225.endm
226
227 /*
228 * Macro that sets up the callee save frame to conform with
229 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes non-moving GC.
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000230 * callee-save: $a1-$a3, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700231 * Clobbers $sp
232 * Use $a0 as the Method* and loads it into bottom of stack.
233 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
234 * Reserves FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE + ARG_SLOT_SIZE bytes on the stack
235 */
236.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
237 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_REGISTERS_ONLY
238 sw $a0, 0($sp) # Place Method* at bottom of stack.
239 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
240 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
241 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800242.endm
243
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700244.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -0700245 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
246 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000247 lw $ra, 60($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800248 .cfi_restore 31
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000249 lw $s8, 56($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800250 .cfi_restore 30
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000251 lw $gp, 52($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800252 .cfi_restore 28
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000253 lw $s7, 48($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800254 .cfi_restore 23
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000255 lw $s6, 44($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800256 .cfi_restore 22
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000257 lw $s5, 40($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800258 .cfi_restore 21
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000259 lw $s4, 36($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800260 .cfi_restore 20
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000261 lw $s3, 32($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800262 .cfi_restore 19
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000263 lw $s2, 28($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800264 .cfi_restore 18
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000265 lw $a3, 24($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800266 .cfi_restore 7
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000267 lw $a2, 20($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800268 .cfi_restore 6
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000269 lw $a1, 16($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800270 .cfi_restore 5
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000271 addiu $sp, $sp, 64 # pop frame
272 .cfi_adjust_cfa_offset -64
buzbee5bc5a7b2012-03-07 15:52:59 -0800273.endm
274
275 /*
276 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
277 * exception is Thread::Current()->exception_
278 */
279.macro DELIVER_PENDING_EXCEPTION
jeffhao8161c032012-10-31 15:50:00 -0700280 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME # save callee saves for throw
jeffhao8161c032012-10-31 15:50:00 -0700281 la $t9, artDeliverPendingExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800282 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700283 move $a0, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800284.endm
285
286.macro RETURN_IF_NO_EXCEPTION
jeffhao7fbee072012-08-24 17:56:54 -0700287 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700288 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700289 bnez $t0, 1f # success if no exception is pending
buzbee5bc5a7b2012-03-07 15:52:59 -0800290 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800291 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -0800292 nop
2931:
294 DELIVER_PENDING_EXCEPTION
295.endm
296
297.macro RETURN_IF_ZERO
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700298 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700299 bnez $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800300 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800301 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800302 nop
3031:
304 DELIVER_PENDING_EXCEPTION
305.endm
306
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800307.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700308 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700309 beqz $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800310 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800311 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800312 nop
3131:
314 DELIVER_PENDING_EXCEPTION
315.endm
316
buzbee5bc5a7b2012-03-07 15:52:59 -0800317 /*
jeffhao7fbee072012-08-24 17:56:54 -0700318 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
buzbee5bc5a7b2012-03-07 15:52:59 -0800319 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
320 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800321ENTRY art_quick_do_long_jump
Duane Sande34652f2014-11-04 11:09:36 -0800322 LDu $f0, $f1, 0*8, $a1, $t1
323 LDu $f2, $f3, 1*8, $a1, $t1
324 LDu $f4, $f5, 2*8, $a1, $t1
325 LDu $f6, $f7, 3*8, $a1, $t1
326 LDu $f8, $f9, 4*8, $a1, $t1
327 LDu $f10, $f11, 5*8, $a1, $t1
328 LDu $f12, $f13, 6*8, $a1, $t1
329 LDu $f14, $f15, 7*8, $a1, $t1
330 LDu $f16, $f17, 8*8, $a1, $t1
331 LDu $f18, $f19, 9*8, $a1, $t1
332 LDu $f20, $f21, 10*8, $a1, $t1
333 LDu $f22, $f23, 11*8, $a1, $t1
334 LDu $f24, $f25, 12*8, $a1, $t1
335 LDu $f26, $f27, 13*8, $a1, $t1
336 LDu $f28, $f29, 14*8, $a1, $t1
337 LDu $f30, $f31, 15*8, $a1, $t1
338
Chris Dearman748dd952014-05-23 10:47:01 -0700339 .set push
340 .set nomacro
341 .set noat
jeffhao7fbee072012-08-24 17:56:54 -0700342 lw $at, 4($a0)
Chris Dearman748dd952014-05-23 10:47:01 -0700343 .set pop
jeffhao7fbee072012-08-24 17:56:54 -0700344 lw $v0, 8($a0)
345 lw $v1, 12($a0)
346 lw $a1, 20($a0)
347 lw $a2, 24($a0)
348 lw $a3, 28($a0)
349 lw $t0, 32($a0)
350 lw $t1, 36($a0)
351 lw $t2, 40($a0)
352 lw $t3, 44($a0)
353 lw $t4, 48($a0)
354 lw $t5, 52($a0)
355 lw $t6, 56($a0)
356 lw $t7, 60($a0)
357 lw $s0, 64($a0)
358 lw $s1, 68($a0)
359 lw $s2, 72($a0)
360 lw $s3, 76($a0)
361 lw $s4, 80($a0)
362 lw $s5, 84($a0)
363 lw $s6, 88($a0)
364 lw $s7, 92($a0)
365 lw $t8, 96($a0)
366 lw $t9, 100($a0)
jeffhao7fbee072012-08-24 17:56:54 -0700367 lw $gp, 112($a0)
368 lw $sp, 116($a0)
369 lw $fp, 120($a0)
370 lw $ra, 124($a0)
371 lw $a0, 16($a0)
372 move $v0, $zero # clear result registers r0 and r1
Andreas Gampe8d365912015-01-13 11:32:32 -0800373 jalr $zero, $ra # do long jump
jeffhao7fbee072012-08-24 17:56:54 -0700374 move $v1, $zero
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800375END art_quick_do_long_jump
buzbee5bc5a7b2012-03-07 15:52:59 -0800376
buzbee5bc5a7b2012-03-07 15:52:59 -0800377 /*
378 * Called by managed code, saves most registers (forms basis of long jump context) and passes
379 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200380 * the bottom of the thread. On entry a0 holds Throwable*
buzbee5bc5a7b2012-03-07 15:52:59 -0800381 */
Ian Rogers468532e2013-08-05 10:56:33 -0700382ENTRY art_quick_deliver_exception
Ian Rogers57b86d42012-03-27 16:05:41 -0700383 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700384 la $t9, artDeliverExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800385 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700386 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700387END art_quick_deliver_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800388
buzbee5bc5a7b2012-03-07 15:52:59 -0800389 /*
390 * Called by managed code to create and deliver a NullPointerException
391 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800392 .extern artThrowNullPointerExceptionFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700393ENTRY art_quick_throw_null_pointer_exception
Ian Rogers57b86d42012-03-27 16:05:41 -0700394 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700395 la $t9, artThrowNullPointerExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800396 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700397 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700398END art_quick_throw_null_pointer_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800399
buzbee5bc5a7b2012-03-07 15:52:59 -0800400 /*
401 * Called by managed code to create and deliver an ArithmeticException
402 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800403 .extern artThrowDivZeroFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700404ENTRY art_quick_throw_div_zero
Ian Rogers57b86d42012-03-27 16:05:41 -0700405 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700406 la $t9, artThrowDivZeroFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800407 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700408 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700409END art_quick_throw_div_zero
buzbee5bc5a7b2012-03-07 15:52:59 -0800410
buzbee5bc5a7b2012-03-07 15:52:59 -0800411 /*
412 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
413 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800414 .extern artThrowArrayBoundsFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700415ENTRY art_quick_throw_array_bounds
Ian Rogers57b86d42012-03-27 16:05:41 -0700416 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700417 la $t9, artThrowArrayBoundsFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800418 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700419 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700420END art_quick_throw_array_bounds
buzbee5bc5a7b2012-03-07 15:52:59 -0800421
Ian Rogers57b86d42012-03-27 16:05:41 -0700422 /*
423 * Called by managed code to create and deliver a StackOverflowError.
424 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800425 .extern artThrowStackOverflowFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700426ENTRY art_quick_throw_stack_overflow
Ian Rogers57b86d42012-03-27 16:05:41 -0700427 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700428 la $t9, artThrowStackOverflowFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800429 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700430 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700431END art_quick_throw_stack_overflow
buzbee5bc5a7b2012-03-07 15:52:59 -0800432
Ian Rogers57b86d42012-03-27 16:05:41 -0700433 /*
434 * Called by managed code to create and deliver a NoSuchMethodError.
435 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800436 .extern artThrowNoSuchMethodFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700437ENTRY art_quick_throw_no_such_method
Ian Rogers57b86d42012-03-27 16:05:41 -0700438 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700439 la $t9, artThrowNoSuchMethodFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800440 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700441 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700442END art_quick_throw_no_such_method
buzbee5bc5a7b2012-03-07 15:52:59 -0800443
buzbee5bc5a7b2012-03-07 15:52:59 -0800444 /*
445 * All generated callsites for interface invokes and invocation slow paths will load arguments
jeffhao7fbee072012-08-24 17:56:54 -0700446 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100447 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
jeffhao7fbee072012-08-24 17:56:54 -0700448 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800449 *
jeffhao7fbee072012-08-24 17:56:54 -0700450 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
451 * of the target Method* in $v0 and method->code_ in $v1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800452 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700453 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
buzbee5bc5a7b2012-03-07 15:52:59 -0800454 * thread and we branch to another stub to deliver it.
455 *
456 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
457 * pointing back to the original caller.
458 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700459.macro INVOKE_TRAMPOLINE_BODY cxx_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800460 .extern \cxx_name
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700461 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100462 move $a2, rSELF # pass Thread::Current
463 jal \cxx_name # (method_idx, this, Thread*, $sp)
464 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
465 move $a0, $v0 # save target Method*
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700466 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhaofa147e22012-10-12 17:03:32 -0700467 beqz $v0, 1f
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100468 move $t9, $v1 # save $v0->code_
Andreas Gampe8d365912015-01-13 11:32:32 -0800469 jalr $zero, $t9
buzbee5bc5a7b2012-03-07 15:52:59 -0800470 nop
4711:
472 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700473.endm
474.macro INVOKE_TRAMPOLINE c_name, cxx_name
475ENTRY \c_name
476 INVOKE_TRAMPOLINE_BODY \cxx_name
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800477END \c_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800478.endm
479
Logan Chien8dbb7082013-01-25 20:31:17 +0800480INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800481
Logan Chien8dbb7082013-01-25 20:31:17 +0800482INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
483INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
484INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
485INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800486
Jeff Hao79fe5392013-04-24 18:41:58 -0700487 /*
Ian Rogersef7d42f2014-01-06 12:55:46 -0800488 * Invocation stub for quick code.
Jeff Hao5d917302013-02-27 17:57:33 -0800489 * On entry:
490 * a0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700491 * a1 = argument array or null for no argument methods
Jeff Hao5d917302013-02-27 17:57:33 -0800492 * a2 = size of argument array in bytes
493 * a3 = (managed) thread pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700494 * [sp + 16] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800495 * [sp + 20] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800496 */
497ENTRY art_quick_invoke_stub
Jeff Hao5d917302013-02-27 17:57:33 -0800498 sw $a0, 0($sp) # save out a0
499 addiu $sp, $sp, -16 # spill s0, s1, fp, ra
500 .cfi_adjust_cfa_offset 16
501 sw $ra, 12($sp)
502 .cfi_rel_offset 31, 12
503 sw $fp, 8($sp)
504 .cfi_rel_offset 30, 8
505 sw $s1, 4($sp)
506 .cfi_rel_offset 17, 4
507 sw $s0, 0($sp)
508 .cfi_rel_offset 16, 0
509 move $fp, $sp # save sp in fp
510 .cfi_def_cfa_register 30
511 move $s1, $a3 # move managed thread pointer into s1
512 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000513 addiu $t0, $a2, 4 # create space for method pointer in frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700514 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000515 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
516 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
517 addiu $a0, $sp, 4 # pass stack pointer + method ptr as dest for memcpy
Jeff Hao5d917302013-02-27 17:57:33 -0800518 jal memcpy # (dest, src, bytes)
519 addiu $sp, $sp, -16 # make space for argument slots for memcpy
520 addiu $sp, $sp, 16 # restore stack after memcpy
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000521 lw $a0, 16($fp) # restore method*
522 lw $a1, 4($sp) # copy arg value for a1
523 lw $a2, 8($sp) # copy arg value for a2
524 lw $a3, 12($sp) # copy arg value for a3
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800526 jalr $t9 # call the method
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000527 sw $zero, 0($sp) # store null for method* at bottom of frame
Jeff Hao5d917302013-02-27 17:57:33 -0800528 move $sp, $fp # restore the stack
529 lw $s0, 0($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800530 .cfi_restore 16
Jeff Hao5d917302013-02-27 17:57:33 -0800531 lw $s1, 4($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800532 .cfi_restore 17
Jeff Hao5d917302013-02-27 17:57:33 -0800533 lw $fp, 8($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800534 .cfi_restore 30
Jeff Hao5d917302013-02-27 17:57:33 -0800535 lw $ra, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800536 .cfi_restore 31
Jeff Hao5d917302013-02-27 17:57:33 -0800537 addiu $sp, $sp, 16
538 .cfi_adjust_cfa_offset -16
539 lw $t0, 16($sp) # get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800540 lw $t1, 20($sp) # get shorty
541 lb $t1, 0($t1) # get result type char
Vladimir Marko7fee84c2015-08-21 18:39:26 +0000542 li $t2, 68 # put char 'D' into t2
543 beq $t1, $t2, 1f # branch if result type char == 'D'
544 li $t3, 70 # put char 'F' into t3
545 beq $t1, $t3, 1f # branch if result type char == 'F'
Jeff Hao5d917302013-02-27 17:57:33 -0800546 sw $v0, 0($t0) # store the result
Andreas Gampe8d365912015-01-13 11:32:32 -0800547 jalr $zero, $ra
Jeff Hao5d917302013-02-27 17:57:33 -0800548 sw $v1, 4($t0) # store the other half of the result
Vladimir Marko7fee84c2015-08-21 18:39:26 +00005491:
Duane Sande34652f2014-11-04 11:09:36 -0800550 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
Andreas Gampe8d365912015-01-13 11:32:32 -0800551 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -0800552 nop
Jeff Hao5d917302013-02-27 17:57:33 -0800553END art_quick_invoke_stub
554
555 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800556 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
557 * failure.
558 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800559 .extern artHandleFillArrayDataFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700560ENTRY art_quick_handle_fill_data
Douglas Leung735b8552014-10-31 12:21:40 -0700561 lw $a2, 0($sp) # pass referrer's Method*
562 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700563 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*)
Ian Rogers832336b2014-10-08 15:35:22 -0700564 move $a3, rSELF # pass Thread::Current
jeffhaofc6a30e2012-10-18 18:24:15 -0700565 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700566END art_quick_handle_fill_data
buzbee5bc5a7b2012-03-07 15:52:59 -0800567
buzbee5bc5a7b2012-03-07 15:52:59 -0800568 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700569 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
buzbee5bc5a7b2012-03-07 15:52:59 -0800570 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800571 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700572ENTRY art_quick_lock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -0800573 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700574 nop
Douglas Leung735b8552014-10-31 12:21:40 -0700575 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700576 jal artLockObjectFromCode # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700577 move $a1, rSELF # pass Thread::Current
Ian Rogers6bcd1632013-10-08 18:50:47 -0700578 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700579END art_quick_lock_object
buzbee5bc5a7b2012-03-07 15:52:59 -0800580
buzbee5bc5a7b2012-03-07 15:52:59 -0800581 /*
582 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
583 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800584 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700585ENTRY art_quick_unlock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -0800586 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700587 nop
Douglas Leung735b8552014-10-31 12:21:40 -0700588 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700589 jal artUnlockObjectFromCode # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700590 move $a1, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800591 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700592END art_quick_unlock_object
buzbee5bc5a7b2012-03-07 15:52:59 -0800593
buzbee5bc5a7b2012-03-07 15:52:59 -0800594 /*
595 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
596 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700597 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -0700598ENTRY art_quick_check_cast
Ian Rogersa9a82542013-10-04 11:17:26 -0700599 addiu $sp, $sp, -16
600 .cfi_adjust_cfa_offset 16
601 sw $ra, 12($sp)
602 .cfi_rel_offset 31, 12
603 sw $t9, 8($sp)
604 sw $a1, 4($sp)
605 sw $a0, 0($sp)
606 jal artIsAssignableFromCode
Douglas Leung735b8552014-10-31 12:21:40 -0700607 addiu $sp, $sp, -16 # reserve argument slots on the stack
608 addiu $sp, $sp, 16
Ian Rogers86bcdc22014-02-21 22:06:38 -0800609 beqz $v0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -0700610 lw $ra, 12($sp)
Andreas Gampe8d365912015-01-13 11:32:32 -0800611 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -0700612 addiu $sp, $sp, 16
613 .cfi_adjust_cfa_offset -16
Ian Rogers86bcdc22014-02-21 22:06:38 -0800614.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -0700615 lw $t9, 8($sp)
616 lw $a1, 4($sp)
617 lw $a0, 0($sp)
618 addiu $sp, $sp, 16
619 .cfi_adjust_cfa_offset -16
620 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -0700621 la $t9, artThrowClassCastException
Andreas Gampe8d365912015-01-13 11:32:32 -0800622 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700623 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700624END art_quick_check_cast
buzbee5bc5a7b2012-03-07 15:52:59 -0800625
buzbee5bc5a7b2012-03-07 15:52:59 -0800626 /*
Man Cao1aee9002015-07-14 22:31:42 -0700627 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
628 * nReg is the register number for rReg.
629 */
630.macro POP_REG_NE rReg, nReg, offset, rExclude
631 .ifnc \rReg, \rExclude
632 lw \rReg, \offset($sp) # restore rReg
633 .cfi_restore \nReg
634 .endif
635.endm
636
637 /*
638 * Macro to insert read barrier, only used in art_quick_aput_obj.
639 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
640 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
641 */
642.macro READ_BARRIER rDest, rObj, offset
643#ifdef USE_READ_BARRIER
644 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
645 addiu $sp, $sp, -32
646 .cfi_adjust_cfa_offset 32
647 sw $ra, 28($sp)
648 .cfi_rel_offset 31, 28
649 sw $t9, 24($sp)
650 .cfi_rel_offset 25, 24
651 sw $t1, 20($sp)
652 .cfi_rel_offset 9, 20
653 sw $t0, 16($sp)
654 .cfi_rel_offset 8, 16
655 sw $a2, 8($sp) # padding slot at offset 12 (padding can be any slot in the 32B)
656 .cfi_rel_offset 6, 8
657 sw $a1, 4($sp)
658 .cfi_rel_offset 5, 4
659 sw $a0, 0($sp)
660 .cfi_rel_offset 4, 0
661
662 # move $a0, $a0 # pass ref in a0 (no-op for now since parameter ref is unused)
663 .ifnc \rObj, $a1
664 move $a1, \rObj # pass rObj
665 .endif
666 addiu $a2, $zero, \offset # pass offset
667 jal artReadBarrierSlow # artReadBarrierSlow(ref, rObj, offset)
668 addiu $sp, $sp, -16 # Use branch delay slot to reserve argument slots on the stack
669 # before the call to artReadBarrierSlow.
670 addiu $sp, $sp, 16 # restore stack after call to artReadBarrierSlow
671 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
672 move \rDest, $v0 # save return value in rDest
673 # (rDest cannot be v0 in art_quick_aput_obj)
674
675 lw $a0, 0($sp) # restore registers except rDest
676 # (rDest can only be t0 or t1 in art_quick_aput_obj)
677 .cfi_restore 4
678 lw $a1, 4($sp)
679 .cfi_restore 5
680 lw $a2, 8($sp)
681 .cfi_restore 6
682 POP_REG_NE $t0, 8, 16, \rDest
683 POP_REG_NE $t1, 9, 20, \rDest
684 lw $t9, 24($sp)
685 .cfi_restore 25
686 lw $ra, 28($sp) # restore $ra
687 .cfi_restore 31
688 addiu $sp, $sp, 32
689 .cfi_adjust_cfa_offset -32
690#else
691 lw \rDest, \offset(\rObj)
692 UNPOISON_HEAP_REF \rDest
693#endif // USE_READ_BARRIER
694.endm
695
696 /*
Ian Rogersa9a82542013-10-04 11:17:26 -0700697 * Entry from managed code for array put operations of objects where the value being stored
698 * needs to be checked for compatibility.
699 * a0 = array, a1 = index, a2 = value
buzbee5bc5a7b2012-03-07 15:52:59 -0800700 */
Ian Rogersa9a82542013-10-04 11:17:26 -0700701ENTRY art_quick_aput_obj_with_null_and_bound_check
Ian Rogers86bcdc22014-02-21 22:06:38 -0800702 bnez $a0, .Lart_quick_aput_obj_with_bound_check_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700703 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -0800704 b .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700705 nop
706END art_quick_aput_obj_with_null_and_bound_check
707
708ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700709 lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
Ian Rogersa9a82542013-10-04 11:17:26 -0700710 sltu $t1, $a1, $t0
Ian Rogers86bcdc22014-02-21 22:06:38 -0800711 bnez $t1, .Lart_quick_aput_obj_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700712 nop
713 move $a0, $a1
Ian Rogers86bcdc22014-02-21 22:06:38 -0800714 b .Lart_quick_throw_array_bounds_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -0700715 move $a1, $t0
716END art_quick_aput_obj_with_bound_check
717
Man Cao1aee9002015-07-14 22:31:42 -0700718#ifdef USE_READ_BARRIER
719 .extern artReadBarrierSlow
720#endif
Ian Rogersa9a82542013-10-04 11:17:26 -0700721ENTRY art_quick_aput_obj
Ian Rogers86bcdc22014-02-21 22:06:38 -0800722 beqz $a2, .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -0700723 nop
Man Cao1aee9002015-07-14 22:31:42 -0700724 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
725 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
726 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogers86bcdc22014-02-21 22:06:38 -0800727 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
Ian Rogersa9a82542013-10-04 11:17:26 -0700728 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -0800729.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -0700730 sll $a1, $a1, 2
731 add $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -0700732 POISON_HEAP_REF $a2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700733 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Ian Rogersa9a82542013-10-04 11:17:26 -0700734 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
735 srl $t1, $a0, 7
736 add $t1, $t1, $t0
737 sb $t0, ($t1)
Andreas Gampe8d365912015-01-13 11:32:32 -0800738 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -0700739 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -0800740.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -0700741 sll $a1, $a1, 2
742 add $t0, $a0, $a1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700743 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Andreas Gampe8d365912015-01-13 11:32:32 -0800744 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -0700745 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -0800746.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -0700747 addiu $sp, $sp, -32
748 .cfi_adjust_cfa_offset 32
749 sw $ra, 28($sp)
750 .cfi_rel_offset 31, 28
751 sw $t9, 12($sp)
752 sw $a2, 8($sp)
753 sw $a1, 4($sp)
754 sw $a0, 0($sp)
755 move $a1, $t1
756 move $a0, $t0
757 jal artIsAssignableFromCode # (Class*, Class*)
Douglas Leung735b8552014-10-31 12:21:40 -0700758 addiu $sp, $sp, -16 # reserve argument slots on the stack
759 addiu $sp, $sp, 16
Ian Rogersa9a82542013-10-04 11:17:26 -0700760 lw $ra, 28($sp)
761 lw $t9, 12($sp)
762 lw $a2, 8($sp)
763 lw $a1, 4($sp)
764 lw $a0, 0($sp)
Duane Sande34652f2014-11-04 11:09:36 -0800765 addiu $sp, 32
Ian Rogersa9a82542013-10-04 11:17:26 -0700766 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -0800767 bnez $v0, .Ldo_aput
Ian Rogersa9a82542013-10-04 11:17:26 -0700768 nop
769 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
770 move $a1, $a2
Ian Rogersa9a82542013-10-04 11:17:26 -0700771 la $t9, artThrowArrayStoreException
Andreas Gampe8d365912015-01-13 11:32:32 -0800772 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700773 move $a2, rSELF # pass Thread::Current
Ian Rogersa9a82542013-10-04 11:17:26 -0700774END art_quick_aput_obj
buzbee5bc5a7b2012-03-07 15:52:59 -0800775
buzbee5bc5a7b2012-03-07 15:52:59 -0800776 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700777 * Called by managed code to resolve a static field and load a boolean primitive value.
778 */
779 .extern artGetBooleanStaticFromCode
780ENTRY art_quick_get_boolean_static
Douglas Leung735b8552014-10-31 12:21:40 -0700781 lw $a1, 0($sp) # pass referrer's Method*
782 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700783 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700784 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700785 RETURN_IF_NO_EXCEPTION
786END art_quick_get_boolean_static
787 /*
788 * Called by managed code to resolve a static field and load a byte primitive value.
789 */
790 .extern artGetByteStaticFromCode
791ENTRY art_quick_get_byte_static
Douglas Leung735b8552014-10-31 12:21:40 -0700792 lw $a1, 0($sp) # pass referrer's Method*
793 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700794 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700795 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700796 RETURN_IF_NO_EXCEPTION
797END art_quick_get_byte_static
798
799 /*
800 * Called by managed code to resolve a static field and load a char primitive value.
801 */
802 .extern artGetCharStaticFromCode
803ENTRY art_quick_get_char_static
Douglas Leung735b8552014-10-31 12:21:40 -0700804 lw $a1, 0($sp) # pass referrer's Method*
805 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700806 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700807 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700808 RETURN_IF_NO_EXCEPTION
809END art_quick_get_char_static
810 /*
811 * Called by managed code to resolve a static field and load a short primitive value.
812 */
813 .extern artGetShortStaticFromCode
814ENTRY art_quick_get_short_static
Douglas Leung735b8552014-10-31 12:21:40 -0700815 lw $a1, 0($sp) # pass referrer's Method*
816 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700817 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700818 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700819 RETURN_IF_NO_EXCEPTION
820END art_quick_get_short_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800821
buzbee5bc5a7b2012-03-07 15:52:59 -0800822 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700823 * Called by managed code to resolve a static field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800824 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800825 .extern artGet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700826ENTRY art_quick_get32_static
Douglas Leung735b8552014-10-31 12:21:40 -0700827 lw $a1, 0($sp) # pass referrer's Method*
828 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700829 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700830 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800831 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700832END art_quick_get32_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800833
buzbee5bc5a7b2012-03-07 15:52:59 -0800834 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700835 * Called by managed code to resolve a static field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800836 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800837 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700838ENTRY art_quick_get64_static
Douglas Leung735b8552014-10-31 12:21:40 -0700839 lw $a1, 0($sp) # pass referrer's Method*
840 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700841 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700842 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800843 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700844END art_quick_get64_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800845
buzbee5bc5a7b2012-03-07 15:52:59 -0800846 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700847 * Called by managed code to resolve a static field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -0800848 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800849 .extern artGetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700850ENTRY art_quick_get_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -0700851 lw $a1, 0($sp) # pass referrer's Method*
852 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700853 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700854 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800855 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700856END art_quick_get_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800857
buzbee5bc5a7b2012-03-07 15:52:59 -0800858 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700859 * Called by managed code to resolve an instance field and load a boolean primitive value.
860 */
861 .extern artGetBooleanInstanceFromCode
862ENTRY art_quick_get_boolean_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700863 lw $a2, 0($sp) # pass referrer's Method*
864 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700865 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700866 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700867 RETURN_IF_NO_EXCEPTION
868END art_quick_get_boolean_instance
869 /*
870 * Called by managed code to resolve an instance field and load a byte primitive value.
871 */
872 .extern artGetByteInstanceFromCode
873ENTRY art_quick_get_byte_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700874 lw $a2, 0($sp) # pass referrer's Method*
875 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700876 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700877 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700878 RETURN_IF_NO_EXCEPTION
879END art_quick_get_byte_instance
880
881 /*
882 * Called by managed code to resolve an instance field and load a char primitive value.
883 */
884 .extern artGetCharInstanceFromCode
885ENTRY art_quick_get_char_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700886 lw $a2, 0($sp) # pass referrer's Method*
887 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700888 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700889 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700890 RETURN_IF_NO_EXCEPTION
891END art_quick_get_char_instance
892 /*
893 * Called by managed code to resolve an instance field and load a short primitive value.
894 */
895 .extern artGetShortInstanceFromCode
896ENTRY art_quick_get_short_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700897 lw $a2, 0($sp) # pass referrer's Method*
898 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
899 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700900 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700901 RETURN_IF_NO_EXCEPTION
902END art_quick_get_short_instance
903
904 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700905 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800906 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800907 .extern artGet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700908ENTRY art_quick_get32_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700909 lw $a2, 0($sp) # pass referrer's Method*
910 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
911 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700912 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800913 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700914END art_quick_get32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -0800915
buzbee5bc5a7b2012-03-07 15:52:59 -0800916 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700917 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800918 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800919 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700920ENTRY art_quick_get64_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700921 lw $a2, 0($sp) # pass referrer's Method*
922 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
923 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700924 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800925 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700926END art_quick_get64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -0800927
buzbee5bc5a7b2012-03-07 15:52:59 -0800928 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700929 * Called by managed code to resolve an instance field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -0800930 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800931 .extern artGetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700932ENTRY art_quick_get_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -0700933 lw $a2, 0($sp) # pass referrer's Method*
934 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700935 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700936 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800937 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -0700938END art_quick_get_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -0800939
buzbee5bc5a7b2012-03-07 15:52:59 -0800940 /*
Fred Shih37f05ef2014-07-16 18:38:08 -0700941 * Called by managed code to resolve a static field and store a 8-bit primitive value.
942 */
943 .extern artSet8StaticFromCode
944ENTRY art_quick_set8_static
Douglas Leung735b8552014-10-31 12:21:40 -0700945 lw $a2, 0($sp) # pass referrer's Method*
946 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700947 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -0700948 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700949 RETURN_IF_ZERO
950END art_quick_set8_static
951
952 /*
953 * Called by managed code to resolve a static field and store a 16-bit primitive value.
954 */
955 .extern artSet16StaticFromCode
956ENTRY art_quick_set16_static
Douglas Leung735b8552014-10-31 12:21:40 -0700957 lw $a2, 0($sp) # pass referrer's Method*
958 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Fred Shih37f05ef2014-07-16 18:38:08 -0700959 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*, $sp)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700960 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -0700961 RETURN_IF_ZERO
962END art_quick_set16_static
963
964 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700965 * Called by managed code to resolve a static field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800966 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800967 .extern artSet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700968ENTRY art_quick_set32_static
Douglas Leung735b8552014-10-31 12:21:40 -0700969 lw $a2, 0($sp) # pass referrer's Method*
970 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700971 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -0700972 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800973 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700974END art_quick_set32_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800975
buzbee5bc5a7b2012-03-07 15:52:59 -0800976 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700977 * Called by managed code to resolve a static field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -0800978 */
Fred Shih37f05ef2014-07-16 18:38:08 -0700979 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700980ENTRY art_quick_set64_static
Douglas Leung735b8552014-10-31 12:21:40 -0700981 lw $a1, 0($sp) # pass referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -0800982 # 64 bit new_val is in a2:a3 pair
Douglas Leung735b8552014-10-31 12:21:40 -0700983 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700984 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -0700985 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800986 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700987END art_quick_set64_static
buzbee5bc5a7b2012-03-07 15:52:59 -0800988
buzbee5bc5a7b2012-03-07 15:52:59 -0800989 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700990 * Called by managed code to resolve a static field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -0800991 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800992 .extern artSetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700993ENTRY art_quick_set_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -0700994 lw $a2, 0($sp) # pass referrer's Method*
995 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
jeffhao7fbee072012-08-24 17:56:54 -0700996 move $a3, rSELF # pass Thread::Current
Douglas Leung735b8552014-10-31 12:21:40 -0700997 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
buzbee5bc5a7b2012-03-07 15:52:59 -0800998 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -0700999END art_quick_set_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001000
buzbee5bc5a7b2012-03-07 15:52:59 -08001001 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001002 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1003 */
1004 .extern artSet8InstanceFromCode
1005ENTRY art_quick_set8_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001006 lw $a3, 0($sp) # pass referrer's Method*
1007 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1008 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001009 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001010 RETURN_IF_ZERO
1011END art_quick_set8_instance
1012
1013 /*
1014 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1015 */
1016 .extern artSet16InstanceFromCode
1017ENTRY art_quick_set16_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001018 lw $a3, 0($sp) # pass referrer's Method*
1019 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001020 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001021 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001022 RETURN_IF_ZERO
1023END art_quick_set16_instance
1024
1025 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001026 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001027 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001028 .extern artSet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001029ENTRY art_quick_set32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001030 lw $a3, 0($sp) # pass referrer's Method*
1031 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001032 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001033 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001034 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001035END art_quick_set32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001036
buzbee5bc5a7b2012-03-07 15:52:59 -08001037 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001038 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001039 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001040 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001041ENTRY art_quick_set64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001042 lw $t1, 0($sp) # load referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001043 # 64 bit new_val is in a2:a3 pair
Douglas Leung735b8552014-10-31 12:21:40 -07001044 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001045 sw rSELF, 20($sp) # pass Thread::Current
1046 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
Douglas Leung735b8552014-10-31 12:21:40 -07001047 sw $t1, 16($sp) # pass referrer's Method*
buzbee5bc5a7b2012-03-07 15:52:59 -08001048 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001049END art_quick_set64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001050
buzbee5bc5a7b2012-03-07 15:52:59 -08001051 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001052 * Called by managed code to resolve an instance field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001053 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001054 .extern artSetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001055ENTRY art_quick_set_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001056 lw $a3, 0($sp) # pass referrer's Method*
1057 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001058 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001059 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001060 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001061END art_quick_set_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001062
Vladimir Markoa3c38272015-04-28 12:37:09 +01001063// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001064.macro ONE_ARG_DOWNCALL name, entrypoint, return
1065 .extern \entrypoint
1066ENTRY \name
1067 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1068 jal \entrypoint
1069 move $a1, rSELF # pass Thread::Current
1070 \return
1071END \name
1072.endm
1073
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001074.macro TWO_ARG_DOWNCALL name, entrypoint, return
1075 .extern \entrypoint
1076ENTRY \name
Douglas Leung735b8552014-10-31 12:21:40 -07001077 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001078 jal \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001079 move $a2, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001080 \return
1081END \name
1082.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001083
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001084.macro THREE_ARG_DOWNCALL name, entrypoint, return
1085 .extern \entrypoint
1086ENTRY \name
Douglas Leung735b8552014-10-31 12:21:40 -07001087 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001088 jal \entrypoint
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001089 move $a3, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001090 \return
1091END \name
1092.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001093
Jeff Hao848f70a2014-01-15 13:49:50 -08001094.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1095 .extern \entrypoint
1096ENTRY \name
Vladimir Markoa3c38272015-04-28 12:37:09 +01001097 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Jeff Hao848f70a2014-01-15 13:49:50 -08001098 jal \entrypoint
Vladimir Markoa3c38272015-04-28 12:37:09 +01001099 sw rSELF, 16($sp) # pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -08001100 \return
1101END \name
1102.endm
1103
Mathieu Chartier7410f292013-11-24 13:17:35 -08001104// Generate the allocation entrypoints for each allocator.
1105GENERATE_ALL_ALLOC_ENTRYPOINTS
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001106
buzbee5bc5a7b2012-03-07 15:52:59 -08001107 /*
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001108 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001109 * exception on error. On success the String is returned. A0 holds the string index. The fast
1110 * path check for hit in strings cache has already been performed.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001111 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001112ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001113
1114 /*
1115 * Entry from managed code when uninitialized static storage, this stub will run the class
1116 * initializer and deliver the exception on error. On success the static storage base is
1117 * returned.
1118 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001119ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001120
1121 /*
1122 * Entry from managed code when dex cache misses for a type_idx.
1123 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001124ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001125
1126 /*
1127 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1128 * miss.
1129 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001130ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001131
1132 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001133 * Called by managed code when the value in rSUSPEND has been decremented to 0.
buzbee5bc5a7b2012-03-07 15:52:59 -08001134 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001135 .extern artTestSuspendFromCode
1136ENTRY art_quick_test_suspend
Ian Rogers474b6da2012-09-25 00:20:38 -07001137 lh $a0, THREAD_FLAGS_OFFSET(rSELF)
jeffhao7fbee072012-08-24 17:56:54 -07001138 bnez $a0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001139 addiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Andreas Gampe8d365912015-01-13 11:32:32 -08001140 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -08001141 nop
11421:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001143 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves for stack crawl
1144 jal artTestSuspendFromCode # (Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001145 move $a0, rSELF
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001146 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001147END art_quick_test_suspend
buzbee5bc5a7b2012-03-07 15:52:59 -08001148
buzbee5bc5a7b2012-03-07 15:52:59 -08001149 /*
1150 * Called by managed code that is attempting to call a method on a proxy class. On entry
Ian Rogers57b86d42012-03-27 16:05:41 -07001151 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
buzbee5bc5a7b2012-03-07 15:52:59 -08001152 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001153 .extern artQuickProxyInvokeHandler
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001154ENTRY art_quick_proxy_invoke_handler
Douglas Leung735b8552014-10-31 12:21:40 -07001155 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1156 move $a2, rSELF # pass Thread::Current
Jeff Hao5fa60c32013-04-04 17:57:01 -07001157 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001158 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
jeffhao7fbee072012-08-24 17:56:54 -07001159 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Douglas Leung735b8552014-10-31 12:21:40 -07001160 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao7fbee072012-08-24 17:56:54 -07001161 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001162 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1163 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001164 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001165 nop
buzbee5bc5a7b2012-03-07 15:52:59 -080011661:
1167 DELIVER_PENDING_EXCEPTION
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001168END art_quick_proxy_invoke_handler
buzbee5bc5a7b2012-03-07 15:52:59 -08001169
Jeff Hao88474b42013-10-23 16:24:40 -07001170 /*
1171 * Called to resolve an imt conflict. t0 is a hidden argument that holds the target method's
1172 * dex method index.
1173 */
Douglas Leung13738bf2014-10-27 14:44:47 -07001174ENTRY art_quick_imt_conflict_trampoline
Nicolas Geoffray8ea18d02015-05-26 16:29:08 +01001175 move $a0, $t0
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001176 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001177END art_quick_imt_conflict_trampoline
1178
Ian Rogers468532e2013-08-05 10:56:33 -07001179 .extern artQuickResolutionTrampoline
1180ENTRY art_quick_resolution_trampoline
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001181 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001182 move $a2, rSELF # pass Thread::Current
Ian Rogers65d1b222013-09-27 10:59:41 -07001183 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001184 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers468532e2013-08-05 10:56:33 -07001185 beqz $v0, 1f
Douglas Leung735b8552014-10-31 12:21:40 -07001186 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001187 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers65d1b222013-09-27 10:59:41 -07001188 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001189 jalr $zero, $t9 # tail call to method
Mathieu Chartier19841522013-10-22 11:29:00 -07001190 nop
Ian Rogers468532e2013-08-05 10:56:33 -070011911:
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001192 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001193 DELIVER_PENDING_EXCEPTION
1194END art_quick_resolution_trampoline
1195
Douglas Leung735b8552014-10-31 12:21:40 -07001196 .extern artQuickGenericJniTrampoline
1197 .extern artQuickGenericJniEndTrampoline
1198ENTRY art_quick_generic_jni_trampoline
1199 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
1200 move $s8, $sp # save $sp to $s8
1201 move $s3, $gp # save $gp to $s3
1202
1203 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1204 move $a0, rSELF # pass Thread::Current
1205 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots)
1206 jal artQuickGenericJniTrampoline # (Thread*, SP)
1207 addiu $sp, $sp, -5120 # reserve space on the stack
1208
1209 # The C call will have registered the complete save-frame on success.
1210 # The result of the call is:
1211 # v0: ptr to native code, 0 on error.
1212 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1213 beq $v0, $zero, 1f # check entry error
1214 move $t9, $v0 # save the code ptr
1215 move $sp, $v1 # release part of the alloca
1216
1217 # Load parameters from stack into registers
1218 lw $a0, 0($sp)
1219 lw $a1, 4($sp)
1220 lw $a2, 8($sp)
1221
1222 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1223 jalr $t9 # native call
1224 lw $a3, 12($sp)
1225 addiu $sp, $sp, 16 # remove arg slots
1226
1227 move $gp, $s3 # restore $gp from $s3
1228
1229 # result sign extension is handled in C code
1230 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1231 move $a0, rSELF # pass Thread::Current
1232 move $a2, $v0 # pass result
1233 move $a3, $v1
1234 addiu $sp, $sp, -24 # reserve arg slots
1235 jal artQuickGenericJniEndTrampoline
1236 s.d $f0, 16($sp) # pass result_f
Douglas Leung735b8552014-10-31 12:21:40 -07001237
1238 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001239 bne $t0, $zero, 1f # check for pending exceptions
1240
Douglas Leung735b8552014-10-31 12:21:40 -07001241 move $sp, $s8 # tear down the alloca
1242
1243 # tear dpown the callee-save frame
1244 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1245
Duane Sande34652f2014-11-04 11:09:36 -08001246 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001247 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001248 nop
Douglas Leung735b8552014-10-31 12:21:40 -07001249
12501:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00001251 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
1252 # This will create a new save-all frame, required by the runtime.
Douglas Leung735b8552014-10-31 12:21:40 -07001253 DELIVER_PENDING_EXCEPTION
1254END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08001255
Ian Rogers468532e2013-08-05 10:56:33 -07001256 .extern artQuickToInterpreterBridge
1257ENTRY art_quick_to_interpreter_bridge
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001258 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001259 move $a1, rSELF # pass Thread::Current
1260 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
1261 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers7db619b2013-01-16 18:35:48 -08001262 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Douglas Leung735b8552014-10-31 12:21:40 -07001263 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08001264 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001265 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1266 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001267 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001268 nop
Ian Rogers7db619b2013-01-16 18:35:48 -080012691:
1270 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001271END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08001272
buzbee5bc5a7b2012-03-07 15:52:59 -08001273 /*
jeffhao725a9572012-11-13 18:20:12 -08001274 * Routine that intercepts method calls and returns.
buzbee5bc5a7b2012-03-07 15:52:59 -08001275 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001276 .extern artInstrumentationMethodEntryFromCode
1277 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001278ENTRY art_quick_instrumentation_entry
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001279 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001280 sw $a0, 28($sp) # save arg0 in free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001281 move $a3, $ra # pass $ra
1282 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08001283 move $a2, rSELF # pass Thread::Current
jeffhao8161c032012-10-31 15:50:00 -07001284 move $t9, $v0 # $t9 holds reference to code
Douglas Leung735b8552014-10-31 12:21:40 -07001285 lw $a0, 28($sp) # restore arg0 from free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001286 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
jeffhao8161c032012-10-31 15:50:00 -07001287 jalr $t9 # call method
Ian Rogers62d6c772013-02-27 08:32:07 -08001288 nop
Ian Rogers468532e2013-08-05 10:56:33 -07001289END art_quick_instrumentation_entry
buzbee5bc5a7b2012-03-07 15:52:59 -08001290 /* intentional fallthrough */
Ian Rogers468532e2013-08-05 10:56:33 -07001291 .global art_quick_instrumentation_exit
1292art_quick_instrumentation_exit:
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001293 .cfi_startproc
jeffhao12051ea2013-01-10 11:24:31 -08001294 addiu $t9, $ra, 4 # put current address into $t9 to rebuild $gp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001295 .cpload $t9
Douglas Leungc3d131e2014-07-16 17:32:41 -07001296 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Douglas Leung735b8552014-10-31 12:21:40 -07001297
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001298 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001299 addiu $sp, $sp, -16 # allocate temp storage on the stack
1300 .cfi_adjust_cfa_offset 16
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001301 sw $v0, ARG_SLOT_SIZE+12($sp)
1302 .cfi_rel_offset 2, ARG_SLOT_SIZE+12
1303 sw $v1, ARG_SLOT_SIZE+8($sp)
1304 .cfi_rel_offset 3, ARG_SLOT_SIZE+8
1305 s.d $f0, ARG_SLOT_SIZE($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001306 s.d $f0, 16($sp) # pass fpr result
Ian Rogers62d6c772013-02-27 08:32:07 -08001307 move $a2, $v0 # pass gpr result
1308 move $a3, $v1
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001309 addiu $a1, $sp, ARG_SLOT_SIZE+16 # pass $sp (remove arg slots and temp storage)
Ian Rogers62d6c772013-02-27 08:32:07 -08001310 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
jeffhao12051ea2013-01-10 11:24:31 -08001311 move $a0, rSELF # pass Thread::Current
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001312 move $t9, $v0 # set aside returned link register
jeffhao12051ea2013-01-10 11:24:31 -08001313 move $ra, $v1 # set link register for deoptimization
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001314 lw $v0, ARG_SLOT_SIZE+12($sp) # restore return values
1315 lw $v1, ARG_SLOT_SIZE+8($sp)
1316 l.d $f0, ARG_SLOT_SIZE($sp)
1317 jalr $zero, $t9 # return
1318 addiu $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16 # restore stack
1319 .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE+16)
Ian Rogers468532e2013-08-05 10:56:33 -07001320END art_quick_instrumentation_exit
buzbee5bc5a7b2012-03-07 15:52:59 -08001321
jeffhao12051ea2013-01-10 11:24:31 -08001322 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08001323 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
1324 * will long jump to the upcall with a special exception of -1.
jeffhao12051ea2013-01-10 11:24:31 -08001325 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001326 .extern artDeoptimize
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001327ENTRY art_quick_deoptimize
Jeff Hao14dd5a82013-04-11 10:23:36 -07001328 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001329 jal artDeoptimize # artDeoptimize(Thread*)
jeffhao12051ea2013-01-10 11:24:31 -08001330 # Returns caller method's frame size.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001331 move $a0, rSELF # pass Thread::current
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001332END art_quick_deoptimize
jeffhao12051ea2013-01-10 11:24:31 -08001333
buzbee5bc5a7b2012-03-07 15:52:59 -08001334 /*
1335 * Long integer shift. This is different from the generic 32/64-bit
1336 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1337 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1338 * 6 bits.
1339 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07001340 * $a0: low word
1341 * $a1: high word
1342 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08001343 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001344ENTRY_NO_GP art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001345 /* shl-long vAA, vBB, vCC */
jeffhao7fbee072012-08-24 17:56:54 -07001346 sll $v0, $a0, $a2 # rlo<- alo << (shift&31)
1347 not $v1, $a2 # rhi<- 31-shift (shift is 5b)
1348 srl $a0, 1
1349 srl $a0, $v1 # alo<- alo >> (32-(shift&31))
1350 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001351 andi $a2, 0x20 # shift< shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08001352 beqz $a2, 1f
1353 or $v1, $a0 # rhi<- rhi | alo
1354
1355 move $v1, $v0 # rhi<- rlo (if shift&0x20)
1356 move $v0, $zero # rlo<- 0 (if shift&0x20)
1357
Andreas Gampe8d365912015-01-13 11:32:32 -080013581: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001359 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001360END art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001361
buzbee5bc5a7b2012-03-07 15:52:59 -08001362 /*
1363 * Long integer shift. This is different from the generic 32/64-bit
1364 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1365 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1366 * 6 bits.
1367 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07001368 * $a0: low word
1369 * $a1: high word
1370 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08001371 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001372ENTRY_NO_GP art_quick_shr_long
jeffhao7fbee072012-08-24 17:56:54 -07001373 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
1374 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
1375 sra $a3, $a1, 31 # $a3<- sign(ah)
1376 not $a0, $a2 # alo<- 31-shift (shift is 5b)
1377 sll $a1, 1
1378 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07001379 andi $a2, 0x20 # shift & 0x20
Douglas Leung475cfd82014-12-16 20:15:41 -08001380 beqz $a2, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001381 or $v0, $a1 # rlo<- rlo | ahi
1382
1383 move $v0, $v1 # rlo<- rhi (if shift&0x20)
1384 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20)
1385
Andreas Gampe8d365912015-01-13 11:32:32 -080013861: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001387 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001388END art_quick_shr_long
buzbee5bc5a7b2012-03-07 15:52:59 -08001389
buzbee5bc5a7b2012-03-07 15:52:59 -08001390 /*
1391 * Long integer shift. This is different from the generic 32/64-bit
1392 * binary operations because vAA/vBB are 64-bit but vCC (the shift
1393 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
1394 * 6 bits.
1395 * On entry:
1396 * r0: low word
1397 * r1: high word
1398 * r2: shift count
1399 */
1400 /* ushr-long vAA, vBB, vCC */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001401ENTRY_NO_GP art_quick_ushr_long
jeffhaofc6a30e2012-10-18 18:24:15 -07001402 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001403 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07001404 not $a0, $a2 # alo<- 31-shift (shift is 5b)
1405 sll $a1, 1
1406 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07001407 andi $a2, 0x20 # shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08001408 beqz $a2, 1f
1409 or $v0, $a1 # rlo<- rlo | ahi
1410
1411 move $v0, $v1 # rlo<- rhi (if shift&0x20)
1412 move $v1, $zero # rhi<- 0 (if shift&0x20)
1413
Andreas Gampe8d365912015-01-13 11:32:32 -080014141: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001415 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001416END art_quick_ushr_long
jeffhao7fbee072012-08-24 17:56:54 -07001417
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001418UNIMPLEMENTED art_quick_indexof
1419UNIMPLEMENTED art_quick_string_compareto