blob: 71b8ae281d1930939ed671b20be4e72eb4d051de [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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010033 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010037 * Reserves FRAME_SIZE_SAVE_ALL_CALLEE_SAVES + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080038 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010039.macro SETUP_SAVE_ALL_CALLEE_SAVES_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 96)
45#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -070046#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)
Vladimir Markofd36f1f2016-08-03 18:49:58 +010082 lw $t0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +010091 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly). Restoration assumes non-moving GC.
buzbee5bc5a7b2012-03-07 15:52:59 -080092 * 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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010096 * Reserves FRAME_SIZE_SAVE_REFS_ONLY + ARG_SLOT_SIZE bytes on the stack
buzbee5bc5a7b2012-03-07 15:52:59 -080097 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010098.macro SETUP_SAVE_REFS_ONLY_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.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100103#if (FRAME_SIZE_SAVE_REFS_ONLY != 48)
104#error "FRAME_SIZE_SAVE_REFS_ONLY(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700105#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)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100129 lw $t0, RUNTIME_SAVE_REFS_ONLY_METHOD_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100136.macro RESTORE_SAVE_REFS_ONLY_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100161.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
162 RESTORE_SAVE_REFS_ONLY_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
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100169 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs).
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 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100172.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Goran Jakovljevicff734982015-08-24 12:58:55 +0000173 addiu $sp, $sp, -80
174 .cfi_adjust_cfa_offset 80
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700175
176 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100177#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 80)
178#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(MIPS) size not as expected."
Andreas Gampe5c1e4352014-04-21 19:28:24 -0700179#endif
180
Goran Jakovljevicff734982015-08-24 12:58:55 +0000181 sw $ra, 76($sp)
182 .cfi_rel_offset 31, 76
183 sw $s8, 72($sp)
184 .cfi_rel_offset 30, 72
185 sw $gp, 68($sp)
186 .cfi_rel_offset 28, 68
187 sw $s7, 64($sp)
188 .cfi_rel_offset 23, 64
189 sw $s6, 60($sp)
190 .cfi_rel_offset 22, 60
191 sw $s5, 56($sp)
192 .cfi_rel_offset 21, 56
193 sw $s4, 52($sp)
194 .cfi_rel_offset 20, 52
195 sw $s3, 48($sp)
196 .cfi_rel_offset 19, 48
197 sw $s2, 44($sp)
198 .cfi_rel_offset 18, 44
199 sw $a3, 40($sp)
200 .cfi_rel_offset 7, 40
201 sw $a2, 36($sp)
202 .cfi_rel_offset 6, 36
203 sw $a1, 32($sp)
204 .cfi_rel_offset 5, 32
205 SDu $f14, $f15, 24, $sp, $t0
206 SDu $f12, $f13, 16, $sp, $t0
jeffhaofa147e22012-10-12 17:03:32 -0700207 # bottom will hold Method*
Douglas Leung735b8552014-10-31 12:21:40 -0700208.endm
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700209
Douglas Leung735b8552014-10-31 12:21:40 -0700210 /*
211 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100212 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes non-moving GC.
Goran Jakovljevicff734982015-08-24 12:58:55 +0000213 * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700214 * Clobbers $t0 and $sp
215 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100216 * Reserves FRAME_SIZE_SAVE_REFS_AND_ARGS + ARG_SLOT_SIZE bytes on the stack
Douglas Leung735b8552014-10-31 12:21:40 -0700217 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100218.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
219 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Douglas Leung4af77b72014-10-22 16:32:28 -0700220 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
221 lw $t0, 0($t0)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100222 lw $t0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET($t0)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700223 sw $t0, 0($sp) # Place Method* at bottom of stack.
224 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700225 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
226 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
227.endm
228
229 /*
230 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100231 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes non-moving GC.
Goran Jakovljevicff734982015-08-24 12:58:55 +0000232 * callee-save: $a1-$a3, $f12-$f15, $s2-$s8 + $gp + $ra, 12 total + 3 words padding + method*
Douglas Leung735b8552014-10-31 12:21:40 -0700233 * Clobbers $sp
234 * Use $a0 as the Method* and loads it into bottom of stack.
235 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100236 * Reserves FRAME_SIZE_SAVE_REFS_AND_ARGS + ARG_SLOT_SIZE bytes on the stack
Douglas Leung735b8552014-10-31 12:21:40 -0700237 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100238.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
239 SETUP_SAVE_REFS_AND_ARGS_FRAME_REGISTERS_ONLY
Douglas Leung735b8552014-10-31 12:21:40 -0700240 sw $a0, 0($sp) # Place Method* at bottom of stack.
241 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
242 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
243 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
buzbee5bc5a7b2012-03-07 15:52:59 -0800244.endm
245
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100246.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -0700247 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
248 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +0000249 lw $ra, 76($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800250 .cfi_restore 31
Goran Jakovljevicff734982015-08-24 12:58:55 +0000251 lw $s8, 72($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800252 .cfi_restore 30
Goran Jakovljevicff734982015-08-24 12:58:55 +0000253 lw $gp, 68($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800254 .cfi_restore 28
Goran Jakovljevicff734982015-08-24 12:58:55 +0000255 lw $s7, 64($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800256 .cfi_restore 23
Goran Jakovljevicff734982015-08-24 12:58:55 +0000257 lw $s6, 60($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800258 .cfi_restore 22
Goran Jakovljevicff734982015-08-24 12:58:55 +0000259 lw $s5, 56($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800260 .cfi_restore 21
Goran Jakovljevicff734982015-08-24 12:58:55 +0000261 lw $s4, 52($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800262 .cfi_restore 20
Goran Jakovljevicff734982015-08-24 12:58:55 +0000263 lw $s3, 48($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800264 .cfi_restore 19
Goran Jakovljevicff734982015-08-24 12:58:55 +0000265 lw $s2, 44($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800266 .cfi_restore 18
Goran Jakovljevicff734982015-08-24 12:58:55 +0000267 lw $a3, 40($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800268 .cfi_restore 7
Goran Jakovljevicff734982015-08-24 12:58:55 +0000269 lw $a2, 36($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800270 .cfi_restore 6
Goran Jakovljevicff734982015-08-24 12:58:55 +0000271 lw $a1, 32($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800272 .cfi_restore 5
Goran Jakovljevicff734982015-08-24 12:58:55 +0000273 LDu $f14, $f15, 24, $sp, $t1
274 LDu $f12, $f13, 16, $sp, $t1
275 addiu $sp, $sp, 80 # pop frame
276 .cfi_adjust_cfa_offset -80
buzbee5bc5a7b2012-03-07 15:52:59 -0800277.endm
278
279 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100280 * Macro that sets up the callee save frame to conform with
281 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000282 * when the $sp has already been decremented by FRAME_SIZE_SAVE_EVERYTHING.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100283 * Callee-save: $at, $v0-$v1, $a0-$a3, $t0-$t7, $s0-$s7, $t8-$t9, $gp, $fp $ra, $f0-$f31;
284 * 28(GPR)+ 32(FPR) + 3 words for padding and 1 word for Method*
285 * Clobbers $t0 and $t1.
286 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100287 * Reserves FRAME_SIZE_SAVE_EVERYTHING + ARG_SLOT_SIZE bytes on the stack.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100288 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
289 */
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000290.macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
Vladimir Marko952dbb12016-07-28 12:01:51 +0100291 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100292#if (FRAME_SIZE_SAVE_EVERYTHING != 256)
293#error "FRAME_SIZE_SAVE_EVERYTHING(MIPS) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100294#endif
295
296 sw $ra, 252($sp)
297 .cfi_rel_offset 31, 252
298 sw $fp, 248($sp)
299 .cfi_rel_offset 30, 248
300 sw $gp, 244($sp)
301 .cfi_rel_offset 28, 244
302 sw $t9, 240($sp)
303 .cfi_rel_offset 25, 240
304 sw $t8, 236($sp)
305 .cfi_rel_offset 24, 236
306 sw $s7, 232($sp)
307 .cfi_rel_offset 23, 232
308 sw $s6, 228($sp)
309 .cfi_rel_offset 22, 228
310 sw $s5, 224($sp)
311 .cfi_rel_offset 21, 224
312 sw $s4, 220($sp)
313 .cfi_rel_offset 20, 220
314 sw $s3, 216($sp)
315 .cfi_rel_offset 19, 216
316 sw $s2, 212($sp)
317 .cfi_rel_offset 18, 212
318 sw $s1, 208($sp)
319 .cfi_rel_offset 17, 208
320 sw $s0, 204($sp)
321 .cfi_rel_offset 16, 204
322 sw $t7, 200($sp)
323 .cfi_rel_offset 15, 200
324 sw $t6, 196($sp)
325 .cfi_rel_offset 14, 196
326 sw $t5, 192($sp)
327 .cfi_rel_offset 13, 192
328 sw $t4, 188($sp)
329 .cfi_rel_offset 12, 188
330 sw $t3, 184($sp)
331 .cfi_rel_offset 11, 184
332 sw $t2, 180($sp)
333 .cfi_rel_offset 10, 180
334 sw $t1, 176($sp)
335 .cfi_rel_offset 9, 176
336 sw $t0, 172($sp)
337 .cfi_rel_offset 8, 172
338 sw $a3, 168($sp)
339 .cfi_rel_offset 7, 168
340 sw $a2, 164($sp)
341 .cfi_rel_offset 6, 164
342 sw $a1, 160($sp)
343 .cfi_rel_offset 5, 160
344 sw $a0, 156($sp)
345 .cfi_rel_offset 4, 156
346 sw $v1, 152($sp)
347 .cfi_rel_offset 3, 152
348 sw $v0, 148($sp)
349 .cfi_rel_offset 2, 148
350
351 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
352 bal 1f
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200353 .set push
354 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100355 sw $at, 144($sp)
356 .cfi_rel_offset 1, 144
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200357 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +01003581:
359 .cpload $ra
360
361 SDu $f30, $f31, 136, $sp, $t1
362 SDu $f28, $f29, 128, $sp, $t1
363 SDu $f26, $f27, 120, $sp, $t1
364 SDu $f24, $f25, 112, $sp, $t1
365 SDu $f22, $f23, 104, $sp, $t1
366 SDu $f20, $f21, 96, $sp, $t1
367 SDu $f18, $f19, 88, $sp, $t1
368 SDu $f16, $f17, 80, $sp, $t1
369 SDu $f14, $f15, 72, $sp, $t1
370 SDu $f12, $f13, 64, $sp, $t1
371 SDu $f10, $f11, 56, $sp, $t1
372 SDu $f8, $f9, 48, $sp, $t1
373 SDu $f6, $f7, 40, $sp, $t1
374 SDu $f4, $f5, 32, $sp, $t1
375 SDu $f2, $f3, 24, $sp, $t1
376 SDu $f0, $f1, 16, $sp, $t1
377
378 # 3 words padding and 1 word for holding Method*
379
380 lw $t0, %got(_ZN3art7Runtime9instance_E)($gp)
381 lw $t0, 0($t0)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100382 lw $t0, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET($t0)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100383 sw $t0, 0($sp) # Place Method* at bottom of stack.
384 sw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
385 addiu $sp, $sp, -ARG_SLOT_SIZE # reserve argument slots on the stack
386 .cfi_adjust_cfa_offset ARG_SLOT_SIZE
387.endm
388
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000389 /*
390 * Macro that sets up the callee save frame to conform with
391 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
392 * Callee-save: $at, $v0-$v1, $a0-$a3, $t0-$t7, $s0-$s7, $t8-$t9, $gp, $fp $ra, $f0-$f31;
393 * 28(GPR)+ 32(FPR) + 3 words for padding and 1 word for Method*
394 * Clobbers $t0 and $t1.
395 * Allocates ARG_SLOT_SIZE bytes at the bottom of the stack for arg slots.
396 * Reserves FRAME_SIZE_SAVE_EVERYTHING + ARG_SLOT_SIZE bytes on the stack.
397 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
398 */
399.macro SETUP_SAVE_EVERYTHING_FRAME
400 addiu $sp, $sp, -(FRAME_SIZE_SAVE_EVERYTHING)
401 .cfi_adjust_cfa_offset (FRAME_SIZE_SAVE_EVERYTHING)
402 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
403.endm
404
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100405.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100406 addiu $sp, $sp, ARG_SLOT_SIZE # remove argument slots on the stack
407 .cfi_adjust_cfa_offset -ARG_SLOT_SIZE
408
409 LDu $f30, $f31, 136, $sp, $t1
410 LDu $f28, $f29, 128, $sp, $t1
411 LDu $f26, $f27, 120, $sp, $t1
412 LDu $f24, $f25, 112, $sp, $t1
413 LDu $f22, $f23, 104, $sp, $t1
414 LDu $f20, $f21, 96, $sp, $t1
415 LDu $f18, $f19, 88, $sp, $t1
416 LDu $f16, $f17, 80, $sp, $t1
417 LDu $f14, $f15, 72, $sp, $t1
418 LDu $f12, $f13, 64, $sp, $t1
419 LDu $f10, $f11, 56, $sp, $t1
420 LDu $f8, $f9, 48, $sp, $t1
421 LDu $f6, $f7, 40, $sp, $t1
422 LDu $f4, $f5, 32, $sp, $t1
423 LDu $f2, $f3, 24, $sp, $t1
424 LDu $f0, $f1, 16, $sp, $t1
425
426 lw $ra, 252($sp)
427 .cfi_restore 31
428 lw $fp, 248($sp)
429 .cfi_restore 30
430 lw $gp, 244($sp)
431 .cfi_restore 28
432 lw $t9, 240($sp)
433 .cfi_restore 25
434 lw $t8, 236($sp)
435 .cfi_restore 24
436 lw $s7, 232($sp)
437 .cfi_restore 23
438 lw $s6, 228($sp)
439 .cfi_restore 22
440 lw $s5, 224($sp)
441 .cfi_restore 21
442 lw $s4, 220($sp)
443 .cfi_restore 20
444 lw $s3, 216($sp)
445 .cfi_restore 19
446 lw $s2, 212($sp)
447 .cfi_restore 18
448 lw $s1, 208($sp)
449 .cfi_restore 17
450 lw $s0, 204($sp)
451 .cfi_restore 16
452 lw $t7, 200($sp)
453 .cfi_restore 15
454 lw $t6, 196($sp)
455 .cfi_restore 14
456 lw $t5, 192($sp)
457 .cfi_restore 13
458 lw $t4, 188($sp)
459 .cfi_restore 12
460 lw $t3, 184($sp)
461 .cfi_restore 11
462 lw $t2, 180($sp)
463 .cfi_restore 10
464 lw $t1, 176($sp)
465 .cfi_restore 9
466 lw $t0, 172($sp)
467 .cfi_restore 8
468 lw $a3, 168($sp)
469 .cfi_restore 7
470 lw $a2, 164($sp)
471 .cfi_restore 6
472 lw $a1, 160($sp)
473 .cfi_restore 5
474 lw $a0, 156($sp)
475 .cfi_restore 4
476 lw $v1, 152($sp)
477 .cfi_restore 3
478 lw $v0, 148($sp)
479 .cfi_restore 2
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200480 .set push
481 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100482 lw $at, 144($sp)
483 .cfi_restore 1
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200484 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +0100485
486 addiu $sp, $sp, 256 # pop frame
487 .cfi_adjust_cfa_offset -256
488.endm
489
490 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800491 * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending
492 * exception is Thread::Current()->exception_
493 */
494.macro DELIVER_PENDING_EXCEPTION
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100495 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME # save callee saves for throw
jeffhao8161c032012-10-31 15:50:00 -0700496 la $t9, artDeliverPendingExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800497 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700498 move $a0, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -0800499.endm
500
501.macro RETURN_IF_NO_EXCEPTION
jeffhao7fbee072012-08-24 17:56:54 -0700502 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100503 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700504 bnez $t0, 1f # success if no exception is pending
buzbee5bc5a7b2012-03-07 15:52:59 -0800505 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800506 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -0800507 nop
5081:
509 DELIVER_PENDING_EXCEPTION
510.endm
511
512.macro RETURN_IF_ZERO
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100513 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700514 bnez $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800515 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800516 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800517 nop
5181:
519 DELIVER_PENDING_EXCEPTION
520.endm
521
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800522.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100523 RESTORE_SAVE_REFS_ONLY_FRAME
jeffhao7fbee072012-08-24 17:56:54 -0700524 beqz $v0, 1f # success?
buzbee5bc5a7b2012-03-07 15:52:59 -0800525 nop
Andreas Gampe8d365912015-01-13 11:32:32 -0800526 jalr $zero, $ra # return on success
buzbee5bc5a7b2012-03-07 15:52:59 -0800527 nop
5281:
529 DELIVER_PENDING_EXCEPTION
530.endm
531
buzbee5bc5a7b2012-03-07 15:52:59 -0800532 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100533 * On stack replacement stub.
534 * On entry:
535 * a0 = stack to copy
536 * a1 = size of stack
537 * a2 = pc to call
538 * a3 = JValue* result
539 * [sp + 16] = shorty
540 * [sp + 20] = thread
541 */
542ENTRY art_quick_osr_stub
543 // Save callee general purpose registers, RA and GP.
544 addiu $sp, $sp, -48
545 .cfi_adjust_cfa_offset 48
546 sw $ra, 44($sp)
547 .cfi_rel_offset 31, 44
548 sw $s8, 40($sp)
549 .cfi_rel_offset 30, 40
550 sw $gp, 36($sp)
551 .cfi_rel_offset 28, 36
552 sw $s7, 32($sp)
553 .cfi_rel_offset 23, 32
554 sw $s6, 28($sp)
555 .cfi_rel_offset 22, 28
556 sw $s5, 24($sp)
557 .cfi_rel_offset 21, 24
558 sw $s4, 20($sp)
559 .cfi_rel_offset 20, 20
560 sw $s3, 16($sp)
561 .cfi_rel_offset 19, 16
562 sw $s2, 12($sp)
563 .cfi_rel_offset 18, 12
564 sw $s1, 8($sp)
565 .cfi_rel_offset 17, 8
566 sw $s0, 4($sp)
567 .cfi_rel_offset 16, 4
568
569 move $s8, $sp # Save the stack pointer
570 move $s7, $a1 # Save size of stack
571 move $s6, $a2 # Save the pc to call
572 lw rSELF, 48+20($sp) # Save managed thread pointer into rSELF
573 addiu $t0, $sp, -12 # Reserve space for stack pointer,
574 # JValue* result, and ArtMethod* slot.
575 srl $t0, $t0, 4 # Align stack pointer to 16 bytes
576 sll $sp, $t0, 4 # Update stack pointer
577 sw $s8, 4($sp) # Save old stack pointer
578 sw $a3, 8($sp) # Save JValue* result
579 sw $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
580 subu $sp, $a1 # Reserve space for callee stack
581 move $a2, $a1
582 move $a1, $a0
583 move $a0, $sp
584 la $t9, memcpy
585 jalr $t9 # memcpy (dest a0, src a1, bytes a2)
586 addiu $sp, $sp, -16 # make space for argument slots for memcpy
587 bal .Losr_entry # Call the method
588 addiu $sp, $sp, 16 # restore stack after memcpy
589 lw $a2, 8($sp) # Restore JValue* result
590 lw $sp, 4($sp) # Restore saved stack pointer
591 lw $a0, 48+16($sp) # load shorty
592 lbu $a0, 0($a0) # load return type
593 li $a1, 'D' # put char 'D' into a1
594 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'D'
595 li $a1, 'F' # put char 'F' into a1
596 beq $a0, $a1, .Losr_fp_result # Test if result type char == 'F'
597 nop
598 sw $v0, 0($a2)
599 b .Losr_exit
600 sw $v1, 4($a2) # store v0/v1 into result
601.Losr_fp_result:
602 SDu $f0, $f1, 0, $a2, $t0 # store f0/f1 into result
603.Losr_exit:
604 lw $ra, 44($sp)
605 .cfi_restore 31
606 lw $s8, 40($sp)
607 .cfi_restore 30
608 lw $gp, 36($sp)
609 .cfi_restore 28
610 lw $s7, 32($sp)
611 .cfi_restore 23
612 lw $s6, 28($sp)
613 .cfi_restore 22
614 lw $s5, 24($sp)
615 .cfi_restore 21
616 lw $s4, 20($sp)
617 .cfi_restore 20
618 lw $s3, 16($sp)
619 .cfi_restore 19
620 lw $s2, 12($sp)
621 .cfi_restore 18
622 lw $s1, 8($sp)
623 .cfi_restore 17
624 lw $s0, 4($sp)
625 .cfi_restore 16
626 jalr $zero, $ra
627 addiu $sp, $sp, 48
628 .cfi_adjust_cfa_offset -48
629.Losr_entry:
630 addiu $s7, $s7, -4
631 addu $t0, $s7, $sp
632 move $t9, $s6
633 jalr $zero, $t9
634 sw $ra, 0($t0) # Store RA per the compiler ABI
635END art_quick_osr_stub
636
637 /*
jeffhao7fbee072012-08-24 17:56:54 -0700638 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
buzbee5bc5a7b2012-03-07 15:52:59 -0800639 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
640 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800641ENTRY art_quick_do_long_jump
Duane Sande34652f2014-11-04 11:09:36 -0800642 LDu $f0, $f1, 0*8, $a1, $t1
643 LDu $f2, $f3, 1*8, $a1, $t1
644 LDu $f4, $f5, 2*8, $a1, $t1
645 LDu $f6, $f7, 3*8, $a1, $t1
646 LDu $f8, $f9, 4*8, $a1, $t1
647 LDu $f10, $f11, 5*8, $a1, $t1
648 LDu $f12, $f13, 6*8, $a1, $t1
649 LDu $f14, $f15, 7*8, $a1, $t1
650 LDu $f16, $f17, 8*8, $a1, $t1
651 LDu $f18, $f19, 9*8, $a1, $t1
652 LDu $f20, $f21, 10*8, $a1, $t1
653 LDu $f22, $f23, 11*8, $a1, $t1
654 LDu $f24, $f25, 12*8, $a1, $t1
655 LDu $f26, $f27, 13*8, $a1, $t1
656 LDu $f28, $f29, 14*8, $a1, $t1
657 LDu $f30, $f31, 15*8, $a1, $t1
658
Chris Dearman748dd952014-05-23 10:47:01 -0700659 .set push
660 .set nomacro
661 .set noat
jeffhao7fbee072012-08-24 17:56:54 -0700662 lw $at, 4($a0)
Chris Dearman748dd952014-05-23 10:47:01 -0700663 .set pop
jeffhao7fbee072012-08-24 17:56:54 -0700664 lw $v0, 8($a0)
665 lw $v1, 12($a0)
666 lw $a1, 20($a0)
667 lw $a2, 24($a0)
668 lw $a3, 28($a0)
669 lw $t0, 32($a0)
670 lw $t1, 36($a0)
671 lw $t2, 40($a0)
672 lw $t3, 44($a0)
673 lw $t4, 48($a0)
674 lw $t5, 52($a0)
675 lw $t6, 56($a0)
676 lw $t7, 60($a0)
677 lw $s0, 64($a0)
678 lw $s1, 68($a0)
679 lw $s2, 72($a0)
680 lw $s3, 76($a0)
681 lw $s4, 80($a0)
682 lw $s5, 84($a0)
683 lw $s6, 88($a0)
684 lw $s7, 92($a0)
685 lw $t8, 96($a0)
686 lw $t9, 100($a0)
jeffhao7fbee072012-08-24 17:56:54 -0700687 lw $gp, 112($a0)
688 lw $sp, 116($a0)
689 lw $fp, 120($a0)
690 lw $ra, 124($a0)
691 lw $a0, 16($a0)
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100692 move $v0, $zero # clear result registers v0 and v1 (in branch delay slot)
Goran Jakovljevic75969962015-10-27 12:29:07 +0100693 jalr $zero, $t9 # do long jump
jeffhao7fbee072012-08-24 17:56:54 -0700694 move $v1, $zero
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800695END art_quick_do_long_jump
buzbee5bc5a7b2012-03-07 15:52:59 -0800696
buzbee5bc5a7b2012-03-07 15:52:59 -0800697 /*
698 * Called by managed code, saves most registers (forms basis of long jump context) and passes
699 * the bottom of the stack. artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200700 * the bottom of the thread. On entry a0 holds Throwable*
buzbee5bc5a7b2012-03-07 15:52:59 -0800701 */
Ian Rogers468532e2013-08-05 10:56:33 -0700702ENTRY art_quick_deliver_exception
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100703 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700704 la $t9, artDeliverExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800705 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700706 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700707END art_quick_deliver_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800708
buzbee5bc5a7b2012-03-07 15:52:59 -0800709 /*
710 * Called by managed code to create and deliver a NullPointerException
711 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800712 .extern artThrowNullPointerExceptionFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700713ENTRY art_quick_throw_null_pointer_exception
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100714 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700715 la $t9, artThrowNullPointerExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800716 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700717 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700718END art_quick_throw_null_pointer_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800719
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100720
721 /*
722 * Call installed by a signal handler to create and deliver a NullPointerException.
723 */
724 .extern artThrowNullPointerExceptionFromSignal
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000725ENTRY_NO_GP_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, FRAME_SIZE_SAVE_EVERYTHING
726 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
727 # Retrieve the fault address from the padding where the signal handler stores it.
728 lw $a0, (ARG_SLOT_SIZE + __SIZEOF_POINTER__)($sp)
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100729 la $t9, artThrowNullPointerExceptionFromSignal
730 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uintptr_t, Thread*)
731 move $a1, rSELF # pass Thread::Current
732END art_quick_throw_null_pointer_exception_from_signal
733
buzbee5bc5a7b2012-03-07 15:52:59 -0800734 /*
735 * Called by managed code to create and deliver an ArithmeticException
736 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800737 .extern artThrowDivZeroFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700738ENTRY art_quick_throw_div_zero
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100739 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700740 la $t9, artThrowDivZeroFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800741 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700742 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700743END art_quick_throw_div_zero
buzbee5bc5a7b2012-03-07 15:52:59 -0800744
buzbee5bc5a7b2012-03-07 15:52:59 -0800745 /*
746 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
747 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800748 .extern artThrowArrayBoundsFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700749ENTRY art_quick_throw_array_bounds
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100750 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700751 la $t9, artThrowArrayBoundsFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800752 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700753 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700754END art_quick_throw_array_bounds
buzbee5bc5a7b2012-03-07 15:52:59 -0800755
Ian Rogers57b86d42012-03-27 16:05:41 -0700756 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100757 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
758 * as if thrown from a call to String.charAt().
759 */
760 .extern artThrowStringBoundsFromCode
761ENTRY art_quick_throw_string_bounds
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100762 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100763 la $t9, artThrowStringBoundsFromCode
764 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
765 move $a2, rSELF # pass Thread::Current
766END art_quick_throw_string_bounds
767
768 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700769 * Called by managed code to create and deliver a StackOverflowError.
770 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800771 .extern artThrowStackOverflowFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700772ENTRY art_quick_throw_stack_overflow
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100773 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700774 la $t9, artThrowStackOverflowFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800775 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700776 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700777END art_quick_throw_stack_overflow
buzbee5bc5a7b2012-03-07 15:52:59 -0800778
Ian Rogers57b86d42012-03-27 16:05:41 -0700779 /*
780 * Called by managed code to create and deliver a NoSuchMethodError.
781 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800782 .extern artThrowNoSuchMethodFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700783ENTRY art_quick_throw_no_such_method
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100784 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700785 la $t9, artThrowNoSuchMethodFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800786 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700787 move $a1, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700788END art_quick_throw_no_such_method
buzbee5bc5a7b2012-03-07 15:52:59 -0800789
buzbee5bc5a7b2012-03-07 15:52:59 -0800790 /*
791 * All generated callsites for interface invokes and invocation slow paths will load arguments
jeffhao7fbee072012-08-24 17:56:54 -0700792 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100793 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
jeffhao7fbee072012-08-24 17:56:54 -0700794 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800795 *
jeffhao7fbee072012-08-24 17:56:54 -0700796 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
797 * of the target Method* in $v0 and method->code_ in $v1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800798 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700799 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
buzbee5bc5a7b2012-03-07 15:52:59 -0800800 * thread and we branch to another stub to deliver it.
801 *
802 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
803 * pointing back to the original caller.
804 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700805.macro INVOKE_TRAMPOLINE_BODY cxx_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800806 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100807 SETUP_SAVE_REFS_AND_ARGS_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100808 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100809 la $t9, \cxx_name
810 jalr $t9 # (method_idx, this, Thread*, $sp)
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100811 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
812 move $a0, $v0 # save target Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100813 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhaofa147e22012-10-12 17:03:32 -0700814 beqz $v0, 1f
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100815 move $t9, $v1 # save $v0->code_
Andreas Gampe8d365912015-01-13 11:32:32 -0800816 jalr $zero, $t9
buzbee5bc5a7b2012-03-07 15:52:59 -0800817 nop
8181:
819 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700820.endm
821.macro INVOKE_TRAMPOLINE c_name, cxx_name
822ENTRY \c_name
823 INVOKE_TRAMPOLINE_BODY \cxx_name
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800824END \c_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800825.endm
826
Logan Chien8dbb7082013-01-25 20:31:17 +0800827INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800828
Logan Chien8dbb7082013-01-25 20:31:17 +0800829INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
830INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
831INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
832INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800833
Goran Jakovljevicff734982015-08-24 12:58:55 +0000834.macro LOAD_WORD_TO_REG reg, next_arg, index, label
835 lw $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
836 b \label
837 addiu $\index, 1
838.endm
839
840.macro LOAD_LONG_TO_REG reg1, reg2, next_arg, index, label
841 lw $\reg1, -8($\next_arg) # next_arg points to argument after the current one (offset is 8)
842 lw $\reg2, -4($\next_arg)
843 b \label
844 li $\index, 4 # long can be loaded only to a2_a3 pair so index will be always 4
845.endm
846
847.macro LOAD_FLOAT_TO_REG reg, next_arg, index, label
848 lwc1 $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
849 b \label
850 addiu $\index, 1
851.endm
852
853.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index, tmp, label
854 LDu $\reg1, $\reg2, -8, $\next_arg, $\tmp # next_arg points to argument after the current one
855 # (offset is 8)
856 b \label
857 addiu $\index, 1
858.endm
859
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100860#define SPILL_SIZE 32
861
Jeff Hao79fe5392013-04-24 18:41:58 -0700862 /*
Ian Rogersef7d42f2014-01-06 12:55:46 -0800863 * Invocation stub for quick code.
Jeff Hao5d917302013-02-27 17:57:33 -0800864 * On entry:
865 * a0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700866 * a1 = argument array or null for no argument methods
Jeff Hao5d917302013-02-27 17:57:33 -0800867 * a2 = size of argument array in bytes
868 * a3 = (managed) thread pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700869 * [sp + 16] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800870 * [sp + 20] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800871 */
872ENTRY art_quick_invoke_stub
Jeff Hao5d917302013-02-27 17:57:33 -0800873 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100874 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
875 .cfi_adjust_cfa_offset SPILL_SIZE
876 sw $gp, 16($sp)
Jeff Hao5d917302013-02-27 17:57:33 -0800877 sw $ra, 12($sp)
878 .cfi_rel_offset 31, 12
879 sw $fp, 8($sp)
880 .cfi_rel_offset 30, 8
881 sw $s1, 4($sp)
882 .cfi_rel_offset 17, 4
883 sw $s0, 0($sp)
884 .cfi_rel_offset 16, 0
885 move $fp, $sp # save sp in fp
886 .cfi_def_cfa_register 30
887 move $s1, $a3 # move managed thread pointer into s1
888 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
Goran Jakovljevicff734982015-08-24 12:58:55 +0000889 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700890 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
Goran Jakovljevicff734982015-08-24 12:58:55 +0000891 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
892 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
893 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100894 la $t9, memcpy
895 jalr $t9 # (dest, src, bytes)
Jeff Hao5d917302013-02-27 17:57:33 -0800896 addiu $sp, $sp, -16 # make space for argument slots for memcpy
897 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100898 lw $gp, 16($fp) # restore $gp
899 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000900 lw $a1, 4($sp) # a1 = this*
901 addiu $t0, $sp, 8 # t0 = pointer to the current argument (skip ArtMethod* and this*)
902 li $t3, 2 # t3 = gpr_index = 2 (skip A0 and A1)
903 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100904 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
905 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000906 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
907loop:
908 lbu $t2, 0($t1) # t2 = shorty[i]
909 beqz $t2, loopEnd # finish getting args when shorty[i] == '\0'
910 addiu $t1, 1
911
912 li $t9, 'J' # put char 'J' into t9
913 beq $t9, $t2, isLong # branch if result type char == 'J'
914 li $t9, 'D' # put char 'D' into t9
915 beq $t9, $t2, isDouble # branch if result type char == 'D'
916 li $t9, 'F' # put char 'F' into t9
917 beq $t9, $t2, isSingle # branch if result type char == 'F'
918 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
919 # for both, int and single)
920
921 li $t5, 2 # skip a0 and a1 (ArtMethod* and this*)
922 bne $t5, $t3, 1f # if (gpr_index == 2)
923 addiu $t5, 1
924 LOAD_WORD_TO_REG a2, t0, t3, loop # a2 = current argument, gpr_index++
9251: bne $t5, $t3, loop # else if (gpr_index == 3)
926 nop
927 LOAD_WORD_TO_REG a3, t0, t3, loop # a3 = current argument, gpr_index++
928
929isLong:
930 addiu $t0, 8 # next_arg = curr_arg + 8
931 slti $t5, $t3, 3
932 beqz $t5, 2f # if (gpr_index < 3)
933 nop
934 LOAD_LONG_TO_REG a2, a3, t0, t3, loop # a2_a3 = curr_arg, gpr_index = 4
9352: b loop # else
936 li $t3, 4 # gpr_index = 4
937
938isDouble:
939 addiu $t0, 8 # next_arg = curr_arg + 8
940 li $t5, 0
941 bne $t5, $t4, 3f # if (fp_index == 0)
942 addiu $t5, 1
943 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loop # f12_f13 = curr_arg, fp_index++
9443: bne $t5, $t4, loop # else if (fp_index == 1)
945 nop
946 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loop # f14_f15 = curr_arg, fp_index++
947
948isSingle:
949 li $t5, 0
950 bne $t5, $t4, 4f # if (fp_index == 0)
951 addiu $t5, 1
952 LOAD_FLOAT_TO_REG f12, t0, t4, loop # f12 = curr_arg, fp_index++
9534: bne $t5, $t4, loop # else if (fp_index == 1)
954 nop
955 LOAD_FLOAT_TO_REG f14, t0, t4, loop # f14 = curr_arg, fp_index++
956
957loopEnd:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700958 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800959 jalr $t9 # call the method
Goran Jakovljevicff734982015-08-24 12:58:55 +0000960 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
Jeff Hao5d917302013-02-27 17:57:33 -0800961 move $sp, $fp # restore the stack
962 lw $s0, 0($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800963 .cfi_restore 16
Jeff Hao5d917302013-02-27 17:57:33 -0800964 lw $s1, 4($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800965 .cfi_restore 17
Jeff Hao5d917302013-02-27 17:57:33 -0800966 lw $fp, 8($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800967 .cfi_restore 30
Jeff Hao5d917302013-02-27 17:57:33 -0800968 lw $ra, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800969 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100970 addiu $sp, $sp, SPILL_SIZE
971 .cfi_adjust_cfa_offset -SPILL_SIZE
Jeff Hao5d917302013-02-27 17:57:33 -0800972 lw $t0, 16($sp) # get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800973 lw $t1, 20($sp) # get shorty
974 lb $t1, 0($t1) # get result type char
Goran Jakovljevicff734982015-08-24 12:58:55 +0000975 li $t2, 'D' # put char 'D' into t2
976 beq $t1, $t2, 5f # branch if result type char == 'D'
977 li $t3, 'F' # put char 'F' into t3
978 beq $t1, $t3, 5f # branch if result type char == 'F'
Jeff Hao5d917302013-02-27 17:57:33 -0800979 sw $v0, 0($t0) # store the result
Andreas Gampe8d365912015-01-13 11:32:32 -0800980 jalr $zero, $ra
Jeff Hao5d917302013-02-27 17:57:33 -0800981 sw $v1, 4($t0) # store the other half of the result
Goran Jakovljevicff734982015-08-24 12:58:55 +00009825:
Duane Sande34652f2014-11-04 11:09:36 -0800983 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
Andreas Gampe8d365912015-01-13 11:32:32 -0800984 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -0800985 nop
Jeff Hao5d917302013-02-27 17:57:33 -0800986END art_quick_invoke_stub
987
988 /*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000989 * Invocation static stub for quick code.
990 * On entry:
991 * a0 = method pointer
992 * a1 = argument array or null for no argument methods
993 * a2 = size of argument array in bytes
994 * a3 = (managed) thread pointer
995 * [sp + 16] = JValue* result
996 * [sp + 20] = shorty
997 */
998ENTRY art_quick_invoke_static_stub
999 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001000 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
1001 .cfi_adjust_cfa_offset SPILL_SIZE
1002 sw $gp, 16($sp)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001003 sw $ra, 12($sp)
1004 .cfi_rel_offset 31, 12
1005 sw $fp, 8($sp)
1006 .cfi_rel_offset 30, 8
1007 sw $s1, 4($sp)
1008 .cfi_rel_offset 17, 4
1009 sw $s0, 0($sp)
1010 .cfi_rel_offset 16, 0
1011 move $fp, $sp # save sp in fp
1012 .cfi_def_cfa_register 30
1013 move $s1, $a3 # move managed thread pointer into s1
1014 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
1015 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
1016 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
1017 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
1018 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
1019 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001020 la $t9, memcpy
1021 jalr $t9 # (dest, src, bytes)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001022 addiu $sp, $sp, -16 # make space for argument slots for memcpy
1023 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001024 lw $gp, 16($fp) # restore $gp
1025 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +00001026 addiu $t0, $sp, 4 # t0 = pointer to the current argument (skip ArtMethod*)
1027 li $t3, 1 # t3 = gpr_index = 1 (skip A0)
1028 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001029 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
1030 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001031 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
1032loopS:
1033 lbu $t2, 0($t1) # t2 = shorty[i]
1034 beqz $t2, loopEndS # finish getting args when shorty[i] == '\0'
1035 addiu $t1, 1
1036
1037 li $t9, 'J' # put char 'J' into t9
1038 beq $t9, $t2, isLongS # branch if result type char == 'J'
1039 li $t9, 'D' # put char 'D' into t9
1040 beq $t9, $t2, isDoubleS # branch if result type char == 'D'
1041 li $t9, 'F' # put char 'F' into t9
1042 beq $t9, $t2, isSingleS # branch if result type char == 'F'
1043 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
1044 # for both, int and single)
1045
1046 li $t5, 1 # skip a0 (ArtMethod*)
1047 bne $t5, $t3, 1f # if (gpr_index == 1)
1048 addiu $t5, 1
1049 LOAD_WORD_TO_REG a1, t0, t3, loopS # a1 = current argument, gpr_index++
10501: bne $t5, $t3, 2f # else if (gpr_index == 2)
1051 addiu $t5, 1
1052 LOAD_WORD_TO_REG a2, t0, t3, loopS # a2 = current argument, gpr_index++
10532: bne $t5, $t3, loopS # else if (gpr_index == 3)
1054 nop
1055 LOAD_WORD_TO_REG a3, t0, t3, loopS # a3 = current argument, gpr_index++
1056
1057isLongS:
1058 addiu $t0, 8 # next_arg = curr_arg + 8
1059 slti $t5, $t3, 3
1060 beqz $t5, 3f # if (gpr_index < 3)
1061 nop
1062 LOAD_LONG_TO_REG a2, a3, t0, t3, loopS # a2_a3 = curr_arg, gpr_index = 4
10633: b loopS # else
1064 li $t3, 4 # gpr_index = 4
1065
1066isDoubleS:
1067 addiu $t0, 8 # next_arg = curr_arg + 8
1068 li $t5, 0
1069 bne $t5, $t4, 4f # if (fp_index == 0)
1070 addiu $t5, 1
1071 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loopS # f12_f13 = curr_arg, fp_index++
10724: bne $t5, $t4, loopS # else if (fp_index == 1)
1073 nop
1074 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loopS # f14_f15 = curr_arg, fp_index++
1075
1076isSingleS:
1077 li $t5, 0
1078 bne $t5, $t4, 5f # if (fp_index == 0)
1079 addiu $t5, 1
1080 LOAD_FLOAT_TO_REG f12, t0, t4, loopS # f12 = curr_arg, fp_index++
10815: bne $t5, $t4, loopS # else if (fp_index == 1)
1082 nop
1083 LOAD_FLOAT_TO_REG f14, t0, t4, loopS # f14 = curr_arg, fp_index++
1084
1085loopEndS:
1086 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
1087 jalr $t9 # call the method
1088 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1089 move $sp, $fp # restore the stack
1090 lw $s0, 0($sp)
1091 .cfi_restore 16
1092 lw $s1, 4($sp)
1093 .cfi_restore 17
1094 lw $fp, 8($sp)
1095 .cfi_restore 30
1096 lw $ra, 12($sp)
1097 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001098 addiu $sp, $sp, SPILL_SIZE
1099 .cfi_adjust_cfa_offset -SPILL_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +00001100 lw $t0, 16($sp) # get result pointer
1101 lw $t1, 20($sp) # get shorty
1102 lb $t1, 0($t1) # get result type char
1103 li $t2, 'D' # put char 'D' into t2
1104 beq $t1, $t2, 6f # branch if result type char == 'D'
1105 li $t3, 'F' # put char 'F' into t3
1106 beq $t1, $t3, 6f # branch if result type char == 'F'
1107 sw $v0, 0($t0) # store the result
1108 jalr $zero, $ra
1109 sw $v1, 4($t0) # store the other half of the result
11106:
1111 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
1112 jalr $zero, $ra
1113 nop
1114END art_quick_invoke_static_stub
1115
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001116#undef SPILL_SIZE
1117
Goran Jakovljevicff734982015-08-24 12:58:55 +00001118 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08001119 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1120 * failure.
1121 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001122 .extern artHandleFillArrayDataFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001123ENTRY art_quick_handle_fill_data
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001124 lw $a2, 0($sp) # pass referrer's Method*
1125 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001126 la $t9, artHandleFillArrayDataFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001127 jalr $t9 # (payload offset, Array*, method, Thread*)
1128 move $a3, rSELF # pass Thread::Current
jeffhaofc6a30e2012-10-18 18:24:15 -07001129 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001130END art_quick_handle_fill_data
buzbee5bc5a7b2012-03-07 15:52:59 -08001131
buzbee5bc5a7b2012-03-07 15:52:59 -08001132 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001133 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
buzbee5bc5a7b2012-03-07 15:52:59 -08001134 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001135 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001136ENTRY art_quick_lock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -08001137 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001138 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001139 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001140 la $t9, artLockObjectFromCode
1141 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001142 move $a1, rSELF # pass Thread::Current
Ian Rogers6bcd1632013-10-08 18:50:47 -07001143 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001144END art_quick_lock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001145
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001146ENTRY art_quick_lock_object_no_inline
1147 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
1148 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001149 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001150 la $t9, artLockObjectFromCode
1151 jalr $t9 # (Object* obj, Thread*)
1152 move $a1, rSELF # pass Thread::Current
1153 RETURN_IF_ZERO
1154END art_quick_lock_object_no_inline
1155
buzbee5bc5a7b2012-03-07 15:52:59 -08001156 /*
1157 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1158 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001159 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001160ENTRY art_quick_unlock_object
Ian Rogers86bcdc22014-02-21 22:06:38 -08001161 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001162 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001163 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001164 la $t9, artUnlockObjectFromCode
1165 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001166 move $a1, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001167 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001168END art_quick_unlock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001169
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001170ENTRY art_quick_unlock_object_no_inline
1171 beqz $a0, .Lart_quick_throw_null_pointer_exception_gp_set
1172 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001173 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001174 la $t9, artUnlockObjectFromCode
1175 jalr $t9 # (Object* obj, Thread*)
1176 move $a1, rSELF # pass Thread::Current
1177 RETURN_IF_ZERO
1178END art_quick_unlock_object_no_inline
1179
buzbee5bc5a7b2012-03-07 15:52:59 -08001180 /*
1181 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1182 */
Ian Rogersa9a82542013-10-04 11:17:26 -07001183 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -07001184ENTRY art_quick_check_cast
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001185 addiu $sp, $sp, -32
1186 .cfi_adjust_cfa_offset 32
1187 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001188 sw $ra, 12($sp)
1189 .cfi_rel_offset 31, 12
1190 sw $t9, 8($sp)
1191 sw $a1, 4($sp)
1192 sw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001193 la $t9, artIsAssignableFromCode
1194 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07001195 addiu $sp, $sp, -16 # reserve argument slots on the stack
1196 addiu $sp, $sp, 16
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001197 lw $gp, 16($sp)
Ian Rogers86bcdc22014-02-21 22:06:38 -08001198 beqz $v0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001199 lw $ra, 12($sp)
Andreas Gampe8d365912015-01-13 11:32:32 -08001200 jalr $zero, $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001201 addiu $sp, $sp, 32
1202 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001203.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001204 lw $t9, 8($sp)
1205 lw $a1, 4($sp)
1206 lw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001207 addiu $sp, $sp, 32
1208 .cfi_adjust_cfa_offset -32
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001209 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -07001210 la $t9, artThrowClassCastException
Andreas Gampe8d365912015-01-13 11:32:32 -08001211 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001212 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -07001213END art_quick_check_cast
buzbee5bc5a7b2012-03-07 15:52:59 -08001214
buzbee5bc5a7b2012-03-07 15:52:59 -08001215 /*
Man Cao1aee9002015-07-14 22:31:42 -07001216 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1217 * nReg is the register number for rReg.
1218 */
1219.macro POP_REG_NE rReg, nReg, offset, rExclude
1220 .ifnc \rReg, \rExclude
1221 lw \rReg, \offset($sp) # restore rReg
1222 .cfi_restore \nReg
1223 .endif
1224.endm
1225
1226 /*
1227 * Macro to insert read barrier, only used in art_quick_aput_obj.
1228 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1229 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1230 */
1231.macro READ_BARRIER rDest, rObj, offset
1232#ifdef USE_READ_BARRIER
1233 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
1234 addiu $sp, $sp, -32
1235 .cfi_adjust_cfa_offset 32
1236 sw $ra, 28($sp)
1237 .cfi_rel_offset 31, 28
1238 sw $t9, 24($sp)
1239 .cfi_rel_offset 25, 24
1240 sw $t1, 20($sp)
1241 .cfi_rel_offset 9, 20
1242 sw $t0, 16($sp)
1243 .cfi_rel_offset 8, 16
1244 sw $a2, 8($sp) # padding slot at offset 12 (padding can be any slot in the 32B)
1245 .cfi_rel_offset 6, 8
1246 sw $a1, 4($sp)
1247 .cfi_rel_offset 5, 4
1248 sw $a0, 0($sp)
1249 .cfi_rel_offset 4, 0
1250
Man Cao63069212015-08-21 15:51:39 -07001251 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001252 .ifnc \rObj, $a1
1253 move $a1, \rObj # pass rObj
1254 .endif
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001255 addiu $a2, $zero, \offset # pass offset
1256 la $t9, artReadBarrierSlow
1257 jalr $t9 # artReadBarrierSlow(ref, rObj, offset)
Man Cao1aee9002015-07-14 22:31:42 -07001258 addiu $sp, $sp, -16 # Use branch delay slot to reserve argument slots on the stack
1259 # before the call to artReadBarrierSlow.
1260 addiu $sp, $sp, 16 # restore stack after call to artReadBarrierSlow
1261 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1262 move \rDest, $v0 # save return value in rDest
1263 # (rDest cannot be v0 in art_quick_aput_obj)
1264
1265 lw $a0, 0($sp) # restore registers except rDest
1266 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1267 .cfi_restore 4
1268 lw $a1, 4($sp)
1269 .cfi_restore 5
1270 lw $a2, 8($sp)
1271 .cfi_restore 6
1272 POP_REG_NE $t0, 8, 16, \rDest
1273 POP_REG_NE $t1, 9, 20, \rDest
1274 lw $t9, 24($sp)
1275 .cfi_restore 25
1276 lw $ra, 28($sp) # restore $ra
1277 .cfi_restore 31
1278 addiu $sp, $sp, 32
1279 .cfi_adjust_cfa_offset -32
1280#else
1281 lw \rDest, \offset(\rObj)
1282 UNPOISON_HEAP_REF \rDest
1283#endif // USE_READ_BARRIER
1284.endm
1285
1286 /*
Ian Rogersa9a82542013-10-04 11:17:26 -07001287 * Entry from managed code for array put operations of objects where the value being stored
1288 * needs to be checked for compatibility.
1289 * a0 = array, a1 = index, a2 = value
buzbee5bc5a7b2012-03-07 15:52:59 -08001290 */
Ian Rogersa9a82542013-10-04 11:17:26 -07001291ENTRY art_quick_aput_obj_with_null_and_bound_check
Ian Rogers86bcdc22014-02-21 22:06:38 -08001292 bnez $a0, .Lart_quick_aput_obj_with_bound_check_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001293 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001294 b .Lart_quick_throw_null_pointer_exception_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001295 nop
1296END art_quick_aput_obj_with_null_and_bound_check
1297
1298ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001299 lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001300 sltu $t1, $a1, $t0
Ian Rogers86bcdc22014-02-21 22:06:38 -08001301 bnez $t1, .Lart_quick_aput_obj_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001302 nop
1303 move $a0, $a1
Ian Rogers86bcdc22014-02-21 22:06:38 -08001304 b .Lart_quick_throw_array_bounds_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001305 move $a1, $t0
1306END art_quick_aput_obj_with_bound_check
1307
Man Cao1aee9002015-07-14 22:31:42 -07001308#ifdef USE_READ_BARRIER
1309 .extern artReadBarrierSlow
1310#endif
Ian Rogersa9a82542013-10-04 11:17:26 -07001311ENTRY art_quick_aput_obj
Ian Rogers86bcdc22014-02-21 22:06:38 -08001312 beqz $a2, .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -07001313 nop
Man Cao1aee9002015-07-14 22:31:42 -07001314 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1315 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1316 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogers86bcdc22014-02-21 22:06:38 -08001317 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
Ian Rogersa9a82542013-10-04 11:17:26 -07001318 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001319.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -07001320 sll $a1, $a1, 2
1321 add $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001322 POISON_HEAP_REF $a2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001323 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001324 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1325 srl $t1, $a0, 7
1326 add $t1, $t1, $t0
1327 sb $t0, ($t1)
Andreas Gampe8d365912015-01-13 11:32:32 -08001328 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001329 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001330.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -07001331 sll $a1, $a1, 2
1332 add $t0, $a0, $a1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001333 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Andreas Gampe8d365912015-01-13 11:32:32 -08001334 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001335 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001336.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -07001337 addiu $sp, $sp, -32
1338 .cfi_adjust_cfa_offset 32
1339 sw $ra, 28($sp)
1340 .cfi_rel_offset 31, 28
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001341 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001342 sw $t9, 12($sp)
1343 sw $a2, 8($sp)
1344 sw $a1, 4($sp)
1345 sw $a0, 0($sp)
1346 move $a1, $t1
1347 move $a0, $t0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001348 la $t9, artIsAssignableFromCode
1349 jalr $t9 # (Class*, Class*)
1350 addiu $sp, $sp, -16 # reserve argument slots on the stack
1351 addiu $sp, $sp, 16
Ian Rogersa9a82542013-10-04 11:17:26 -07001352 lw $ra, 28($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001353 lw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001354 lw $t9, 12($sp)
1355 lw $a2, 8($sp)
1356 lw $a1, 4($sp)
1357 lw $a0, 0($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001358 addiu $sp, 32
Ian Rogersa9a82542013-10-04 11:17:26 -07001359 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001360 bnez $v0, .Ldo_aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001361 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001362 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -07001363 move $a1, $a2
Ian Rogersa9a82542013-10-04 11:17:26 -07001364 la $t9, artThrowArrayStoreException
Andreas Gampe8d365912015-01-13 11:32:32 -08001365 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001366 move $a2, rSELF # pass Thread::Current
Ian Rogersa9a82542013-10-04 11:17:26 -07001367END art_quick_aput_obj
buzbee5bc5a7b2012-03-07 15:52:59 -08001368
buzbee5bc5a7b2012-03-07 15:52:59 -08001369 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001370 * Called by managed code to resolve a static field and load a boolean primitive value.
1371 */
1372 .extern artGetBooleanStaticFromCode
1373ENTRY art_quick_get_boolean_static
Douglas Leung735b8552014-10-31 12:21:40 -07001374 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001375 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001376 la $t9, artGetBooleanStaticFromCode
1377 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001378 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001379 RETURN_IF_NO_EXCEPTION
1380END art_quick_get_boolean_static
1381 /*
1382 * Called by managed code to resolve a static field and load a byte primitive value.
1383 */
1384 .extern artGetByteStaticFromCode
1385ENTRY art_quick_get_byte_static
Douglas Leung735b8552014-10-31 12:21:40 -07001386 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001387 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001388 la $t9, artGetByteStaticFromCode
1389 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001390 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001391 RETURN_IF_NO_EXCEPTION
1392END art_quick_get_byte_static
1393
1394 /*
1395 * Called by managed code to resolve a static field and load a char primitive value.
1396 */
1397 .extern artGetCharStaticFromCode
1398ENTRY art_quick_get_char_static
Douglas Leung735b8552014-10-31 12:21:40 -07001399 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001400 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001401 la $t9, artGetCharStaticFromCode
1402 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001403 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001404 RETURN_IF_NO_EXCEPTION
1405END art_quick_get_char_static
1406 /*
1407 * Called by managed code to resolve a static field and load a short primitive value.
1408 */
1409 .extern artGetShortStaticFromCode
1410ENTRY art_quick_get_short_static
Douglas Leung735b8552014-10-31 12:21:40 -07001411 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001412 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001413 la $t9, artGetShortStaticFromCode
1414 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001415 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001416 RETURN_IF_NO_EXCEPTION
1417END art_quick_get_short_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001418
buzbee5bc5a7b2012-03-07 15:52:59 -08001419 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001420 * Called by managed code to resolve a static field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001421 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001422 .extern artGet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001423ENTRY art_quick_get32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001424 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001425 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001426 la $t9, artGet32StaticFromCode
1427 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001428 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001429 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001430END art_quick_get32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001431
buzbee5bc5a7b2012-03-07 15:52:59 -08001432 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001433 * Called by managed code to resolve a static field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001434 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001435 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001436ENTRY art_quick_get64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001437 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001438 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001439 la $t9, artGet64StaticFromCode
1440 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001441 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001442 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001443END art_quick_get64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001444
buzbee5bc5a7b2012-03-07 15:52:59 -08001445 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001446 * Called by managed code to resolve a static field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001447 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001448 .extern artGetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001449ENTRY art_quick_get_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001450 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001451 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001452 la $t9, artGetObjStaticFromCode
1453 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001454 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001455 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001456END art_quick_get_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001457
buzbee5bc5a7b2012-03-07 15:52:59 -08001458 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001459 * Called by managed code to resolve an instance field and load a boolean primitive value.
1460 */
1461 .extern artGetBooleanInstanceFromCode
1462ENTRY art_quick_get_boolean_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001463 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001464 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001465 la $t9, artGetBooleanInstanceFromCode
1466 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001467 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001468 RETURN_IF_NO_EXCEPTION
1469END art_quick_get_boolean_instance
1470 /*
1471 * Called by managed code to resolve an instance field and load a byte primitive value.
1472 */
1473 .extern artGetByteInstanceFromCode
1474ENTRY art_quick_get_byte_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001475 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001476 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001477 la $t9, artGetByteInstanceFromCode
1478 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001479 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001480 RETURN_IF_NO_EXCEPTION
1481END art_quick_get_byte_instance
1482
1483 /*
1484 * Called by managed code to resolve an instance field and load a char primitive value.
1485 */
1486 .extern artGetCharInstanceFromCode
1487ENTRY art_quick_get_char_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001488 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001489 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001490 la $t9, artGetCharInstanceFromCode
1491 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001492 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001493 RETURN_IF_NO_EXCEPTION
1494END art_quick_get_char_instance
1495 /*
1496 * Called by managed code to resolve an instance field and load a short primitive value.
1497 */
1498 .extern artGetShortInstanceFromCode
1499ENTRY art_quick_get_short_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001500 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001501 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001502 la $t9, artGetShortInstanceFromCode
1503 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001504 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001505 RETURN_IF_NO_EXCEPTION
1506END art_quick_get_short_instance
1507
1508 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001509 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001510 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001511 .extern artGet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001512ENTRY art_quick_get32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001513 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001514 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001515 la $t9, artGet32InstanceFromCode
1516 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001517 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001518 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001519END art_quick_get32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001520
buzbee5bc5a7b2012-03-07 15:52:59 -08001521 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001522 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001523 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001524 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001525ENTRY art_quick_get64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001526 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001527 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001528 la $t9, artGet64InstanceFromCode
1529 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001530 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001531 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001532END art_quick_get64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001533
buzbee5bc5a7b2012-03-07 15:52:59 -08001534 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001535 * Called by managed code to resolve an instance field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001536 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001537 .extern artGetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001538ENTRY art_quick_get_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001539 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001540 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001541 la $t9, artGetObjInstanceFromCode
1542 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001543 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001544 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001545END art_quick_get_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001546
buzbee5bc5a7b2012-03-07 15:52:59 -08001547 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001548 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1549 */
1550 .extern artSet8StaticFromCode
1551ENTRY art_quick_set8_static
Douglas Leung735b8552014-10-31 12:21:40 -07001552 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001553 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001554 la $t9, artSet8StaticFromCode
1555 jalr $t9 # (field_idx, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001556 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001557 RETURN_IF_ZERO
1558END art_quick_set8_static
1559
1560 /*
1561 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1562 */
1563 .extern artSet16StaticFromCode
1564ENTRY art_quick_set16_static
Douglas Leung735b8552014-10-31 12:21:40 -07001565 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001566 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001567 la $t9, artSet16StaticFromCode
1568 jalr $t9 # (field_idx, new_val, referrer, Thread*, $sp)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001569 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001570 RETURN_IF_ZERO
1571END art_quick_set16_static
1572
1573 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001574 * Called by managed code to resolve a static field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001575 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001576 .extern artSet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001577ENTRY art_quick_set32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001578 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001579 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001580 la $t9, artSet32StaticFromCode
1581 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001582 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001583 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001584END art_quick_set32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001585
buzbee5bc5a7b2012-03-07 15:52:59 -08001586 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001587 * Called by managed code to resolve a static field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001588 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001589 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001590ENTRY art_quick_set64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001591 lw $a1, 0($sp) # pass referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001592 # 64 bit new_val is in a2:a3 pair
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001593 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001594 la $t9, artSet64StaticFromCode
1595 jalr $t9 # (field_idx, referrer, new_val, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001596 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001597 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001598END art_quick_set64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001599
buzbee5bc5a7b2012-03-07 15:52:59 -08001600 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001601 * Called by managed code to resolve a static field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001602 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001603 .extern artSetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001604ENTRY art_quick_set_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001605 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001606 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001607 la $t9, artSetObjStaticFromCode
1608 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001609 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001610 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001611END art_quick_set_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001612
buzbee5bc5a7b2012-03-07 15:52:59 -08001613 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001614 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1615 */
1616 .extern artSet8InstanceFromCode
1617ENTRY art_quick_set8_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001618 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001619 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001620 la $t9, artSet8InstanceFromCode
1621 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001622 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001623 RETURN_IF_ZERO
1624END art_quick_set8_instance
1625
1626 /*
1627 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1628 */
1629 .extern artSet16InstanceFromCode
1630ENTRY art_quick_set16_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001631 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001632 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001633 la $t9, artSet16InstanceFromCode
1634 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001635 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001636 RETURN_IF_ZERO
1637END art_quick_set16_instance
1638
1639 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001640 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001641 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001642 .extern artSet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001643ENTRY art_quick_set32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001644 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001645 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001646 la $t9, artSet32InstanceFromCode
1647 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001648 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001649 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001650END art_quick_set32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001651
buzbee5bc5a7b2012-03-07 15:52:59 -08001652 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001653 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001654 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001655 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001656ENTRY art_quick_set64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001657 lw $t1, 0($sp) # load referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001658 # 64 bit new_val is in a2:a3 pair
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001659 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001660 sw rSELF, 20($sp) # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001661 la $t9, artSet64InstanceFromCode
1662 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Douglas Leung735b8552014-10-31 12:21:40 -07001663 sw $t1, 16($sp) # pass referrer's Method*
buzbee5bc5a7b2012-03-07 15:52:59 -08001664 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001665END art_quick_set64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001666
buzbee5bc5a7b2012-03-07 15:52:59 -08001667 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001668 * Called by managed code to resolve an instance field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001669 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001670 .extern artSetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001671ENTRY art_quick_set_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001672 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001673 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001674 la $t9, artSetObjInstanceFromCode
1675 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001676 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001677 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001678END art_quick_set_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001679
Vladimir Markoa3c38272015-04-28 12:37:09 +01001680// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001681.macro ONE_ARG_DOWNCALL name, entrypoint, return
1682 .extern \entrypoint
1683ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001684 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001685 la $t9, \entrypoint
1686 jalr $t9
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001687 move $a1, rSELF # pass Thread::Current
1688 \return
1689END \name
1690.endm
1691
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001692.macro TWO_ARG_DOWNCALL name, entrypoint, return
1693 .extern \entrypoint
1694ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001695 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001696 la $t9, \entrypoint
1697 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001698 move $a2, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001699 \return
1700END \name
1701.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001702
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001703.macro THREE_ARG_DOWNCALL name, entrypoint, return
1704 .extern \entrypoint
1705ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001706 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001707 la $t9, \entrypoint
1708 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001709 move $a3, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001710 \return
1711END \name
1712.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001713
Jeff Hao848f70a2014-01-15 13:49:50 -08001714.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1715 .extern \entrypoint
1716ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001717 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001718 la $t9, \entrypoint
1719 jalr $t9
Vladimir Markoa3c38272015-04-28 12:37:09 +01001720 sw rSELF, 16($sp) # pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -08001721 \return
1722END \name
1723.endm
1724
Mathieu Chartier7410f292013-11-24 13:17:35 -08001725// Generate the allocation entrypoints for each allocator.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001726GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001727
Pavle Batuta712c59d2015-12-02 18:39:01 +01001728// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1729ENTRY art_quick_alloc_object_rosalloc
1730
1731 # Fast path rosalloc allocation
1732 # a0: type_idx
1733 # a1: ArtMethod*
1734 # s1: Thread::Current
1735 # -----------------------------
1736 # t0: class
1737 # t1: object size
1738 # t2: rosalloc run
1739 # t3: thread stack top offset
1740 # t4: thread stack bottom offset
1741 # v0: free list head
1742 #
1743 # t5, t6 : temps
1744
1745 lw $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_32($a1) # Load dex cache resolved types
1746 # array.
1747
1748 sll $t5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1749 addu $t5, $t0, $t5 # Compute the index.
1750 lw $t0, 0($t5) # Load class (t0).
1751 beqz $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1752
1753 li $t6, MIRROR_CLASS_STATUS_INITIALIZED
1754 lw $t5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1755 bne $t5, $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1756
1757 # Add a fake dependence from the following access flag and size loads to the status load. This
1758 # is to prevent those loads from being reordered above the status load and reading wrong values.
1759 xor $t5, $t5, $t5
1760 addu $t0, $t0, $t5
1761
1762 lw $t5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1763 li $t6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1764 and $t6, $t5, $t6
1765 bnez $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1766
1767 lw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation
1768 lw $t4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # stack has any room left.
1769 bgeu $t3, $t4, .Lart_quick_alloc_object_rosalloc_slow_path
1770
1771 lw $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1772 li $t5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1773 # allocation.
1774 bgtu $t1, $t5, .Lart_quick_alloc_object_rosalloc_slow_path
1775
1776 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1777 # quantum size and divide by the quantum size and subtract by 1.
1778
1779 addiu $t1, $t1, -1 # Decrease obj size and shift right
1780 srl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # by quantum.
1781
1782 sll $t2, $t1, POINTER_SIZE_SHIFT
1783 addu $t2, $t2, $s1
1784 lw $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1785
1786 # Load the free list head (v0).
1787 # NOTE: this will be the return val.
1788
1789 lw $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1790 beqz $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1791 nop
1792
1793 # Load the next pointer of the head and update the list head with the next pointer.
1794
1795 lw $t5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1796 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1797
1798 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1799 # asserted to match.
1800
1801#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1802#error "Class pointer needs to overwrite next pointer."
1803#endif
1804
1805 POISON_HEAP_REF $t0
1806 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1807
1808 # Push the new object onto the thread local allocation stack and increment the thread local
1809 # allocation stack top.
1810
1811 sw $v0, 0($t3)
1812 addiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1813 sw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1814
1815 # Decrement the size of the free list.
1816
1817 lw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1818 addiu $t5, $t5, -1
1819 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1820
1821 sync # Fence.
1822
1823 jalr $zero, $ra
1824 nop
1825
1826 .Lart_quick_alloc_object_rosalloc_slow_path:
1827
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001828 SETUP_SAVE_REFS_ONLY_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001829 la $t9, artAllocObjectFromCodeRosAlloc
1830 jalr $t9
Chris Larsencf283da2016-01-19 16:45:35 -08001831 move $a2, $s1 # Pass self as argument.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001832 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1833
1834END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001835
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001836GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1837GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1838
buzbee5bc5a7b2012-03-07 15:52:59 -08001839 /*
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001840 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001841 * exception on error. On success the String is returned. A0 holds the string index. The fast
1842 * path check for hit in strings cache has already been performed.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001843 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001844ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001845
1846 /*
1847 * Entry from managed code when uninitialized static storage, this stub will run the class
1848 * initializer and deliver the exception on error. On success the static storage base is
1849 * returned.
1850 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001851ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001852
1853 /*
1854 * Entry from managed code when dex cache misses for a type_idx.
1855 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001856ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001857
1858 /*
1859 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1860 * miss.
1861 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001862ONE_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 -08001863
1864 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001865 * Called by managed code when the value in rSUSPEND has been decremented to 0.
buzbee5bc5a7b2012-03-07 15:52:59 -08001866 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001867 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001868ENTRY_NO_GP art_quick_test_suspend
1869 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1870 bnez rSUSPEND, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001871 addiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Andreas Gampe8d365912015-01-13 11:32:32 -08001872 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -08001873 nop
18741:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001875 SETUP_SAVE_EVERYTHING_FRAME # save everything for stack crawl
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001876 la $t9, artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001877 jalr $t9 # (Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001878 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001879 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001880 jalr $zero, $ra
1881 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001882END art_quick_test_suspend
buzbee5bc5a7b2012-03-07 15:52:59 -08001883
buzbee5bc5a7b2012-03-07 15:52:59 -08001884 /*
1885 * Called by managed code that is attempting to call a method on a proxy class. On entry
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001886 * a0 holds the proxy method; a1, a2 and a3 may contain arguments.
buzbee5bc5a7b2012-03-07 15:52:59 -08001887 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001888 .extern artQuickProxyInvokeHandler
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001889ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001890 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07001891 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001892 la $t9, artQuickProxyInvokeHandler
1893 jalr $t9 # (Method* proxy method, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001894 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
jeffhao7fbee072012-08-24 17:56:54 -07001895 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001896 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhao7fbee072012-08-24 17:56:54 -07001897 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001898 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1899 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001900 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001901 nop
buzbee5bc5a7b2012-03-07 15:52:59 -080019021:
1903 DELIVER_PENDING_EXCEPTION
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001904END art_quick_proxy_invoke_handler
buzbee5bc5a7b2012-03-07 15:52:59 -08001905
Jeff Hao88474b42013-10-23 16:24:40 -07001906 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001907 * Called to resolve an imt conflict.
1908 * a0 is the conflict ArtMethod.
1909 * t0 is a hidden argument that holds the target interface method's dex method index.
1910 *
1911 * Note that this stub writes to a0, t0 and t1.
Jeff Hao88474b42013-10-23 16:24:40 -07001912 */
Douglas Leung13738bf2014-10-27 14:44:47 -07001913ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001914 lw $t1, 0($sp) # Load referrer.
1915 lw $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_32($t1) # Load dex cache methods array.
1916 sll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1917 addu $t0, $t1, $t0 # Add offset to base.
1918 lw $t0, 0($t0) # Load interface method.
1919 lw $a0, ART_METHOD_JNI_OFFSET_32($a0) # Load ImtConflictTable.
1920
1921.Limt_table_iterate:
1922 lw $t1, 0($a0) # Load next entry in ImtConflictTable.
1923 # Branch if found.
1924 beq $t1, $t0, .Limt_table_found
1925 nop
1926 # If the entry is null, the interface method is not in the ImtConflictTable.
1927 beqz $t1, .Lconflict_trampoline
1928 nop
1929 # Iterate over the entries of the ImtConflictTable.
1930 b .Limt_table_iterate
1931 addiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1932
1933.Limt_table_found:
1934 # We successfully hit an entry in the table. Load the target method and jump to it.
1935 lw $a0, __SIZEOF_POINTER__($a0)
1936 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)
1937 jr $t9
1938 nop
1939
1940.Lconflict_trampoline:
1941 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001942 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001943END art_quick_imt_conflict_trampoline
1944
Ian Rogers468532e2013-08-05 10:56:33 -07001945 .extern artQuickResolutionTrampoline
1946ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001947 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001948 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001949 la $t9, artQuickResolutionTrampoline
1950 jalr $t9 # (Method* called, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001951 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers468532e2013-08-05 10:56:33 -07001952 beqz $v0, 1f
Douglas Leung735b8552014-10-31 12:21:40 -07001953 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001954 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers65d1b222013-09-27 10:59:41 -07001955 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001956 jalr $zero, $t9 # tail call to method
Mathieu Chartier19841522013-10-22 11:29:00 -07001957 nop
Ian Rogers468532e2013-08-05 10:56:33 -070019581:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001959 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001960 DELIVER_PENDING_EXCEPTION
1961END art_quick_resolution_trampoline
1962
Douglas Leung735b8552014-10-31 12:21:40 -07001963 .extern artQuickGenericJniTrampoline
1964 .extern artQuickGenericJniEndTrampoline
1965ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001966 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07001967 move $s8, $sp # save $sp to $s8
1968 move $s3, $gp # save $gp to $s3
1969
1970 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1971 move $a0, rSELF # pass Thread::Current
1972 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001973 la $t9, artQuickGenericJniTrampoline
1974 jalr $t9 # (Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001975 addiu $sp, $sp, -5120 # reserve space on the stack
1976
1977 # The C call will have registered the complete save-frame on success.
1978 # The result of the call is:
1979 # v0: ptr to native code, 0 on error.
1980 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1981 beq $v0, $zero, 1f # check entry error
1982 move $t9, $v0 # save the code ptr
1983 move $sp, $v1 # release part of the alloca
1984
1985 # Load parameters from stack into registers
1986 lw $a0, 0($sp)
1987 lw $a1, 4($sp)
1988 lw $a2, 8($sp)
1989
1990 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1991 jalr $t9 # native call
1992 lw $a3, 12($sp)
1993 addiu $sp, $sp, 16 # remove arg slots
1994
1995 move $gp, $s3 # restore $gp from $s3
1996
1997 # result sign extension is handled in C code
1998 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1999 move $a0, rSELF # pass Thread::Current
2000 move $a2, $v0 # pass result
2001 move $a3, $v1
2002 addiu $sp, $sp, -24 # reserve arg slots
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002003 la $t9, artQuickGenericJniEndTrampoline
2004 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07002005 s.d $f0, 16($sp) # pass result_f
Douglas Leung735b8552014-10-31 12:21:40 -07002006
2007 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002008 bne $t0, $zero, 1f # check for pending exceptions
2009
Douglas Leung735b8552014-10-31 12:21:40 -07002010 move $sp, $s8 # tear down the alloca
2011
2012 # tear dpown the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002013 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002014
Duane Sande34652f2014-11-04 11:09:36 -08002015 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002016 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002017 nop
Douglas Leung735b8552014-10-31 12:21:40 -07002018
20191:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002020 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2021 # This will create a new save-all frame, required by the runtime.
Douglas Leung735b8552014-10-31 12:21:40 -07002022 DELIVER_PENDING_EXCEPTION
2023END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08002024
Ian Rogers468532e2013-08-05 10:56:33 -07002025 .extern artQuickToInterpreterBridge
2026ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002027 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002028 move $a1, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002029 la $t9, artQuickToInterpreterBridge
2030 jalr $t9 # (Method* method, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002031 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers7db619b2013-01-16 18:35:48 -08002032 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002033 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08002034 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002035 # don't care if $v0 and/or $v1 are modified, when exception branch taken
2036 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002037 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002038 nop
Ian Rogers7db619b2013-01-16 18:35:48 -080020391:
2040 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07002041END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08002042
buzbee5bc5a7b2012-03-07 15:52:59 -08002043 /*
jeffhao725a9572012-11-13 18:20:12 -08002044 * Routine that intercepts method calls and returns.
buzbee5bc5a7b2012-03-07 15:52:59 -08002045 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002046 .extern artInstrumentationMethodEntryFromCode
2047 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07002048ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002049 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002050 sw $a0, 28($sp) # save arg0 in free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002051 move $a3, $ra # pass $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002052 la $t9, artInstrumentationMethodEntryFromCode
2053 jalr $t9 # (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08002054 move $a2, rSELF # pass Thread::Current
jeffhao8161c032012-10-31 15:50:00 -07002055 move $t9, $v0 # $t9 holds reference to code
Douglas Leung735b8552014-10-31 12:21:40 -07002056 lw $a0, 28($sp) # restore arg0 from free arg slot
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002057 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhao8161c032012-10-31 15:50:00 -07002058 jalr $t9 # call method
Ian Rogers62d6c772013-02-27 08:32:07 -08002059 nop
Ian Rogers468532e2013-08-05 10:56:33 -07002060END art_quick_instrumentation_entry
buzbee5bc5a7b2012-03-07 15:52:59 -08002061 /* intentional fallthrough */
Ian Rogers468532e2013-08-05 10:56:33 -07002062 .global art_quick_instrumentation_exit
2063art_quick_instrumentation_exit:
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002064 .cfi_startproc
jeffhao12051ea2013-01-10 11:24:31 -08002065 addiu $t9, $ra, 4 # put current address into $t9 to rebuild $gp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002066 .cpload $t9
Douglas Leungc3d131e2014-07-16 17:32:41 -07002067 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Douglas Leung735b8552014-10-31 12:21:40 -07002068
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002069 SETUP_SAVE_REFS_ONLY_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002070 addiu $sp, $sp, -16 # allocate temp storage on the stack
2071 .cfi_adjust_cfa_offset 16
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002072 sw $v0, ARG_SLOT_SIZE+12($sp)
2073 .cfi_rel_offset 2, ARG_SLOT_SIZE+12
2074 sw $v1, ARG_SLOT_SIZE+8($sp)
2075 .cfi_rel_offset 3, ARG_SLOT_SIZE+8
2076 s.d $f0, ARG_SLOT_SIZE($sp)
Duane Sande34652f2014-11-04 11:09:36 -08002077 s.d $f0, 16($sp) # pass fpr result
Ian Rogers62d6c772013-02-27 08:32:07 -08002078 move $a2, $v0 # pass gpr result
2079 move $a3, $v1
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002080 addiu $a1, $sp, ARG_SLOT_SIZE+16 # pass $sp (remove arg slots and temp storage)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002081 la $t9, artInstrumentationMethodExitFromCode
2082 jalr $t9 # (Thread*, SP, gpr_res, fpr_res)
jeffhao12051ea2013-01-10 11:24:31 -08002083 move $a0, rSELF # pass Thread::Current
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002084 move $t9, $v0 # set aside returned link register
jeffhao12051ea2013-01-10 11:24:31 -08002085 move $ra, $v1 # set link register for deoptimization
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002086 lw $v0, ARG_SLOT_SIZE+12($sp) # restore return values
2087 lw $v1, ARG_SLOT_SIZE+8($sp)
2088 l.d $f0, ARG_SLOT_SIZE($sp)
2089 jalr $zero, $t9 # return
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002090 addiu $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_SAVE_REFS_ONLY+16 # restore stack
2091 .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_SAVE_REFS_ONLY+16)
Ian Rogers468532e2013-08-05 10:56:33 -07002092END art_quick_instrumentation_exit
buzbee5bc5a7b2012-03-07 15:52:59 -08002093
jeffhao12051ea2013-01-10 11:24:31 -08002094 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08002095 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2096 * will long jump to the upcall with a special exception of -1.
jeffhao12051ea2013-01-10 11:24:31 -08002097 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002098 .extern artDeoptimize
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002099ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002100 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002101 la $t9, artDeoptimize
2102 jalr $t9 # artDeoptimize(Thread*)
jeffhao12051ea2013-01-10 11:24:31 -08002103 # Returns caller method's frame size.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002104 move $a0, rSELF # pass Thread::current
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002105END art_quick_deoptimize
jeffhao12051ea2013-01-10 11:24:31 -08002106
buzbee5bc5a7b2012-03-07 15:52:59 -08002107 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00002108 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2109 * will long jump to the upcall with a special exception of -1.
2110 */
2111 .extern artDeoptimizeFromCompiledCode
2112ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002113 SETUP_SAVE_EVERYTHING_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002114 la $t9, artDeoptimizeFromCompiledCode
2115 jalr $t9 # artDeoptimizeFromCompiledCode(Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002116 # Returns caller method's frame size.
2117 move $a0, rSELF # pass Thread::current
2118END art_quick_deoptimize_from_compiled_code
2119
2120 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08002121 * Long integer shift. This is different from the generic 32/64-bit
2122 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2123 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2124 * 6 bits.
2125 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002126 * $a0: low word
2127 * $a1: high word
2128 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002129 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002130ENTRY_NO_GP art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002131 /* shl-long vAA, vBB, vCC */
jeffhao7fbee072012-08-24 17:56:54 -07002132 sll $v0, $a0, $a2 # rlo<- alo << (shift&31)
2133 not $v1, $a2 # rhi<- 31-shift (shift is 5b)
2134 srl $a0, 1
2135 srl $a0, $v1 # alo<- alo >> (32-(shift&31))
2136 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002137 andi $a2, 0x20 # shift< shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002138 beqz $a2, 1f
2139 or $v1, $a0 # rhi<- rhi | alo
2140
2141 move $v1, $v0 # rhi<- rlo (if shift&0x20)
2142 move $v0, $zero # rlo<- 0 (if shift&0x20)
2143
Andreas Gampe8d365912015-01-13 11:32:32 -080021441: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002145 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002146END art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002147
buzbee5bc5a7b2012-03-07 15:52:59 -08002148 /*
2149 * Long integer shift. This is different from the generic 32/64-bit
2150 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2151 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2152 * 6 bits.
2153 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002154 * $a0: low word
2155 * $a1: high word
2156 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002157 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002158ENTRY_NO_GP art_quick_shr_long
jeffhao7fbee072012-08-24 17:56:54 -07002159 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
2160 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
2161 sra $a3, $a1, 31 # $a3<- sign(ah)
2162 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2163 sll $a1, 1
2164 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002165 andi $a2, 0x20 # shift & 0x20
Douglas Leung475cfd82014-12-16 20:15:41 -08002166 beqz $a2, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002167 or $v0, $a1 # rlo<- rlo | ahi
2168
2169 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2170 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20)
2171
Andreas Gampe8d365912015-01-13 11:32:32 -080021721: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002173 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002174END art_quick_shr_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002175
buzbee5bc5a7b2012-03-07 15:52:59 -08002176 /*
2177 * Long integer shift. This is different from the generic 32/64-bit
2178 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2179 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2180 * 6 bits.
2181 * On entry:
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002182 * $a0: low word
2183 * $a1: high word
2184 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002185 */
2186 /* ushr-long vAA, vBB, vCC */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002187ENTRY_NO_GP art_quick_ushr_long
jeffhaofc6a30e2012-10-18 18:24:15 -07002188 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002189 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002190 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2191 sll $a1, 1
2192 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002193 andi $a2, 0x20 # shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002194 beqz $a2, 1f
2195 or $v0, $a1 # rlo<- rlo | ahi
2196
2197 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2198 move $v1, $zero # rhi<- 0 (if shift&0x20)
2199
Andreas Gampe8d365912015-01-13 11:32:32 -080022001: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002201 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002202END art_quick_ushr_long
jeffhao7fbee072012-08-24 17:56:54 -07002203
Chris Larsencf283da2016-01-19 16:45:35 -08002204/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2205ENTRY_NO_GP art_quick_indexof
2206/* $a0 holds address of "this" */
2207/* $a1 holds "ch" */
2208/* $a2 holds "fromIndex" */
2209 lw $t0, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002210 slt $t1, $a2, $zero # if fromIndex < 0
Chris Larsencf283da2016-01-19 16:45:35 -08002211#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002212 seleqz $a2, $a2, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08002213#else
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002214 movn $a2, $zero, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08002215#endif
2216 subu $t0, $t0, $a2 # this.length() - fromIndex
2217 blez $t0, 6f # if this.length()-fromIndex <= 0
2218 li $v0, -1 # return -1;
2219
2220 sll $v0, $a2, 1 # $a0 += $a2 * 2
2221 addu $a0, $a0, $v0 # " " " " "
2222 move $v0, $a2 # Set i to fromIndex.
2223
22241:
2225 lhu $t3, MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2226 beq $t3, $a1, 6f # return i;
2227 addu $a0, $a0, 2 # i++
2228 subu $t0, $t0, 1 # this.length() - i
2229 bnez $t0, 1b # while this.length() - i > 0
2230 addu $v0, $v0, 1 # i++
2231
2232 li $v0, -1 # if this.length() - i <= 0
2233 # return -1;
2234
22356:
2236 j $ra
2237 nop
2238END art_quick_indexof
2239
Chris Larsencf283da2016-01-19 16:45:35 -08002240/* java.lang.String.compareTo(String anotherString) */
2241ENTRY_NO_GP art_quick_string_compareto
2242/* $a0 holds address of "this" */
2243/* $a1 holds address of "anotherString" */
2244 beq $a0, $a1, 9f # this and anotherString are the same object
2245 move $v0, $zero
2246
2247 lw $a2, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2248 lw $a3, MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
2249 MINu $t2, $a2, $a3
2250# $t2 now holds min(this.length(),anotherString.length())
2251
2252 beqz $t2, 9f # while min(this.length(),anotherString.length())-i != 0
2253 subu $v0, $a2, $a3 # if $t2==0 return
2254 # (this.length() - anotherString.length())
22551:
2256 lhu $t0, MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2257 lhu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2258 bne $t0, $t1, 9f # if this.charAt(i) != anotherString.charAt(i)
2259 subu $v0, $t0, $t1 # return (this.charAt(i) - anotherString.charAt(i))
2260 addiu $a0, $a0, 2 # point at this.charAt(i++)
2261 subu $t2, $t2, 1 # new value of
2262 # min(this.length(),anotherString.length())-i
2263 bnez $t2, 1b
2264 addiu $a1, $a1, 2 # point at anotherString.charAt(i++)
2265 subu $v0, $a2, $a3
2266
22679:
2268 j $ra
2269 nop
2270END art_quick_string_compareto