blob: c3c188233b3183a7140ebff0e01cce71347c4c76 [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
Vladimir Marko804b03f2016-09-14 16:26:36 +0100713ENTRY_NO_GP art_quick_throw_null_pointer_exception
714 // Note that setting up $gp does not rely on $t9 here, so branching here directly is OK,
715 // even after clobbering any registers we don't need to preserve, such as $gp or $t0.
716 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700717 la $t9, artThrowNullPointerExceptionFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800718 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700719 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700720END art_quick_throw_null_pointer_exception
buzbee5bc5a7b2012-03-07 15:52:59 -0800721
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100722
723 /*
724 * Call installed by a signal handler to create and deliver a NullPointerException.
725 */
726 .extern artThrowNullPointerExceptionFromSignal
Vladimir Marko3b7537b2016-09-13 11:56:01 +0000727ENTRY_NO_GP_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, FRAME_SIZE_SAVE_EVERYTHING
728 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
729 # Retrieve the fault address from the padding where the signal handler stores it.
730 lw $a0, (ARG_SLOT_SIZE + __SIZEOF_POINTER__)($sp)
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100731 la $t9, artThrowNullPointerExceptionFromSignal
732 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uintptr_t, Thread*)
733 move $a1, rSELF # pass Thread::Current
734END art_quick_throw_null_pointer_exception_from_signal
735
buzbee5bc5a7b2012-03-07 15:52:59 -0800736 /*
737 * Called by managed code to create and deliver an ArithmeticException
738 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800739 .extern artThrowDivZeroFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100740ENTRY_NO_GP art_quick_throw_div_zero
741 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700742 la $t9, artThrowDivZeroFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800743 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700744 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700745END art_quick_throw_div_zero
buzbee5bc5a7b2012-03-07 15:52:59 -0800746
buzbee5bc5a7b2012-03-07 15:52:59 -0800747 /*
748 * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException
749 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800750 .extern artThrowArrayBoundsFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100751ENTRY_NO_GP art_quick_throw_array_bounds
752 // Note that setting up $gp does not rely on $t9 here, so branching here directly is OK,
753 // even after clobbering any registers we don't need to preserve, such as $gp or $t0.
754 SETUP_SAVE_EVERYTHING_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700755 la $t9, artThrowArrayBoundsFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800756 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700757 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700758END art_quick_throw_array_bounds
buzbee5bc5a7b2012-03-07 15:52:59 -0800759
Ian Rogers57b86d42012-03-27 16:05:41 -0700760 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100761 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
762 * as if thrown from a call to String.charAt().
763 */
764 .extern artThrowStringBoundsFromCode
Vladimir Marko804b03f2016-09-14 16:26:36 +0100765ENTRY_NO_GP art_quick_throw_string_bounds
766 SETUP_SAVE_EVERYTHING_FRAME
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100767 la $t9, artThrowStringBoundsFromCode
768 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
769 move $a2, rSELF # pass Thread::Current
770END art_quick_throw_string_bounds
771
772 /*
Ian Rogers57b86d42012-03-27 16:05:41 -0700773 * Called by managed code to create and deliver a StackOverflowError.
774 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800775 .extern artThrowStackOverflowFromCode
Ian Rogers468532e2013-08-05 10:56:33 -0700776ENTRY art_quick_throw_stack_overflow
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100777 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
jeffhao8161c032012-10-31 15:50:00 -0700778 la $t9, artThrowStackOverflowFromCode
Andreas Gampe8d365912015-01-13 11:32:32 -0800779 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700780 move $a0, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -0700781END art_quick_throw_stack_overflow
buzbee5bc5a7b2012-03-07 15:52:59 -0800782
Ian Rogers57b86d42012-03-27 16:05:41 -0700783 /*
buzbee5bc5a7b2012-03-07 15:52:59 -0800784 * All generated callsites for interface invokes and invocation slow paths will load arguments
jeffhao7fbee072012-08-24 17:56:54 -0700785 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100786 * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper.
jeffhao7fbee072012-08-24 17:56:54 -0700787 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800788 *
jeffhao7fbee072012-08-24 17:56:54 -0700789 * The helper will attempt to locate the target and return a 64-bit result in $v0/$v1 consisting
790 * of the target Method* in $v0 and method->code_ in $v1.
buzbee5bc5a7b2012-03-07 15:52:59 -0800791 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700792 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
buzbee5bc5a7b2012-03-07 15:52:59 -0800793 * thread and we branch to another stub to deliver it.
794 *
795 * On success this wrapper will restore arguments and *jump* to the target, leaving the lr
796 * pointing back to the original caller.
797 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700798.macro INVOKE_TRAMPOLINE_BODY cxx_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800799 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100800 SETUP_SAVE_REFS_AND_ARGS_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100801 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100802 la $t9, \cxx_name
803 jalr $t9 # (method_idx, this, Thread*, $sp)
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100804 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
805 move $a0, $v0 # save target Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100806 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhaofa147e22012-10-12 17:03:32 -0700807 beqz $v0, 1f
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100808 move $t9, $v1 # save $v0->code_
Andreas Gampe8d365912015-01-13 11:32:32 -0800809 jalr $zero, $t9
buzbee5bc5a7b2012-03-07 15:52:59 -0800810 nop
8111:
812 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700813.endm
814.macro INVOKE_TRAMPOLINE c_name, cxx_name
815ENTRY \c_name
816 INVOKE_TRAMPOLINE_BODY \cxx_name
Jeff Haod4c3f7d2013-02-14 14:14:44 -0800817END \c_name
buzbee5bc5a7b2012-03-07 15:52:59 -0800818.endm
819
Logan Chien8dbb7082013-01-25 20:31:17 +0800820INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800821
Logan Chien8dbb7082013-01-25 20:31:17 +0800822INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
823INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
824INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
825INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
buzbee5bc5a7b2012-03-07 15:52:59 -0800826
Goran Jakovljevicff734982015-08-24 12:58:55 +0000827.macro LOAD_WORD_TO_REG reg, next_arg, index, label
828 lw $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
829 b \label
830 addiu $\index, 1
831.endm
832
833.macro LOAD_LONG_TO_REG reg1, reg2, next_arg, index, label
834 lw $\reg1, -8($\next_arg) # next_arg points to argument after the current one (offset is 8)
835 lw $\reg2, -4($\next_arg)
836 b \label
837 li $\index, 4 # long can be loaded only to a2_a3 pair so index will be always 4
838.endm
839
840.macro LOAD_FLOAT_TO_REG reg, next_arg, index, label
841 lwc1 $\reg, -4($\next_arg) # next_arg points to argument after the current one (offset is 4)
842 b \label
843 addiu $\index, 1
844.endm
845
846.macro LOAD_DOUBLE_TO_REG reg1, reg2, next_arg, index, tmp, label
847 LDu $\reg1, $\reg2, -8, $\next_arg, $\tmp # next_arg points to argument after the current one
848 # (offset is 8)
849 b \label
850 addiu $\index, 1
851.endm
852
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100853#define SPILL_SIZE 32
854
Jeff Hao79fe5392013-04-24 18:41:58 -0700855 /*
Ian Rogersef7d42f2014-01-06 12:55:46 -0800856 * Invocation stub for quick code.
Jeff Hao5d917302013-02-27 17:57:33 -0800857 * On entry:
858 * a0 = method pointer
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700859 * a1 = argument array or null for no argument methods
Jeff Hao5d917302013-02-27 17:57:33 -0800860 * a2 = size of argument array in bytes
861 * a3 = (managed) thread pointer
Jeff Hao6474d192013-03-26 14:08:09 -0700862 * [sp + 16] = JValue* result
Ian Rogers0177e532014-02-11 16:30:46 -0800863 * [sp + 20] = shorty
Jeff Hao5d917302013-02-27 17:57:33 -0800864 */
865ENTRY art_quick_invoke_stub
Jeff Hao5d917302013-02-27 17:57:33 -0800866 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100867 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
868 .cfi_adjust_cfa_offset SPILL_SIZE
869 sw $gp, 16($sp)
Jeff Hao5d917302013-02-27 17:57:33 -0800870 sw $ra, 12($sp)
871 .cfi_rel_offset 31, 12
872 sw $fp, 8($sp)
873 .cfi_rel_offset 30, 8
874 sw $s1, 4($sp)
875 .cfi_rel_offset 17, 4
876 sw $s0, 0($sp)
877 .cfi_rel_offset 16, 0
878 move $fp, $sp # save sp in fp
879 .cfi_def_cfa_register 30
880 move $s1, $a3 # move managed thread pointer into s1
881 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
Goran Jakovljevicff734982015-08-24 12:58:55 +0000882 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
Douglas Leung735b8552014-10-31 12:21:40 -0700883 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
Goran Jakovljevicff734982015-08-24 12:58:55 +0000884 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
885 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
886 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100887 la $t9, memcpy
888 jalr $t9 # (dest, src, bytes)
Jeff Hao5d917302013-02-27 17:57:33 -0800889 addiu $sp, $sp, -16 # make space for argument slots for memcpy
890 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100891 lw $gp, 16($fp) # restore $gp
892 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000893 lw $a1, 4($sp) # a1 = this*
894 addiu $t0, $sp, 8 # t0 = pointer to the current argument (skip ArtMethod* and this*)
895 li $t3, 2 # t3 = gpr_index = 2 (skip A0 and A1)
896 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100897 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
898 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000899 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
900loop:
901 lbu $t2, 0($t1) # t2 = shorty[i]
902 beqz $t2, loopEnd # finish getting args when shorty[i] == '\0'
903 addiu $t1, 1
904
905 li $t9, 'J' # put char 'J' into t9
906 beq $t9, $t2, isLong # branch if result type char == 'J'
907 li $t9, 'D' # put char 'D' into t9
908 beq $t9, $t2, isDouble # branch if result type char == 'D'
909 li $t9, 'F' # put char 'F' into t9
910 beq $t9, $t2, isSingle # branch if result type char == 'F'
911 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
912 # for both, int and single)
913
914 li $t5, 2 # skip a0 and a1 (ArtMethod* and this*)
915 bne $t5, $t3, 1f # if (gpr_index == 2)
916 addiu $t5, 1
917 LOAD_WORD_TO_REG a2, t0, t3, loop # a2 = current argument, gpr_index++
9181: bne $t5, $t3, loop # else if (gpr_index == 3)
919 nop
920 LOAD_WORD_TO_REG a3, t0, t3, loop # a3 = current argument, gpr_index++
921
922isLong:
923 addiu $t0, 8 # next_arg = curr_arg + 8
924 slti $t5, $t3, 3
925 beqz $t5, 2f # if (gpr_index < 3)
926 nop
927 LOAD_LONG_TO_REG a2, a3, t0, t3, loop # a2_a3 = curr_arg, gpr_index = 4
9282: b loop # else
929 li $t3, 4 # gpr_index = 4
930
931isDouble:
932 addiu $t0, 8 # next_arg = curr_arg + 8
933 li $t5, 0
934 bne $t5, $t4, 3f # if (fp_index == 0)
935 addiu $t5, 1
936 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loop # f12_f13 = curr_arg, fp_index++
9373: bne $t5, $t4, loop # else if (fp_index == 1)
938 nop
939 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loop # f14_f15 = curr_arg, fp_index++
940
941isSingle:
942 li $t5, 0
943 bne $t5, $t4, 4f # if (fp_index == 0)
944 addiu $t5, 1
945 LOAD_FLOAT_TO_REG f12, t0, t4, loop # f12 = curr_arg, fp_index++
9464: bne $t5, $t4, loop # else if (fp_index == 1)
947 nop
948 LOAD_FLOAT_TO_REG f14, t0, t4, loop # f14 = curr_arg, fp_index++
949
950loopEnd:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700951 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
Jeff Hao5d917302013-02-27 17:57:33 -0800952 jalr $t9 # call the method
Goran Jakovljevicff734982015-08-24 12:58:55 +0000953 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
Jeff Hao5d917302013-02-27 17:57:33 -0800954 move $sp, $fp # restore the stack
955 lw $s0, 0($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800956 .cfi_restore 16
Jeff Hao5d917302013-02-27 17:57:33 -0800957 lw $s1, 4($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800958 .cfi_restore 17
Jeff Hao5d917302013-02-27 17:57:33 -0800959 lw $fp, 8($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800960 .cfi_restore 30
Jeff Hao5d917302013-02-27 17:57:33 -0800961 lw $ra, 12($sp)
Dave Allisonbbb32c22013-11-05 18:25:18 -0800962 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100963 addiu $sp, $sp, SPILL_SIZE
964 .cfi_adjust_cfa_offset -SPILL_SIZE
Jeff Hao5d917302013-02-27 17:57:33 -0800965 lw $t0, 16($sp) # get result pointer
Ian Rogers0177e532014-02-11 16:30:46 -0800966 lw $t1, 20($sp) # get shorty
967 lb $t1, 0($t1) # get result type char
Goran Jakovljevicff734982015-08-24 12:58:55 +0000968 li $t2, 'D' # put char 'D' into t2
969 beq $t1, $t2, 5f # branch if result type char == 'D'
970 li $t3, 'F' # put char 'F' into t3
971 beq $t1, $t3, 5f # branch if result type char == 'F'
Jeff Hao5d917302013-02-27 17:57:33 -0800972 sw $v0, 0($t0) # store the result
Andreas Gampe8d365912015-01-13 11:32:32 -0800973 jalr $zero, $ra
Jeff Hao5d917302013-02-27 17:57:33 -0800974 sw $v1, 4($t0) # store the other half of the result
Goran Jakovljevicff734982015-08-24 12:58:55 +00009755:
Duane Sande34652f2014-11-04 11:09:36 -0800976 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
Andreas Gampe8d365912015-01-13 11:32:32 -0800977 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -0800978 nop
Jeff Hao5d917302013-02-27 17:57:33 -0800979END art_quick_invoke_stub
980
981 /*
Goran Jakovljevicff734982015-08-24 12:58:55 +0000982 * Invocation static stub for quick code.
983 * On entry:
984 * a0 = method pointer
985 * a1 = argument array or null for no argument methods
986 * a2 = size of argument array in bytes
987 * a3 = (managed) thread pointer
988 * [sp + 16] = JValue* result
989 * [sp + 20] = shorty
990 */
991ENTRY art_quick_invoke_static_stub
992 sw $a0, 0($sp) # save out a0
Goran Jakovljevic590b1362016-03-21 14:24:43 +0100993 addiu $sp, $sp, -SPILL_SIZE # spill s0, s1, fp, ra and gp
994 .cfi_adjust_cfa_offset SPILL_SIZE
995 sw $gp, 16($sp)
Goran Jakovljevicff734982015-08-24 12:58:55 +0000996 sw $ra, 12($sp)
997 .cfi_rel_offset 31, 12
998 sw $fp, 8($sp)
999 .cfi_rel_offset 30, 8
1000 sw $s1, 4($sp)
1001 .cfi_rel_offset 17, 4
1002 sw $s0, 0($sp)
1003 .cfi_rel_offset 16, 0
1004 move $fp, $sp # save sp in fp
1005 .cfi_def_cfa_register 30
1006 move $s1, $a3 # move managed thread pointer into s1
1007 addiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset s0 to suspend check interval
1008 addiu $t0, $a2, 4 # create space for ArtMethod* in frame.
1009 subu $t0, $sp, $t0 # reserve & align *stack* to 16 bytes:
1010 srl $t0, $t0, 4 # native calling convention only aligns to 8B,
1011 sll $sp, $t0, 4 # so we have to ensure ART 16B alignment ourselves.
1012 addiu $a0, $sp, 4 # pass stack pointer + ArtMethod* as dest for memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001013 la $t9, memcpy
1014 jalr $t9 # (dest, src, bytes)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001015 addiu $sp, $sp, -16 # make space for argument slots for memcpy
1016 addiu $sp, $sp, 16 # restore stack after memcpy
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001017 lw $gp, 16($fp) # restore $gp
1018 lw $a0, SPILL_SIZE($fp) # restore ArtMethod*
Goran Jakovljevicff734982015-08-24 12:58:55 +00001019 addiu $t0, $sp, 4 # t0 = pointer to the current argument (skip ArtMethod*)
1020 li $t3, 1 # t3 = gpr_index = 1 (skip A0)
1021 move $t4, $zero # t4 = fp_index = 0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001022 lw $t1, 20 + SPILL_SIZE($fp) # get shorty (20 is offset from the $sp on entry + SPILL_SIZE
1023 # as the $fp is SPILL_SIZE bytes below the $sp on entry)
Goran Jakovljevicff734982015-08-24 12:58:55 +00001024 addiu $t1, 1 # t1 = shorty + 1 (skip 1 for return type)
1025loopS:
1026 lbu $t2, 0($t1) # t2 = shorty[i]
1027 beqz $t2, loopEndS # finish getting args when shorty[i] == '\0'
1028 addiu $t1, 1
1029
1030 li $t9, 'J' # put char 'J' into t9
1031 beq $t9, $t2, isLongS # branch if result type char == 'J'
1032 li $t9, 'D' # put char 'D' into t9
1033 beq $t9, $t2, isDoubleS # branch if result type char == 'D'
1034 li $t9, 'F' # put char 'F' into t9
1035 beq $t9, $t2, isSingleS # branch if result type char == 'F'
1036 addiu $t0, 4 # next_arg = curr_arg + 4 (in branch delay slot,
1037 # for both, int and single)
1038
1039 li $t5, 1 # skip a0 (ArtMethod*)
1040 bne $t5, $t3, 1f # if (gpr_index == 1)
1041 addiu $t5, 1
1042 LOAD_WORD_TO_REG a1, t0, t3, loopS # a1 = current argument, gpr_index++
10431: bne $t5, $t3, 2f # else if (gpr_index == 2)
1044 addiu $t5, 1
1045 LOAD_WORD_TO_REG a2, t0, t3, loopS # a2 = current argument, gpr_index++
10462: bne $t5, $t3, loopS # else if (gpr_index == 3)
1047 nop
1048 LOAD_WORD_TO_REG a3, t0, t3, loopS # a3 = current argument, gpr_index++
1049
1050isLongS:
1051 addiu $t0, 8 # next_arg = curr_arg + 8
1052 slti $t5, $t3, 3
1053 beqz $t5, 3f # if (gpr_index < 3)
1054 nop
1055 LOAD_LONG_TO_REG a2, a3, t0, t3, loopS # a2_a3 = curr_arg, gpr_index = 4
10563: b loopS # else
1057 li $t3, 4 # gpr_index = 4
1058
1059isDoubleS:
1060 addiu $t0, 8 # next_arg = curr_arg + 8
1061 li $t5, 0
1062 bne $t5, $t4, 4f # if (fp_index == 0)
1063 addiu $t5, 1
1064 LOAD_DOUBLE_TO_REG f12, f13, t0, t4, t9, loopS # f12_f13 = curr_arg, fp_index++
10654: bne $t5, $t4, loopS # else if (fp_index == 1)
1066 nop
1067 LOAD_DOUBLE_TO_REG f14, f15, t0, t4, t9, loopS # f14_f15 = curr_arg, fp_index++
1068
1069isSingleS:
1070 li $t5, 0
1071 bne $t5, $t4, 5f # if (fp_index == 0)
1072 addiu $t5, 1
1073 LOAD_FLOAT_TO_REG f12, t0, t4, loopS # f12 = curr_arg, fp_index++
10745: bne $t5, $t4, loopS # else if (fp_index == 1)
1075 nop
1076 LOAD_FLOAT_TO_REG f14, t0, t4, loopS # f14 = curr_arg, fp_index++
1077
1078loopEndS:
1079 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0) # get pointer to the code
1080 jalr $t9 # call the method
1081 sw $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1082 move $sp, $fp # restore the stack
1083 lw $s0, 0($sp)
1084 .cfi_restore 16
1085 lw $s1, 4($sp)
1086 .cfi_restore 17
1087 lw $fp, 8($sp)
1088 .cfi_restore 30
1089 lw $ra, 12($sp)
1090 .cfi_restore 31
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001091 addiu $sp, $sp, SPILL_SIZE
1092 .cfi_adjust_cfa_offset -SPILL_SIZE
Goran Jakovljevicff734982015-08-24 12:58:55 +00001093 lw $t0, 16($sp) # get result pointer
1094 lw $t1, 20($sp) # get shorty
1095 lb $t1, 0($t1) # get result type char
1096 li $t2, 'D' # put char 'D' into t2
1097 beq $t1, $t2, 6f # branch if result type char == 'D'
1098 li $t3, 'F' # put char 'F' into t3
1099 beq $t1, $t3, 6f # branch if result type char == 'F'
1100 sw $v0, 0($t0) # store the result
1101 jalr $zero, $ra
1102 sw $v1, 4($t0) # store the other half of the result
11036:
1104 SDu $f0, $f1, 0, $t0, $t1 # store floating point result
1105 jalr $zero, $ra
1106 nop
1107END art_quick_invoke_static_stub
1108
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001109#undef SPILL_SIZE
1110
Goran Jakovljevicff734982015-08-24 12:58:55 +00001111 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08001112 * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on
1113 * failure.
1114 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001115 .extern artHandleFillArrayDataFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001116ENTRY art_quick_handle_fill_data
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001117 lw $a2, 0($sp) # pass referrer's Method*
1118 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001119 la $t9, artHandleFillArrayDataFromCode
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001120 jalr $t9 # (payload offset, Array*, method, Thread*)
1121 move $a3, rSELF # pass Thread::Current
jeffhaofc6a30e2012-10-18 18:24:15 -07001122 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001123END art_quick_handle_fill_data
buzbee5bc5a7b2012-03-07 15:52:59 -08001124
buzbee5bc5a7b2012-03-07 15:52:59 -08001125 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001126 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
buzbee5bc5a7b2012-03-07 15:52:59 -08001127 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001128 .extern artLockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001129ENTRY art_quick_lock_object
Vladimir Marko804b03f2016-09-14 16:26:36 +01001130 beqz $a0, art_quick_throw_null_pointer_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001131 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001132 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001133 la $t9, artLockObjectFromCode
1134 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001135 move $a1, rSELF # pass Thread::Current
Ian Rogers6bcd1632013-10-08 18:50:47 -07001136 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001137END art_quick_lock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001138
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001139ENTRY art_quick_lock_object_no_inline
Vladimir Marko804b03f2016-09-14 16:26:36 +01001140 beqz $a0, art_quick_throw_null_pointer_exception
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001141 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001142 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001143 la $t9, artLockObjectFromCode
1144 jalr $t9 # (Object* obj, Thread*)
1145 move $a1, rSELF # pass Thread::Current
1146 RETURN_IF_ZERO
1147END art_quick_lock_object_no_inline
1148
buzbee5bc5a7b2012-03-07 15:52:59 -08001149 /*
1150 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1151 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001152 .extern artUnlockObjectFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001153ENTRY art_quick_unlock_object
Vladimir Marko804b03f2016-09-14 16:26:36 +01001154 beqz $a0, art_quick_throw_null_pointer_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001155 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001156 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001157 la $t9, artUnlockObjectFromCode
1158 jalr $t9 # (Object* obj, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001159 move $a1, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001160 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001161END art_quick_unlock_object
buzbee5bc5a7b2012-03-07 15:52:59 -08001162
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001163ENTRY art_quick_unlock_object_no_inline
Vladimir Marko804b03f2016-09-14 16:26:36 +01001164 beqz $a0, art_quick_throw_null_pointer_exception
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001165 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001166 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001167 la $t9, artUnlockObjectFromCode
1168 jalr $t9 # (Object* obj, Thread*)
1169 move $a1, rSELF # pass Thread::Current
1170 RETURN_IF_ZERO
1171END art_quick_unlock_object_no_inline
1172
buzbee5bc5a7b2012-03-07 15:52:59 -08001173 /*
1174 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1175 */
Ian Rogersa9a82542013-10-04 11:17:26 -07001176 .extern artThrowClassCastException
Ian Rogers468532e2013-08-05 10:56:33 -07001177ENTRY art_quick_check_cast
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001178 addiu $sp, $sp, -32
1179 .cfi_adjust_cfa_offset 32
1180 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001181 sw $ra, 12($sp)
1182 .cfi_rel_offset 31, 12
1183 sw $t9, 8($sp)
1184 sw $a1, 4($sp)
1185 sw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001186 la $t9, artIsAssignableFromCode
1187 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07001188 addiu $sp, $sp, -16 # reserve argument slots on the stack
1189 addiu $sp, $sp, 16
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001190 lw $gp, 16($sp)
Ian Rogers86bcdc22014-02-21 22:06:38 -08001191 beqz $v0, .Lthrow_class_cast_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001192 lw $ra, 12($sp)
Andreas Gampe8d365912015-01-13 11:32:32 -08001193 jalr $zero, $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001194 addiu $sp, $sp, 32
1195 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001196.Lthrow_class_cast_exception:
Ian Rogersa9a82542013-10-04 11:17:26 -07001197 lw $t9, 8($sp)
1198 lw $a1, 4($sp)
1199 lw $a0, 0($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001200 addiu $sp, $sp, 32
1201 .cfi_adjust_cfa_offset -32
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001202 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -07001203 la $t9, artThrowClassCastException
Andreas Gampe8d365912015-01-13 11:32:32 -08001204 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001205 move $a2, rSELF # pass Thread::Current
Ian Rogers468532e2013-08-05 10:56:33 -07001206END art_quick_check_cast
buzbee5bc5a7b2012-03-07 15:52:59 -08001207
buzbee5bc5a7b2012-03-07 15:52:59 -08001208 /*
Man Cao1aee9002015-07-14 22:31:42 -07001209 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1210 * nReg is the register number for rReg.
1211 */
1212.macro POP_REG_NE rReg, nReg, offset, rExclude
1213 .ifnc \rReg, \rExclude
1214 lw \rReg, \offset($sp) # restore rReg
1215 .cfi_restore \nReg
1216 .endif
1217.endm
1218
1219 /*
1220 * Macro to insert read barrier, only used in art_quick_aput_obj.
1221 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1222 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1223 */
1224.macro READ_BARRIER rDest, rObj, offset
1225#ifdef USE_READ_BARRIER
1226 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 8 words for 16B alignment.
1227 addiu $sp, $sp, -32
1228 .cfi_adjust_cfa_offset 32
1229 sw $ra, 28($sp)
1230 .cfi_rel_offset 31, 28
1231 sw $t9, 24($sp)
1232 .cfi_rel_offset 25, 24
1233 sw $t1, 20($sp)
1234 .cfi_rel_offset 9, 20
1235 sw $t0, 16($sp)
1236 .cfi_rel_offset 8, 16
1237 sw $a2, 8($sp) # padding slot at offset 12 (padding can be any slot in the 32B)
1238 .cfi_rel_offset 6, 8
1239 sw $a1, 4($sp)
1240 .cfi_rel_offset 5, 4
1241 sw $a0, 0($sp)
1242 .cfi_rel_offset 4, 0
1243
Man Cao63069212015-08-21 15:51:39 -07001244 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001245 .ifnc \rObj, $a1
1246 move $a1, \rObj # pass rObj
1247 .endif
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001248 addiu $a2, $zero, \offset # pass offset
1249 la $t9, artReadBarrierSlow
1250 jalr $t9 # artReadBarrierSlow(ref, rObj, offset)
Man Cao1aee9002015-07-14 22:31:42 -07001251 addiu $sp, $sp, -16 # Use branch delay slot to reserve argument slots on the stack
1252 # before the call to artReadBarrierSlow.
1253 addiu $sp, $sp, 16 # restore stack after call to artReadBarrierSlow
1254 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1255 move \rDest, $v0 # save return value in rDest
1256 # (rDest cannot be v0 in art_quick_aput_obj)
1257
1258 lw $a0, 0($sp) # restore registers except rDest
1259 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1260 .cfi_restore 4
1261 lw $a1, 4($sp)
1262 .cfi_restore 5
1263 lw $a2, 8($sp)
1264 .cfi_restore 6
1265 POP_REG_NE $t0, 8, 16, \rDest
1266 POP_REG_NE $t1, 9, 20, \rDest
1267 lw $t9, 24($sp)
1268 .cfi_restore 25
1269 lw $ra, 28($sp) # restore $ra
1270 .cfi_restore 31
1271 addiu $sp, $sp, 32
1272 .cfi_adjust_cfa_offset -32
1273#else
1274 lw \rDest, \offset(\rObj)
1275 UNPOISON_HEAP_REF \rDest
1276#endif // USE_READ_BARRIER
1277.endm
1278
1279 /*
Ian Rogersa9a82542013-10-04 11:17:26 -07001280 * Entry from managed code for array put operations of objects where the value being stored
1281 * needs to be checked for compatibility.
1282 * a0 = array, a1 = index, a2 = value
buzbee5bc5a7b2012-03-07 15:52:59 -08001283 */
Ian Rogersa9a82542013-10-04 11:17:26 -07001284ENTRY art_quick_aput_obj_with_null_and_bound_check
Ian Rogers86bcdc22014-02-21 22:06:38 -08001285 bnez $a0, .Lart_quick_aput_obj_with_bound_check_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001286 nop
Vladimir Marko804b03f2016-09-14 16:26:36 +01001287 b art_quick_throw_null_pointer_exception
Ian Rogersa9a82542013-10-04 11:17:26 -07001288 nop
1289END art_quick_aput_obj_with_null_and_bound_check
1290
1291ENTRY art_quick_aput_obj_with_bound_check
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001292 lw $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001293 sltu $t1, $a1, $t0
Ian Rogers86bcdc22014-02-21 22:06:38 -08001294 bnez $t1, .Lart_quick_aput_obj_gp_set
Ian Rogersa9a82542013-10-04 11:17:26 -07001295 nop
1296 move $a0, $a1
Vladimir Marko804b03f2016-09-14 16:26:36 +01001297 b art_quick_throw_array_bounds
Ian Rogersa9a82542013-10-04 11:17:26 -07001298 move $a1, $t0
1299END art_quick_aput_obj_with_bound_check
1300
Man Cao1aee9002015-07-14 22:31:42 -07001301#ifdef USE_READ_BARRIER
1302 .extern artReadBarrierSlow
1303#endif
Ian Rogersa9a82542013-10-04 11:17:26 -07001304ENTRY art_quick_aput_obj
Ian Rogers86bcdc22014-02-21 22:06:38 -08001305 beqz $a2, .Ldo_aput_null
Ian Rogersa9a82542013-10-04 11:17:26 -07001306 nop
Man Cao1aee9002015-07-14 22:31:42 -07001307 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1308 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1309 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Ian Rogers86bcdc22014-02-21 22:06:38 -08001310 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
Ian Rogersa9a82542013-10-04 11:17:26 -07001311 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001312.Ldo_aput:
Ian Rogersa9a82542013-10-04 11:17:26 -07001313 sll $a1, $a1, 2
1314 add $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001315 POISON_HEAP_REF $a2
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001316 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Ian Rogersa9a82542013-10-04 11:17:26 -07001317 lw $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1318 srl $t1, $a0, 7
1319 add $t1, $t1, $t0
1320 sb $t0, ($t1)
Andreas Gampe8d365912015-01-13 11:32:32 -08001321 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001322 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001323.Ldo_aput_null:
Ian Rogersa9a82542013-10-04 11:17:26 -07001324 sll $a1, $a1, 2
1325 add $t0, $a0, $a1
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001326 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
Andreas Gampe8d365912015-01-13 11:32:32 -08001327 jalr $zero, $ra
Ian Rogersa9a82542013-10-04 11:17:26 -07001328 nop
Ian Rogers86bcdc22014-02-21 22:06:38 -08001329.Lcheck_assignability:
Ian Rogersa9a82542013-10-04 11:17:26 -07001330 addiu $sp, $sp, -32
1331 .cfi_adjust_cfa_offset 32
1332 sw $ra, 28($sp)
1333 .cfi_rel_offset 31, 28
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001334 sw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001335 sw $t9, 12($sp)
1336 sw $a2, 8($sp)
1337 sw $a1, 4($sp)
1338 sw $a0, 0($sp)
1339 move $a1, $t1
1340 move $a0, $t0
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001341 la $t9, artIsAssignableFromCode
1342 jalr $t9 # (Class*, Class*)
1343 addiu $sp, $sp, -16 # reserve argument slots on the stack
1344 addiu $sp, $sp, 16
Ian Rogersa9a82542013-10-04 11:17:26 -07001345 lw $ra, 28($sp)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001346 lw $gp, 16($sp)
Ian Rogersa9a82542013-10-04 11:17:26 -07001347 lw $t9, 12($sp)
1348 lw $a2, 8($sp)
1349 lw $a1, 4($sp)
1350 lw $a0, 0($sp)
Duane Sande34652f2014-11-04 11:09:36 -08001351 addiu $sp, 32
Ian Rogersa9a82542013-10-04 11:17:26 -07001352 .cfi_adjust_cfa_offset -32
Ian Rogers86bcdc22014-02-21 22:06:38 -08001353 bnez $v0, .Ldo_aput
Ian Rogersa9a82542013-10-04 11:17:26 -07001354 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001355 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Ian Rogersa9a82542013-10-04 11:17:26 -07001356 move $a1, $a2
Ian Rogersa9a82542013-10-04 11:17:26 -07001357 la $t9, artThrowArrayStoreException
Andreas Gampe8d365912015-01-13 11:32:32 -08001358 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001359 move $a2, rSELF # pass Thread::Current
Ian Rogersa9a82542013-10-04 11:17:26 -07001360END art_quick_aput_obj
buzbee5bc5a7b2012-03-07 15:52:59 -08001361
buzbee5bc5a7b2012-03-07 15:52:59 -08001362 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001363 * Called by managed code to resolve a static field and load a boolean primitive value.
1364 */
1365 .extern artGetBooleanStaticFromCode
1366ENTRY art_quick_get_boolean_static
Douglas Leung735b8552014-10-31 12:21:40 -07001367 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001368 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001369 la $t9, artGetBooleanStaticFromCode
1370 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001371 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001372 RETURN_IF_NO_EXCEPTION
1373END art_quick_get_boolean_static
1374 /*
1375 * Called by managed code to resolve a static field and load a byte primitive value.
1376 */
1377 .extern artGetByteStaticFromCode
1378ENTRY art_quick_get_byte_static
Douglas Leung735b8552014-10-31 12:21:40 -07001379 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001380 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001381 la $t9, artGetByteStaticFromCode
1382 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001383 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001384 RETURN_IF_NO_EXCEPTION
1385END art_quick_get_byte_static
1386
1387 /*
1388 * Called by managed code to resolve a static field and load a char primitive value.
1389 */
1390 .extern artGetCharStaticFromCode
1391ENTRY art_quick_get_char_static
Douglas Leung735b8552014-10-31 12:21:40 -07001392 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001393 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001394 la $t9, artGetCharStaticFromCode
1395 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001396 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001397 RETURN_IF_NO_EXCEPTION
1398END art_quick_get_char_static
1399 /*
1400 * Called by managed code to resolve a static field and load a short primitive value.
1401 */
1402 .extern artGetShortStaticFromCode
1403ENTRY art_quick_get_short_static
Douglas Leung735b8552014-10-31 12:21:40 -07001404 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001405 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001406 la $t9, artGetShortStaticFromCode
1407 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001408 move $a2, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001409 RETURN_IF_NO_EXCEPTION
1410END art_quick_get_short_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001411
buzbee5bc5a7b2012-03-07 15:52:59 -08001412 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001413 * Called by managed code to resolve a static field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001414 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001415 .extern artGet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001416ENTRY art_quick_get32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001417 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001418 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001419 la $t9, artGet32StaticFromCode
1420 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001421 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001422 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001423END art_quick_get32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001424
buzbee5bc5a7b2012-03-07 15:52:59 -08001425 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001426 * Called by managed code to resolve a static field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001427 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001428 .extern artGet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001429ENTRY art_quick_get64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001430 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001431 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001432 la $t9, artGet64StaticFromCode
1433 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001434 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001435 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001436END art_quick_get64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001437
buzbee5bc5a7b2012-03-07 15:52:59 -08001438 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001439 * Called by managed code to resolve a static field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001440 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001441 .extern artGetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001442ENTRY art_quick_get_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001443 lw $a1, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001444 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001445 la $t9, artGetObjStaticFromCode
1446 jalr $t9 # (uint32_t field_idx, const Method* referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001447 move $a2, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001448 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001449END art_quick_get_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001450
buzbee5bc5a7b2012-03-07 15:52:59 -08001451 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001452 * Called by managed code to resolve an instance field and load a boolean primitive value.
1453 */
1454 .extern artGetBooleanInstanceFromCode
1455ENTRY art_quick_get_boolean_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001456 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001457 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001458 la $t9, artGetBooleanInstanceFromCode
1459 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001460 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001461 RETURN_IF_NO_EXCEPTION
1462END art_quick_get_boolean_instance
1463 /*
1464 * Called by managed code to resolve an instance field and load a byte primitive value.
1465 */
1466 .extern artGetByteInstanceFromCode
1467ENTRY art_quick_get_byte_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001468 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001469 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001470 la $t9, artGetByteInstanceFromCode
1471 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001472 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001473 RETURN_IF_NO_EXCEPTION
1474END art_quick_get_byte_instance
1475
1476 /*
1477 * Called by managed code to resolve an instance field and load a char primitive value.
1478 */
1479 .extern artGetCharInstanceFromCode
1480ENTRY art_quick_get_char_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001481 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001482 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001483 la $t9, artGetCharInstanceFromCode
1484 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001485 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001486 RETURN_IF_NO_EXCEPTION
1487END art_quick_get_char_instance
1488 /*
1489 * Called by managed code to resolve an instance field and load a short primitive value.
1490 */
1491 .extern artGetShortInstanceFromCode
1492ENTRY art_quick_get_short_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001493 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001494 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001495 la $t9, artGetShortInstanceFromCode
1496 jalr $t9 # (field_idx, Object*, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001497 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001498 RETURN_IF_NO_EXCEPTION
1499END art_quick_get_short_instance
1500
1501 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001502 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001503 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001504 .extern artGet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001505ENTRY art_quick_get32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001506 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001507 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001508 la $t9, artGet32InstanceFromCode
1509 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001510 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001511 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001512END art_quick_get32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001513
buzbee5bc5a7b2012-03-07 15:52:59 -08001514 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001515 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001516 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001517 .extern artGet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001518ENTRY art_quick_get64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001519 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001520 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001521 la $t9, artGet64InstanceFromCode
1522 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001523 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001524 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001525END art_quick_get64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001526
buzbee5bc5a7b2012-03-07 15:52:59 -08001527 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001528 * Called by managed code to resolve an instance field and load an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001529 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001530 .extern artGetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001531ENTRY art_quick_get_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001532 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001533 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001534 la $t9, artGetObjInstanceFromCode
1535 jalr $t9 # (field_idx, Object*, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001536 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001537 RETURN_IF_NO_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07001538END art_quick_get_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001539
buzbee5bc5a7b2012-03-07 15:52:59 -08001540 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001541 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1542 */
1543 .extern artSet8StaticFromCode
1544ENTRY art_quick_set8_static
Douglas Leung735b8552014-10-31 12:21:40 -07001545 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001546 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001547 la $t9, artSet8StaticFromCode
1548 jalr $t9 # (field_idx, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001549 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001550 RETURN_IF_ZERO
1551END art_quick_set8_static
1552
1553 /*
1554 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1555 */
1556 .extern artSet16StaticFromCode
1557ENTRY art_quick_set16_static
Douglas Leung735b8552014-10-31 12:21:40 -07001558 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001559 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001560 la $t9, artSet16StaticFromCode
1561 jalr $t9 # (field_idx, new_val, referrer, Thread*, $sp)
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001562 move $a3, rSELF # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001563 RETURN_IF_ZERO
1564END art_quick_set16_static
1565
1566 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001567 * Called by managed code to resolve a static field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001568 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001569 .extern artSet32StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001570ENTRY art_quick_set32_static
Douglas Leung735b8552014-10-31 12:21:40 -07001571 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001572 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001573 la $t9, artSet32StaticFromCode
1574 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001575 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001576 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001577END art_quick_set32_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001578
buzbee5bc5a7b2012-03-07 15:52:59 -08001579 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001580 * Called by managed code to resolve a static field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001581 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001582 .extern artSet64StaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001583ENTRY art_quick_set64_static
Douglas Leung735b8552014-10-31 12:21:40 -07001584 lw $a1, 0($sp) # pass referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001585 # 64 bit new_val is in a2:a3 pair
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001586 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001587 la $t9, artSet64StaticFromCode
1588 jalr $t9 # (field_idx, referrer, new_val, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001589 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001590 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001591END art_quick_set64_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001592
buzbee5bc5a7b2012-03-07 15:52:59 -08001593 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001594 * Called by managed code to resolve a static field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001595 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001596 .extern artSetObjStaticFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001597ENTRY art_quick_set_obj_static
Douglas Leung735b8552014-10-31 12:21:40 -07001598 lw $a2, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001599 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001600 la $t9, artSetObjStaticFromCode
1601 jalr $t9 # (field_idx, new_val, referrer, Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001602 move $a3, rSELF # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001603 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001604END art_quick_set_obj_static
buzbee5bc5a7b2012-03-07 15:52:59 -08001605
buzbee5bc5a7b2012-03-07 15:52:59 -08001606 /*
Fred Shih37f05ef2014-07-16 18:38:08 -07001607 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1608 */
1609 .extern artSet8InstanceFromCode
1610ENTRY art_quick_set8_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001611 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001612 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001613 la $t9, artSet8InstanceFromCode
1614 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001615 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001616 RETURN_IF_ZERO
1617END art_quick_set8_instance
1618
1619 /*
1620 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1621 */
1622 .extern artSet16InstanceFromCode
1623ENTRY art_quick_set16_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001624 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001625 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001626 la $t9, artSet16InstanceFromCode
1627 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Fred Shih37f05ef2014-07-16 18:38:08 -07001628 sw rSELF, 16($sp) # pass Thread::Current
Fred Shih37f05ef2014-07-16 18:38:08 -07001629 RETURN_IF_ZERO
1630END art_quick_set16_instance
1631
1632 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001633 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001634 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001635 .extern artSet32InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001636ENTRY art_quick_set32_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001637 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001638 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001639 la $t9, artSet32InstanceFromCode
1640 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001641 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001642 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001643END art_quick_set32_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001644
buzbee5bc5a7b2012-03-07 15:52:59 -08001645 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001646 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
buzbee5bc5a7b2012-03-07 15:52:59 -08001647 */
Fred Shih37f05ef2014-07-16 18:38:08 -07001648 .extern artSet64InstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001649ENTRY art_quick_set64_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001650 lw $t1, 0($sp) # load referrer's Method*
Andreas Gampe8d365912015-01-13 11:32:32 -08001651 # 64 bit new_val is in a2:a3 pair
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001652 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001653 sw rSELF, 20($sp) # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001654 la $t9, artSet64InstanceFromCode
1655 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
Douglas Leung735b8552014-10-31 12:21:40 -07001656 sw $t1, 16($sp) # pass referrer's Method*
buzbee5bc5a7b2012-03-07 15:52:59 -08001657 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001658END art_quick_set64_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001659
buzbee5bc5a7b2012-03-07 15:52:59 -08001660 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001661 * Called by managed code to resolve an instance field and store an object reference.
buzbee5bc5a7b2012-03-07 15:52:59 -08001662 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001663 .extern artSetObjInstanceFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07001664ENTRY art_quick_set_obj_instance
Douglas Leung735b8552014-10-31 12:21:40 -07001665 lw $a3, 0($sp) # pass referrer's Method*
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001666 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001667 la $t9, artSetObjInstanceFromCode
1668 jalr $t9 # (field_idx, Object*, new_val, referrer, Thread*)
jeffhaofa147e22012-10-12 17:03:32 -07001669 sw rSELF, 16($sp) # pass Thread::Current
buzbee5bc5a7b2012-03-07 15:52:59 -08001670 RETURN_IF_ZERO
Ian Rogers468532e2013-08-05 10:56:33 -07001671END art_quick_set_obj_instance
buzbee5bc5a7b2012-03-07 15:52:59 -08001672
Vladimir Markoa3c38272015-04-28 12:37:09 +01001673// Macro to facilitate adding new allocation entrypoints.
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001674.macro ONE_ARG_DOWNCALL name, entrypoint, return
1675 .extern \entrypoint
1676ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001677 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001678 la $t9, \entrypoint
1679 jalr $t9
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001680 move $a1, rSELF # pass Thread::Current
1681 \return
1682END \name
1683.endm
1684
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001685.macro TWO_ARG_DOWNCALL name, entrypoint, return
1686 .extern \entrypoint
1687ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001688 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001689 la $t9, \entrypoint
1690 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001691 move $a2, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001692 \return
1693END \name
1694.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001695
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001696.macro THREE_ARG_DOWNCALL name, entrypoint, return
1697 .extern \entrypoint
1698ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001699 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001700 la $t9, \entrypoint
1701 jalr $t9
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07001702 move $a3, rSELF # pass Thread::Current
Mathieu Chartiercbb2d202013-11-14 17:45:16 -08001703 \return
1704END \name
1705.endm
buzbee5bc5a7b2012-03-07 15:52:59 -08001706
Jeff Hao848f70a2014-01-15 13:49:50 -08001707.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1708 .extern \entrypoint
1709ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001710 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001711 la $t9, \entrypoint
1712 jalr $t9
Vladimir Markoa3c38272015-04-28 12:37:09 +01001713 sw rSELF, 16($sp) # pass Thread::Current
Jeff Hao848f70a2014-01-15 13:49:50 -08001714 \return
1715END \name
1716.endm
1717
Mathieu Chartier7410f292013-11-24 13:17:35 -08001718// Generate the allocation entrypoints for each allocator.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001719GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001720
Pavle Batuta712c59d2015-12-02 18:39:01 +01001721// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1722ENTRY art_quick_alloc_object_rosalloc
1723
1724 # Fast path rosalloc allocation
1725 # a0: type_idx
1726 # a1: ArtMethod*
1727 # s1: Thread::Current
1728 # -----------------------------
1729 # t0: class
1730 # t1: object size
1731 # t2: rosalloc run
1732 # t3: thread stack top offset
1733 # t4: thread stack bottom offset
1734 # v0: free list head
1735 #
1736 # t5, t6 : temps
1737
1738 lw $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_32($a1) # Load dex cache resolved types
1739 # array.
1740
1741 sll $t5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1742 addu $t5, $t0, $t5 # Compute the index.
1743 lw $t0, 0($t5) # Load class (t0).
1744 beqz $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1745
1746 li $t6, MIRROR_CLASS_STATUS_INITIALIZED
1747 lw $t5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1748 bne $t5, $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1749
1750 # Add a fake dependence from the following access flag and size loads to the status load. This
1751 # is to prevent those loads from being reordered above the status load and reading wrong values.
1752 xor $t5, $t5, $t5
1753 addu $t0, $t0, $t5
1754
1755 lw $t5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1756 li $t6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1757 and $t6, $t5, $t6
1758 bnez $t6, .Lart_quick_alloc_object_rosalloc_slow_path
1759
1760 lw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation
1761 lw $t4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # stack has any room left.
1762 bgeu $t3, $t4, .Lart_quick_alloc_object_rosalloc_slow_path
1763
1764 lw $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1765 li $t5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1766 # allocation.
1767 bgtu $t1, $t5, .Lart_quick_alloc_object_rosalloc_slow_path
1768
1769 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1770 # quantum size and divide by the quantum size and subtract by 1.
1771
1772 addiu $t1, $t1, -1 # Decrease obj size and shift right
1773 srl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # by quantum.
1774
1775 sll $t2, $t1, POINTER_SIZE_SHIFT
1776 addu $t2, $t2, $s1
1777 lw $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1778
1779 # Load the free list head (v0).
1780 # NOTE: this will be the return val.
1781
1782 lw $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1783 beqz $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1784 nop
1785
1786 # Load the next pointer of the head and update the list head with the next pointer.
1787
1788 lw $t5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1789 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1790
1791 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1792 # asserted to match.
1793
1794#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1795#error "Class pointer needs to overwrite next pointer."
1796#endif
1797
1798 POISON_HEAP_REF $t0
1799 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1800
1801 # Push the new object onto the thread local allocation stack and increment the thread local
1802 # allocation stack top.
1803
1804 sw $v0, 0($t3)
1805 addiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1806 sw $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1807
1808 # Decrement the size of the free list.
1809
1810 lw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1811 addiu $t5, $t5, -1
1812 sw $t5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1813
1814 sync # Fence.
1815
1816 jalr $zero, $ra
1817 nop
1818
1819 .Lart_quick_alloc_object_rosalloc_slow_path:
1820
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001821 SETUP_SAVE_REFS_ONLY_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001822 la $t9, artAllocObjectFromCodeRosAlloc
1823 jalr $t9
Chris Larsencf283da2016-01-19 16:45:35 -08001824 move $a2, $s1 # Pass self as argument.
Pavle Batuta712c59d2015-12-02 18:39:01 +01001825 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1826
1827END art_quick_alloc_object_rosalloc
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001828
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001829GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1830GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1831
buzbee5bc5a7b2012-03-07 15:52:59 -08001832 /*
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001833 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001834 * exception on error. On success the String is returned. A0 holds the string index. The fast
1835 * path check for hit in strings cache has already been performed.
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001836 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001837ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001838
1839 /*
1840 * Entry from managed code when uninitialized static storage, this stub will run the class
1841 * initializer and deliver the exception on error. On success the static storage base is
1842 * returned.
1843 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001844ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001845
1846 /*
1847 * Entry from managed code when dex cache misses for a type_idx.
1848 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001849ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Andreas Gampe1cc7dba2014-12-17 18:43:01 -08001850
1851 /*
1852 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1853 * miss.
1854 */
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001855ONE_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 -08001856
1857 /*
Ian Rogers57b86d42012-03-27 16:05:41 -07001858 * Called by managed code when the value in rSUSPEND has been decremented to 0.
buzbee5bc5a7b2012-03-07 15:52:59 -08001859 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001860 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001861ENTRY_NO_GP art_quick_test_suspend
1862 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1863 bnez rSUSPEND, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001864 addiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
Andreas Gampe8d365912015-01-13 11:32:32 -08001865 jalr $zero, $ra
buzbee5bc5a7b2012-03-07 15:52:59 -08001866 nop
18671:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001868 SETUP_SAVE_EVERYTHING_FRAME # save everything for stack crawl
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001869 la $t9, artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001870 jalr $t9 # (Thread*)
jeffhao7fbee072012-08-24 17:56:54 -07001871 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001872 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001873 jalr $zero, $ra
1874 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001875END art_quick_test_suspend
buzbee5bc5a7b2012-03-07 15:52:59 -08001876
buzbee5bc5a7b2012-03-07 15:52:59 -08001877 /*
1878 * Called by managed code that is attempting to call a method on a proxy class. On entry
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001879 * a0 holds the proxy method; a1, a2 and a3 may contain arguments.
buzbee5bc5a7b2012-03-07 15:52:59 -08001880 */
Jeff Hao5fa60c32013-04-04 17:57:01 -07001881 .extern artQuickProxyInvokeHandler
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001882ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001883 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07001884 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001885 la $t9, artQuickProxyInvokeHandler
1886 jalr $t9 # (Method* proxy method, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001887 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
jeffhao7fbee072012-08-24 17:56:54 -07001888 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001889 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhao7fbee072012-08-24 17:56:54 -07001890 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08001891 # don't care if $v0 and/or $v1 are modified, when exception branch taken
1892 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08001893 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08001894 nop
buzbee5bc5a7b2012-03-07 15:52:59 -080018951:
1896 DELIVER_PENDING_EXCEPTION
Jeff Haod4c3f7d2013-02-14 14:14:44 -08001897END art_quick_proxy_invoke_handler
buzbee5bc5a7b2012-03-07 15:52:59 -08001898
Jeff Hao88474b42013-10-23 16:24:40 -07001899 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001900 * Called to resolve an imt conflict.
1901 * a0 is the conflict ArtMethod.
1902 * t0 is a hidden argument that holds the target interface method's dex method index.
1903 *
1904 * Note that this stub writes to a0, t0 and t1.
Jeff Hao88474b42013-10-23 16:24:40 -07001905 */
Douglas Leung13738bf2014-10-27 14:44:47 -07001906ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001907 lw $t1, 0($sp) # Load referrer.
1908 lw $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_32($t1) # Load dex cache methods array.
1909 sll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1910 addu $t0, $t1, $t0 # Add offset to base.
1911 lw $t0, 0($t0) # Load interface method.
1912 lw $a0, ART_METHOD_JNI_OFFSET_32($a0) # Load ImtConflictTable.
1913
1914.Limt_table_iterate:
1915 lw $t1, 0($a0) # Load next entry in ImtConflictTable.
1916 # Branch if found.
1917 beq $t1, $t0, .Limt_table_found
1918 nop
1919 # If the entry is null, the interface method is not in the ImtConflictTable.
1920 beqz $t1, .Lconflict_trampoline
1921 nop
1922 # Iterate over the entries of the ImtConflictTable.
1923 b .Limt_table_iterate
1924 addiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1925
1926.Limt_table_found:
1927 # We successfully hit an entry in the table. Load the target method and jump to it.
1928 lw $a0, __SIZEOF_POINTER__($a0)
1929 lw $t9, ART_METHOD_QUICK_CODE_OFFSET_32($a0)
1930 jr $t9
1931 nop
1932
1933.Lconflict_trampoline:
1934 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001935 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Jeff Hao88474b42013-10-23 16:24:40 -07001936END art_quick_imt_conflict_trampoline
1937
Ian Rogers468532e2013-08-05 10:56:33 -07001938 .extern artQuickResolutionTrampoline
1939ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001940 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07001941 move $a2, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001942 la $t9, artQuickResolutionTrampoline
1943 jalr $t9 # (Method* called, receiver, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001944 addiu $a3, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers468532e2013-08-05 10:56:33 -07001945 beqz $v0, 1f
Douglas Leung735b8552014-10-31 12:21:40 -07001946 lw $a0, ARG_SLOT_SIZE($sp) # load resolved method to $a0
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001947 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers65d1b222013-09-27 10:59:41 -07001948 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
Douglas Leungf96e8bd2015-03-27 15:38:30 -07001949 jalr $zero, $t9 # tail call to method
Mathieu Chartier19841522013-10-22 11:29:00 -07001950 nop
Ian Rogers468532e2013-08-05 10:56:33 -070019511:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001952 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers468532e2013-08-05 10:56:33 -07001953 DELIVER_PENDING_EXCEPTION
1954END art_quick_resolution_trampoline
1955
Douglas Leung735b8552014-10-31 12:21:40 -07001956 .extern artQuickGenericJniTrampoline
1957 .extern artQuickGenericJniEndTrampoline
1958ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001959 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung735b8552014-10-31 12:21:40 -07001960 move $s8, $sp # save $sp to $s8
1961 move $s3, $gp # save $gp to $s3
1962
1963 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1964 move $a0, rSELF # pass Thread::Current
1965 addiu $a1, $sp, ARG_SLOT_SIZE # save $sp (remove arg slots)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001966 la $t9, artQuickGenericJniTrampoline
1967 jalr $t9 # (Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07001968 addiu $sp, $sp, -5120 # reserve space on the stack
1969
1970 # The C call will have registered the complete save-frame on success.
1971 # The result of the call is:
1972 # v0: ptr to native code, 0 on error.
1973 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
1974 beq $v0, $zero, 1f # check entry error
1975 move $t9, $v0 # save the code ptr
1976 move $sp, $v1 # release part of the alloca
1977
1978 # Load parameters from stack into registers
1979 lw $a0, 0($sp)
1980 lw $a1, 4($sp)
1981 lw $a2, 8($sp)
1982
1983 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
1984 jalr $t9 # native call
1985 lw $a3, 12($sp)
1986 addiu $sp, $sp, 16 # remove arg slots
1987
1988 move $gp, $s3 # restore $gp from $s3
1989
1990 # result sign extension is handled in C code
1991 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
1992 move $a0, rSELF # pass Thread::Current
1993 move $a2, $v0 # pass result
1994 move $a3, $v1
1995 addiu $sp, $sp, -24 # reserve arg slots
Goran Jakovljevic590b1362016-03-21 14:24:43 +01001996 la $t9, artQuickGenericJniEndTrampoline
1997 jalr $t9
Douglas Leung735b8552014-10-31 12:21:40 -07001998 s.d $f0, 16($sp) # pass result_f
Douglas Leung735b8552014-10-31 12:21:40 -07001999
2000 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002001 bne $t0, $zero, 1f # check for pending exceptions
2002
Douglas Leung735b8552014-10-31 12:21:40 -07002003 move $sp, $s8 # tear down the alloca
2004
2005 # tear dpown the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002006 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002007
Duane Sande34652f2014-11-04 11:09:36 -08002008 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002009 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002010 nop
Douglas Leung735b8552014-10-31 12:21:40 -07002011
20121:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002013 lw $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2014 # This will create a new save-all frame, required by the runtime.
Douglas Leung735b8552014-10-31 12:21:40 -07002015 DELIVER_PENDING_EXCEPTION
2016END art_quick_generic_jni_trampoline
Andreas Gampe2da88232014-02-27 12:26:20 -08002017
Ian Rogers468532e2013-08-05 10:56:33 -07002018 .extern artQuickToInterpreterBridge
2019ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002020 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002021 move $a1, rSELF # pass Thread::Current
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002022 la $t9, artQuickToInterpreterBridge
2023 jalr $t9 # (Method* method, Thread*, SP)
Douglas Leung735b8552014-10-31 12:21:40 -07002024 addiu $a2, $sp, ARG_SLOT_SIZE # pass $sp (remove arg slots)
Ian Rogers7db619b2013-01-16 18:35:48 -08002025 lw $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002026 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Ian Rogers7db619b2013-01-16 18:35:48 -08002027 bnez $t0, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002028 # don't care if $v0 and/or $v1 are modified, when exception branch taken
2029 MTD $v0, $v1, $f0, $f1 # move float value to return value
Andreas Gampe8d365912015-01-13 11:32:32 -08002030 jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002031 nop
Ian Rogers7db619b2013-01-16 18:35:48 -080020321:
2033 DELIVER_PENDING_EXCEPTION
Ian Rogers468532e2013-08-05 10:56:33 -07002034END art_quick_to_interpreter_bridge
Ian Rogers7db619b2013-01-16 18:35:48 -08002035
buzbee5bc5a7b2012-03-07 15:52:59 -08002036 /*
jeffhao725a9572012-11-13 18:20:12 -08002037 * Routine that intercepts method calls and returns.
buzbee5bc5a7b2012-03-07 15:52:59 -08002038 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002039 .extern artInstrumentationMethodEntryFromCode
2040 .extern artInstrumentationMethodExitFromCode
Ian Rogers468532e2013-08-05 10:56:33 -07002041ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002042 SETUP_SAVE_REFS_AND_ARGS_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002043 sw $a0, 28($sp) # save arg0 in free arg slot
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002044 move $a3, $ra # pass $ra
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002045 la $t9, artInstrumentationMethodEntryFromCode
2046 jalr $t9 # (Method*, Object*, Thread*, LR)
Ian Rogers62d6c772013-02-27 08:32:07 -08002047 move $a2, rSELF # pass Thread::Current
jeffhao8161c032012-10-31 15:50:00 -07002048 move $t9, $v0 # $t9 holds reference to code
Douglas Leung735b8552014-10-31 12:21:40 -07002049 lw $a0, 28($sp) # restore arg0 from free arg slot
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002050 RESTORE_SAVE_REFS_AND_ARGS_FRAME
jeffhao8161c032012-10-31 15:50:00 -07002051 jalr $t9 # call method
Ian Rogers62d6c772013-02-27 08:32:07 -08002052 nop
Ian Rogers468532e2013-08-05 10:56:33 -07002053END art_quick_instrumentation_entry
buzbee5bc5a7b2012-03-07 15:52:59 -08002054 /* intentional fallthrough */
Ian Rogers468532e2013-08-05 10:56:33 -07002055 .global art_quick_instrumentation_exit
2056art_quick_instrumentation_exit:
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002057 .cfi_startproc
jeffhao12051ea2013-01-10 11:24:31 -08002058 addiu $t9, $ra, 4 # put current address into $t9 to rebuild $gp
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002059 .cpload $t9
Douglas Leungc3d131e2014-07-16 17:32:41 -07002060 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Douglas Leung735b8552014-10-31 12:21:40 -07002061
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002062 SETUP_SAVE_REFS_ONLY_FRAME
Douglas Leung735b8552014-10-31 12:21:40 -07002063 addiu $sp, $sp, -16 # allocate temp storage on the stack
2064 .cfi_adjust_cfa_offset 16
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002065 sw $v0, ARG_SLOT_SIZE+12($sp)
2066 .cfi_rel_offset 2, ARG_SLOT_SIZE+12
2067 sw $v1, ARG_SLOT_SIZE+8($sp)
2068 .cfi_rel_offset 3, ARG_SLOT_SIZE+8
2069 s.d $f0, ARG_SLOT_SIZE($sp)
Duane Sande34652f2014-11-04 11:09:36 -08002070 s.d $f0, 16($sp) # pass fpr result
Ian Rogers62d6c772013-02-27 08:32:07 -08002071 move $a2, $v0 # pass gpr result
2072 move $a3, $v1
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002073 addiu $a1, $sp, ARG_SLOT_SIZE+16 # pass $sp (remove arg slots and temp storage)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002074 la $t9, artInstrumentationMethodExitFromCode
2075 jalr $t9 # (Thread*, SP, gpr_res, fpr_res)
jeffhao12051ea2013-01-10 11:24:31 -08002076 move $a0, rSELF # pass Thread::Current
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002077 move $t9, $v0 # set aside returned link register
jeffhao12051ea2013-01-10 11:24:31 -08002078 move $ra, $v1 # set link register for deoptimization
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002079 lw $v0, ARG_SLOT_SIZE+12($sp) # restore return values
2080 lw $v1, ARG_SLOT_SIZE+8($sp)
2081 l.d $f0, ARG_SLOT_SIZE($sp)
2082 jalr $zero, $t9 # return
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002083 addiu $sp, $sp, ARG_SLOT_SIZE+FRAME_SIZE_SAVE_REFS_ONLY+16 # restore stack
2084 .cfi_adjust_cfa_offset -(ARG_SLOT_SIZE+FRAME_SIZE_SAVE_REFS_ONLY+16)
Ian Rogers468532e2013-08-05 10:56:33 -07002085END art_quick_instrumentation_exit
buzbee5bc5a7b2012-03-07 15:52:59 -08002086
jeffhao12051ea2013-01-10 11:24:31 -08002087 /*
Ian Rogers62d6c772013-02-27 08:32:07 -08002088 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2089 * will long jump to the upcall with a special exception of -1.
jeffhao12051ea2013-01-10 11:24:31 -08002090 */
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002091 .extern artDeoptimize
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002092ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002093 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002094 la $t9, artDeoptimize
2095 jalr $t9 # artDeoptimize(Thread*)
jeffhao12051ea2013-01-10 11:24:31 -08002096 # Returns caller method's frame size.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002097 move $a0, rSELF # pass Thread::current
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002098END art_quick_deoptimize
jeffhao12051ea2013-01-10 11:24:31 -08002099
buzbee5bc5a7b2012-03-07 15:52:59 -08002100 /*
Sebastien Hertz07474662015-08-25 15:12:33 +00002101 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2102 * will long jump to the upcall with a special exception of -1.
2103 */
2104 .extern artDeoptimizeFromCompiledCode
2105ENTRY art_quick_deoptimize_from_compiled_code
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002106 SETUP_SAVE_EVERYTHING_FRAME
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002107 la $t9, artDeoptimizeFromCompiledCode
2108 jalr $t9 # artDeoptimizeFromCompiledCode(Thread*)
Sebastien Hertz07474662015-08-25 15:12:33 +00002109 # Returns caller method's frame size.
2110 move $a0, rSELF # pass Thread::current
2111END art_quick_deoptimize_from_compiled_code
2112
2113 /*
buzbee5bc5a7b2012-03-07 15:52:59 -08002114 * Long integer shift. This is different from the generic 32/64-bit
2115 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2116 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2117 * 6 bits.
2118 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002119 * $a0: low word
2120 * $a1: high word
2121 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002122 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002123ENTRY_NO_GP art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002124 /* shl-long vAA, vBB, vCC */
jeffhao7fbee072012-08-24 17:56:54 -07002125 sll $v0, $a0, $a2 # rlo<- alo << (shift&31)
2126 not $v1, $a2 # rhi<- 31-shift (shift is 5b)
2127 srl $a0, 1
2128 srl $a0, $v1 # alo<- alo >> (32-(shift&31))
2129 sll $v1, $a1, $a2 # rhi<- ahi << (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002130 andi $a2, 0x20 # shift< shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002131 beqz $a2, 1f
2132 or $v1, $a0 # rhi<- rhi | alo
2133
2134 move $v1, $v0 # rhi<- rlo (if shift&0x20)
2135 move $v0, $zero # rlo<- 0 (if shift&0x20)
2136
Andreas Gampe8d365912015-01-13 11:32:32 -080021371: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002138 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002139END art_quick_shl_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002140
buzbee5bc5a7b2012-03-07 15:52:59 -08002141 /*
2142 * Long integer shift. This is different from the generic 32/64-bit
2143 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2144 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2145 * 6 bits.
2146 * On entry:
jeffhao7fbee072012-08-24 17:56:54 -07002147 * $a0: low word
2148 * $a1: high word
2149 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002150 */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002151ENTRY_NO_GP art_quick_shr_long
jeffhao7fbee072012-08-24 17:56:54 -07002152 sra $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
2153 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
2154 sra $a3, $a1, 31 # $a3<- sign(ah)
2155 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2156 sll $a1, 1
2157 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002158 andi $a2, 0x20 # shift & 0x20
Douglas Leung475cfd82014-12-16 20:15:41 -08002159 beqz $a2, 1f
Duane Sande34652f2014-11-04 11:09:36 -08002160 or $v0, $a1 # rlo<- rlo | ahi
2161
2162 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2163 move $v1, $a3 # rhi<- sign(ahi) (if shift&0x20)
2164
Andreas Gampe8d365912015-01-13 11:32:32 -080021651: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002166 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002167END art_quick_shr_long
buzbee5bc5a7b2012-03-07 15:52:59 -08002168
buzbee5bc5a7b2012-03-07 15:52:59 -08002169 /*
2170 * Long integer shift. This is different from the generic 32/64-bit
2171 * binary operations because vAA/vBB are 64-bit but vCC (the shift
2172 * distance) is 32-bit. Also, Dalvik requires us to ignore all but the low
2173 * 6 bits.
2174 * On entry:
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002175 * $a0: low word
2176 * $a1: high word
2177 * $a2: shift count
buzbee5bc5a7b2012-03-07 15:52:59 -08002178 */
2179 /* ushr-long vAA, vBB, vCC */
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002180ENTRY_NO_GP art_quick_ushr_long
jeffhaofc6a30e2012-10-18 18:24:15 -07002181 srl $v1, $a1, $a2 # rhi<- ahi >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002182 srl $v0, $a0, $a2 # rlo<- alo >> (shift&31)
jeffhao7fbee072012-08-24 17:56:54 -07002183 not $a0, $a2 # alo<- 31-shift (shift is 5b)
2184 sll $a1, 1
2185 sll $a1, $a0 # ahi<- ahi << (32-(shift&31))
jeffhao7fbee072012-08-24 17:56:54 -07002186 andi $a2, 0x20 # shift & 0x20
Duane Sande34652f2014-11-04 11:09:36 -08002187 beqz $a2, 1f
2188 or $v0, $a1 # rlo<- rlo | ahi
2189
2190 move $v0, $v1 # rlo<- rhi (if shift&0x20)
2191 move $v1, $zero # rhi<- 0 (if shift&0x20)
2192
Andreas Gampe8d365912015-01-13 11:32:32 -080021931: jalr $zero, $ra
Duane Sande34652f2014-11-04 11:09:36 -08002194 nop
Jeff Haod4c3f7d2013-02-14 14:14:44 -08002195END art_quick_ushr_long
jeffhao7fbee072012-08-24 17:56:54 -07002196
Chris Larsencf283da2016-01-19 16:45:35 -08002197/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2198ENTRY_NO_GP art_quick_indexof
2199/* $a0 holds address of "this" */
2200/* $a1 holds "ch" */
2201/* $a2 holds "fromIndex" */
2202 lw $t0, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002203 slt $t1, $a2, $zero # if fromIndex < 0
Chris Larsencf283da2016-01-19 16:45:35 -08002204#if defined(_MIPS_ARCH_MIPS32R6) || defined(_MIPS_ARCH_MIPS64R6)
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002205 seleqz $a2, $a2, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08002206#else
Goran Jakovljevic590b1362016-03-21 14:24:43 +01002207 movn $a2, $zero, $t1 # fromIndex = 0;
Chris Larsencf283da2016-01-19 16:45:35 -08002208#endif
2209 subu $t0, $t0, $a2 # this.length() - fromIndex
2210 blez $t0, 6f # if this.length()-fromIndex <= 0
2211 li $v0, -1 # return -1;
2212
2213 sll $v0, $a2, 1 # $a0 += $a2 * 2
2214 addu $a0, $a0, $v0 # " " " " "
2215 move $v0, $a2 # Set i to fromIndex.
2216
22171:
2218 lhu $t3, MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2219 beq $t3, $a1, 6f # return i;
2220 addu $a0, $a0, 2 # i++
2221 subu $t0, $t0, 1 # this.length() - i
2222 bnez $t0, 1b # while this.length() - i > 0
2223 addu $v0, $v0, 1 # i++
2224
2225 li $v0, -1 # if this.length() - i <= 0
2226 # return -1;
2227
22286:
2229 j $ra
2230 nop
2231END art_quick_indexof
2232
Chris Larsencf283da2016-01-19 16:45:35 -08002233/* java.lang.String.compareTo(String anotherString) */
2234ENTRY_NO_GP art_quick_string_compareto
2235/* $a0 holds address of "this" */
2236/* $a1 holds address of "anotherString" */
2237 beq $a0, $a1, 9f # this and anotherString are the same object
2238 move $v0, $zero
2239
2240 lw $a2, MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2241 lw $a3, MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
2242 MINu $t2, $a2, $a3
2243# $t2 now holds min(this.length(),anotherString.length())
2244
2245 beqz $t2, 9f # while min(this.length(),anotherString.length())-i != 0
2246 subu $v0, $a2, $a3 # if $t2==0 return
2247 # (this.length() - anotherString.length())
22481:
2249 lhu $t0, MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2250 lhu $t1, MIRROR_STRING_VALUE_OFFSET($a1)
2251 bne $t0, $t1, 9f # if this.charAt(i) != anotherString.charAt(i)
2252 subu $v0, $t0, $t1 # return (this.charAt(i) - anotherString.charAt(i))
2253 addiu $a0, $a0, 2 # point at this.charAt(i++)
2254 subu $t2, $t2, 1 # new value of
2255 # min(this.length(),anotherString.length())-i
2256 bnez $t2, 1b
2257 addiu $a1, $a1, 2 # point at anotherString.charAt(i++)
2258 subu $v0, $a2, $a3
2259
22609:
2261 j $ra
2262 nop
2263END art_quick_string_compareto