blob: d51d18a8ac183e02d1b020be2eb96ae26ed8c9fd [file] [log] [blame]
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_mips64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21 .set noreorder
22 .balign 16
23
24 /* Deliver the given exception */
25 .extern artDeliverExceptionFromCode
26 /* Deliver an exception pending on a thread */
27 .extern artDeliverPendingExceptionFromCode
28
29 /*
Goran Jakovljevic04568812015-04-23 15:27:23 +020030 * Macro that sets up $gp and stores the previous $gp value to $t8.
31 * This macro modifies v1 and t8.
32 */
33.macro SETUP_GP
34 move $v1, $ra
35 bal 1f
36 nop
371:
38 .cpsetup $ra, $t8, 1b
39 move $ra, $v1
40.endm
41
42 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -080043 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010044 * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves)
Andreas Gampe1a5c4062015-01-15 12:10:47 -080045 * callee-save: padding + $f24-$f31 + $s0-$s7 + $gp + $ra + $s8 = 19 total + 1x8 bytes padding
46 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +010047.macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -080048 daddiu $sp, $sp, -160
49 .cfi_adjust_cfa_offset 160
50
51 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +010052#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 160)
53#error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -080054#endif
55
56 sd $ra, 152($sp)
57 .cfi_rel_offset 31, 152
58 sd $s8, 144($sp)
59 .cfi_rel_offset 30, 144
Goran Jakovljevic04568812015-04-23 15:27:23 +020060 sd $t8, 136($sp) # t8 holds caller's gp, now save it to the stack.
61 .cfi_rel_offset 28, 136 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080062 sd $s7, 128($sp)
63 .cfi_rel_offset 23, 128
64 sd $s6, 120($sp)
65 .cfi_rel_offset 22, 120
66 sd $s5, 112($sp)
67 .cfi_rel_offset 21, 112
68 sd $s4, 104($sp)
69 .cfi_rel_offset 20, 104
70 sd $s3, 96($sp)
71 .cfi_rel_offset 19, 96
72 sd $s2, 88($sp)
73 .cfi_rel_offset 18, 88
74 sd $s1, 80($sp)
75 .cfi_rel_offset 17, 80
76 sd $s0, 72($sp)
77 .cfi_rel_offset 16, 72
78
79 // FP callee-saves
80 s.d $f31, 64($sp)
81 s.d $f30, 56($sp)
82 s.d $f29, 48($sp)
83 s.d $f28, 40($sp)
84 s.d $f27, 32($sp)
85 s.d $f26, 24($sp)
86 s.d $f25, 16($sp)
87 s.d $f24, 8($sp)
88
89 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +020090 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
91 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +010092 ld $t1, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +020093 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080094 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
95.endm
96
97 /*
98 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +010099 * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly). Restoration assumes
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800100 * non-moving GC.
101 * Does not include rSUSPEND or rSELF
102 * callee-save: padding + $s2-$s7 + $gp + $ra + $s8 = 9 total + 1x8 bytes padding
103 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100104.macro SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800105 daddiu $sp, $sp, -80
106 .cfi_adjust_cfa_offset 80
107
108 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100109#if (FRAME_SIZE_SAVE_REFS_ONLY != 80)
110#error "FRAME_SIZE_SAVE_REFS_ONLY(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800111#endif
112
113 sd $ra, 72($sp)
114 .cfi_rel_offset 31, 72
115 sd $s8, 64($sp)
116 .cfi_rel_offset 30, 64
Goran Jakovljevic04568812015-04-23 15:27:23 +0200117 sd $t8, 56($sp) # t8 holds caller's gp, now save it to the stack.
118 .cfi_rel_offset 28, 56 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800119 sd $s7, 48($sp)
120 .cfi_rel_offset 23, 48
121 sd $s6, 40($sp)
122 .cfi_rel_offset 22, 40
123 sd $s5, 32($sp)
124 .cfi_rel_offset 21, 32
125 sd $s4, 24($sp)
126 .cfi_rel_offset 20, 24
127 sd $s3, 16($sp)
128 .cfi_rel_offset 19, 16
129 sd $s2, 8($sp)
130 .cfi_rel_offset 18, 8
131 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200132 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
133 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100134 ld $t1, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200135 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800136 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
137.endm
138
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100139.macro RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800140 ld $ra, 72($sp)
141 .cfi_restore 31
142 ld $s8, 64($sp)
143 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200144 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800145 .cfi_restore 28
146 ld $s7, 48($sp)
147 .cfi_restore 23
148 ld $s6, 40($sp)
149 .cfi_restore 22
150 ld $s5, 32($sp)
151 .cfi_restore 21
152 ld $s4, 24($sp)
153 .cfi_restore 20
154 ld $s3, 16($sp)
155 .cfi_restore 19
156 ld $s2, 8($sp)
157 .cfi_restore 18
158 daddiu $sp, $sp, 80
159 .cfi_adjust_cfa_offset -80
Goran Jakovljevic04568812015-04-23 15:27:23 +0200160 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800161.endm
162
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100163.macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800164 ld $ra, 72($sp)
165 .cfi_restore 31
166 ld $s8, 64($sp)
167 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200168 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800169 .cfi_restore 28
170 ld $s7, 48($sp)
171 .cfi_restore 23
172 ld $s6, 40($sp)
173 .cfi_restore 22
174 ld $s5, 32($sp)
175 .cfi_restore 21
176 ld $s4, 24($sp)
177 .cfi_restore 20
178 ld $s3, 16($sp)
179 .cfi_restore 19
180 ld $s2, 8($sp)
181 .cfi_restore 18
Goran Jakovljevic04568812015-04-23 15:27:23 +0200182 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800183 jalr $zero, $ra
184 daddiu $sp, $sp, 80
185 .cfi_adjust_cfa_offset -80
186.endm
187
188// This assumes the top part of these stack frame types are identical.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100189#define REFS_AND_ARGS_MINUS_REFS_SIZE (FRAME_SIZE_SAVE_REFS_AND_ARGS - FRAME_SIZE_SAVE_REFS_ONLY)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800190
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100191.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800192 daddiu $sp, $sp, -208
193 .cfi_adjust_cfa_offset 208
194
195 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100196#if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 208)
197#error "FRAME_SIZE_SAVE_REFS_AND_ARGS(MIPS64) size not as expected."
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800198#endif
199
200 sd $ra, 200($sp) # = kQuickCalleeSaveFrame_RefAndArgs_LrOffset
201 .cfi_rel_offset 31, 200
202 sd $s8, 192($sp)
203 .cfi_rel_offset 30, 192
Goran Jakovljevic04568812015-04-23 15:27:23 +0200204 sd $t8, 184($sp) # t8 holds caller's gp, now save it to the stack.
205 .cfi_rel_offset 28, 184 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800206 sd $s7, 176($sp)
207 .cfi_rel_offset 23, 176
208 sd $s6, 168($sp)
209 .cfi_rel_offset 22, 168
210 sd $s5, 160($sp)
211 .cfi_rel_offset 21, 160
212 sd $s4, 152($sp)
213 .cfi_rel_offset 20, 152
214 sd $s3, 144($sp)
215 .cfi_rel_offset 19, 144
216 sd $s2, 136($sp)
217 .cfi_rel_offset 18, 136
218
219 sd $a7, 128($sp)
220 .cfi_rel_offset 11, 128
221 sd $a6, 120($sp)
222 .cfi_rel_offset 10, 120
223 sd $a5, 112($sp)
224 .cfi_rel_offset 9, 112
225 sd $a4, 104($sp)
226 .cfi_rel_offset 8, 104
227 sd $a3, 96($sp)
228 .cfi_rel_offset 7, 96
229 sd $a2, 88($sp)
230 .cfi_rel_offset 6, 88
231 sd $a1, 80($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset
232 .cfi_rel_offset 5, 80
233
234 s.d $f19, 72($sp)
235 s.d $f18, 64($sp)
236 s.d $f17, 56($sp)
237 s.d $f16, 48($sp)
238 s.d $f15, 40($sp)
239 s.d $f14, 32($sp)
240 s.d $f13, 24($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset
241 s.d $f12, 16($sp) # This isn't necessary to store.
Douglas Leung8223b802015-04-28 17:22:29 -0700242 # 1x8 bytes padding + Method*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800243.endm
244
Douglas Leung8223b802015-04-28 17:22:29 -0700245 /*
246 * Macro that sets up the callee save frame to conform with
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100247 * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). Restoration assumes
Douglas Leung8223b802015-04-28 17:22:29 -0700248 * non-moving GC.
249 * callee-save: padding + $f12-$f19 + $a1-$a7 + $s2-$s7 + $gp + $ra + $s8 = 24 total + 1 words padding + Method*
250 */
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100251.macro SETUP_SAVE_REFS_AND_ARGS_FRAME
252 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800253 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200254 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
255 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100256 ld $t1, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200257 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800258 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
259.endm
260
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100261.macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
262 SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL
Mathieu Chartiere401d142015-04-22 13:56:20 -0700263 sd $a0, 0($sp) # Place Method* at bottom of stack.
Douglas Leung8223b802015-04-28 17:22:29 -0700264 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
265.endm
266
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100267.macro RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800268 ld $ra, 200($sp)
269 .cfi_restore 31
270 ld $s8, 192($sp)
271 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200272 ld $t8, 184($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800273 .cfi_restore 28
274 ld $s7, 176($sp)
275 .cfi_restore 23
276 ld $s6, 168($sp)
277 .cfi_restore 22
278 ld $s5, 160($sp)
279 .cfi_restore 21
280 ld $s4, 152($sp)
281 .cfi_restore 20
282 ld $s3, 144($sp)
283 .cfi_restore 19
284 ld $s2, 136($sp)
285 .cfi_restore 18
286
287 ld $a7, 128($sp)
288 .cfi_restore 11
289 ld $a6, 120($sp)
290 .cfi_restore 10
291 ld $a5, 112($sp)
292 .cfi_restore 9
293 ld $a4, 104($sp)
294 .cfi_restore 8
295 ld $a3, 96($sp)
296 .cfi_restore 7
297 ld $a2, 88($sp)
298 .cfi_restore 6
299 ld $a1, 80($sp)
300 .cfi_restore 5
301
302 l.d $f19, 72($sp)
303 l.d $f18, 64($sp)
304 l.d $f17, 56($sp)
305 l.d $f16, 48($sp)
306 l.d $f15, 40($sp)
307 l.d $f14, 32($sp)
308 l.d $f13, 24($sp)
309 l.d $f12, 16($sp)
310
Goran Jakovljevic04568812015-04-23 15:27:23 +0200311 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800312 daddiu $sp, $sp, 208
313 .cfi_adjust_cfa_offset -208
314.endm
315
316 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100317 * Macro that sets up the callee save frame to conform with
318 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
Vladimir Marko7aa75602016-09-07 15:09:21 +0100319 * when the $sp has already been decremented by FRAME_SIZE_SAVE_EVERYTHING.
Vladimir Marko952dbb12016-07-28 12:01:51 +0100320 * callee-save: $at + $v0-$v1 + $a0-$a7 + $t0-$t3 + $s0-$s7 + $t8-$t9 + $gp + $s8 + $ra + $s8,
321 * $f0-$f31; 28(GPR)+ 32(FPR) + 1x8 bytes padding + method*
322 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
323 */
Vladimir Marko7aa75602016-09-07 15:09:21 +0100324.macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
Vladimir Marko952dbb12016-07-28 12:01:51 +0100325 // Ugly compile-time check, but we only have the preprocessor.
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100326#if (FRAME_SIZE_SAVE_EVERYTHING != 496)
327#error "FRAME_SIZE_SAVE_EVERYTHING(MIPS64) size not as expected."
Vladimir Marko952dbb12016-07-28 12:01:51 +0100328#endif
329
330 // Save core registers.
331 sd $ra, 488($sp)
332 .cfi_rel_offset 31, 488
333 sd $s8, 480($sp)
334 .cfi_rel_offset 30, 480
Vladimir Marko952dbb12016-07-28 12:01:51 +0100335 sd $t9, 464($sp)
336 .cfi_rel_offset 25, 464
337 sd $t8, 456($sp)
338 .cfi_rel_offset 24, 456
339 sd $s7, 448($sp)
340 .cfi_rel_offset 23, 448
341 sd $s6, 440($sp)
342 .cfi_rel_offset 22, 440
343 sd $s5, 432($sp)
344 .cfi_rel_offset 21, 432
345 sd $s4, 424($sp)
346 .cfi_rel_offset 20, 424
347 sd $s3, 416($sp)
348 .cfi_rel_offset 19, 416
349 sd $s2, 408($sp)
350 .cfi_rel_offset 18, 408
351 sd $s1, 400($sp)
352 .cfi_rel_offset 17, 400
353 sd $s0, 392($sp)
354 .cfi_rel_offset 16, 392
355 sd $t3, 384($sp)
356 .cfi_rel_offset 15, 384
357 sd $t2, 376($sp)
358 .cfi_rel_offset 14, 376
359 sd $t1, 368($sp)
360 .cfi_rel_offset 13, 368
361 sd $t0, 360($sp)
362 .cfi_rel_offset 12, 360
363 sd $a7, 352($sp)
364 .cfi_rel_offset 11, 352
365 sd $a6, 344($sp)
366 .cfi_rel_offset 10, 344
367 sd $a5, 336($sp)
368 .cfi_rel_offset 9, 336
369 sd $a4, 328($sp)
370 .cfi_rel_offset 8, 328
371 sd $a3, 320($sp)
372 .cfi_rel_offset 7, 320
373 sd $a2, 312($sp)
374 .cfi_rel_offset 6, 312
375 sd $a1, 304($sp)
376 .cfi_rel_offset 5, 304
377 sd $a0, 296($sp)
378 .cfi_rel_offset 4, 296
379 sd $v1, 288($sp)
380 .cfi_rel_offset 3, 288
381 sd $v0, 280($sp)
382 .cfi_rel_offset 2, 280
383
384 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
385 bal 1f
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200386 .set push
387 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100388 sd $at, 272($sp)
389 .cfi_rel_offset 1, 272
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200390 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +01003911:
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200392 .cpsetup $ra, 472, 1b
Vladimir Marko952dbb12016-07-28 12:01:51 +0100393
394 // Save FP registers.
395 s.d $f31, 264($sp)
396 s.d $f30, 256($sp)
397 s.d $f29, 248($sp)
398 s.d $f28, 240($sp)
399 s.d $f27, 232($sp)
400 s.d $f26, 224($sp)
401 s.d $f25, 216($sp)
402 s.d $f24, 208($sp)
403 s.d $f23, 200($sp)
404 s.d $f22, 192($sp)
405 s.d $f21, 184($sp)
406 s.d $f20, 176($sp)
407 s.d $f19, 168($sp)
408 s.d $f18, 160($sp)
409 s.d $f17, 152($sp)
410 s.d $f16, 144($sp)
411 s.d $f15, 136($sp)
412 s.d $f14, 128($sp)
413 s.d $f13, 120($sp)
414 s.d $f12, 112($sp)
415 s.d $f11, 104($sp)
416 s.d $f10, 96($sp)
417 s.d $f9, 88($sp)
418 s.d $f8, 80($sp)
419 s.d $f7, 72($sp)
420 s.d $f6, 64($sp)
421 s.d $f5, 56($sp)
422 s.d $f4, 48($sp)
423 s.d $f3, 40($sp)
424 s.d $f2, 32($sp)
425 s.d $f1, 24($sp)
426 s.d $f0, 16($sp)
427
428 # load appropriate callee-save-method
429 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
430 ld $t1, 0($t1)
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100431 ld $t1, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET($t1)
Vladimir Marko952dbb12016-07-28 12:01:51 +0100432 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
433 # Place sp in Thread::Current()->top_quick_frame.
434 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
435.endm
436
Vladimir Marko7aa75602016-09-07 15:09:21 +0100437 /*
438 * Macro that sets up the callee save frame to conform with
439 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
440 * callee-save: $at + $v0-$v1 + $a0-$a7 + $t0-$t3 + $s0-$s7 + $t8-$t9 + $gp + $s8 + $ra + $s8,
441 * $f0-$f31; 28(GPR)+ 32(FPR) + 1x8 bytes padding + method*
442 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
443 */
444.macro SETUP_SAVE_EVERYTHING_FRAME
445 daddiu $sp, $sp, -(FRAME_SIZE_SAVE_EVERYTHING)
446 .cfi_adjust_cfa_offset (FRAME_SIZE_SAVE_EVERYTHING)
447 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
448.endm
449
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100450.macro RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +0100451 // Restore FP registers.
452 l.d $f31, 264($sp)
453 l.d $f30, 256($sp)
454 l.d $f29, 248($sp)
455 l.d $f28, 240($sp)
456 l.d $f27, 232($sp)
457 l.d $f26, 224($sp)
458 l.d $f25, 216($sp)
459 l.d $f24, 208($sp)
460 l.d $f23, 200($sp)
461 l.d $f22, 192($sp)
462 l.d $f21, 184($sp)
463 l.d $f20, 176($sp)
464 l.d $f19, 168($sp)
465 l.d $f18, 160($sp)
466 l.d $f17, 152($sp)
467 l.d $f16, 144($sp)
468 l.d $f15, 136($sp)
469 l.d $f14, 128($sp)
470 l.d $f13, 120($sp)
471 l.d $f12, 112($sp)
472 l.d $f11, 104($sp)
473 l.d $f10, 96($sp)
474 l.d $f9, 88($sp)
475 l.d $f8, 80($sp)
476 l.d $f7, 72($sp)
477 l.d $f6, 64($sp)
478 l.d $f5, 56($sp)
479 l.d $f4, 48($sp)
480 l.d $f3, 40($sp)
481 l.d $f2, 32($sp)
482 l.d $f1, 24($sp)
483 l.d $f0, 16($sp)
484
485 // Restore core registers.
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200486 .cpreturn
Vladimir Marko952dbb12016-07-28 12:01:51 +0100487 ld $ra, 488($sp)
488 .cfi_restore 31
489 ld $s8, 480($sp)
490 .cfi_restore 30
Vladimir Marko952dbb12016-07-28 12:01:51 +0100491 ld $t9, 464($sp)
492 .cfi_restore 25
493 ld $t8, 456($sp)
494 .cfi_restore 24
495 ld $s7, 448($sp)
496 .cfi_restore 23
497 ld $s6, 440($sp)
498 .cfi_restore 22
499 ld $s5, 432($sp)
500 .cfi_restore 21
501 ld $s4, 424($sp)
502 .cfi_restore 20
503 ld $s3, 416($sp)
504 .cfi_restore 19
505 ld $s2, 408($sp)
506 .cfi_restore 18
507 ld $s1, 400($sp)
508 .cfi_restore 17
509 ld $s0, 392($sp)
510 .cfi_restore 16
511 ld $t3, 384($sp)
512 .cfi_restore 15
513 ld $t2, 376($sp)
514 .cfi_restore 14
515 ld $t1, 368($sp)
516 .cfi_restore 13
517 ld $t0, 360($sp)
518 .cfi_restore 12
519 ld $a7, 352($sp)
520 .cfi_restore 11
521 ld $a6, 344($sp)
522 .cfi_restore 10
523 ld $a5, 336($sp)
524 .cfi_restore 9
525 ld $a4, 328($sp)
526 .cfi_restore 8
527 ld $a3, 320($sp)
528 .cfi_restore 7
529 ld $a2, 312($sp)
530 .cfi_restore 6
531 ld $a1, 304($sp)
532 .cfi_restore 5
533 ld $a0, 296($sp)
534 .cfi_restore 4
535 ld $v1, 288($sp)
536 .cfi_restore 3
537 ld $v0, 280($sp)
538 .cfi_restore 2
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200539 .set push
540 .set noat
Vladimir Marko952dbb12016-07-28 12:01:51 +0100541 ld $at, 272($sp)
542 .cfi_restore 1
Goran Jakovljevic2e42cf12016-08-09 15:15:39 +0200543 .set pop
Vladimir Marko952dbb12016-07-28 12:01:51 +0100544
Vladimir Marko952dbb12016-07-28 12:01:51 +0100545 daddiu $sp, $sp, 496
546 .cfi_adjust_cfa_offset -496
547.endm
548
549 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800550 * Macro that set calls through to artDeliverPendingExceptionFromCode,
551 * where the pending
552 * exception is Thread::Current()->exception_
553 */
554.macro DELIVER_PENDING_EXCEPTION
Goran Jakovljevic04568812015-04-23 15:27:23 +0200555 SETUP_GP
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100556 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME # save callee saves for throw
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800557 dla $t9, artDeliverPendingExceptionFromCode
558 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
559 move $a0, rSELF # pass Thread::Current
560.endm
561
562.macro RETURN_IF_NO_EXCEPTION
563 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100564 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800565 bne $t0, $zero, 1f # success if no exception is pending
566 nop
567 jalr $zero, $ra
568 nop
5691:
570 DELIVER_PENDING_EXCEPTION
571.endm
572
573.macro RETURN_IF_ZERO
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100574 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800575 bne $v0, $zero, 1f # success?
576 nop
577 jalr $zero, $ra # return on success
578 nop
5791:
580 DELIVER_PENDING_EXCEPTION
581.endm
582
583.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100584 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800585 beq $v0, $zero, 1f # success?
586 nop
587 jalr $zero, $ra # return on success
588 nop
5891:
590 DELIVER_PENDING_EXCEPTION
591.endm
592
593 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100594 * On stack replacement stub.
595 * On entry:
596 * a0 = stack to copy
597 * a1 = size of stack
598 * a2 = pc to call
599 * a3 = JValue* result
600 * a4 = shorty
601 * a5 = thread
602 */
603ENTRY art_quick_osr_stub
604 move $t0, $sp # save stack pointer
605 daddiu $t1, $sp, -112 # reserve stack space
606 dsrl $t1, $t1, 4 # enforce 16 byte stack alignment
607 dsll $sp, $t1, 4 # update stack pointer
608
609 // Save callee general purpose registers, SP, T8(GP), RA, A3, and A4 (8x14 bytes)
610 sd $ra, 104($sp)
611 .cfi_rel_offset 31, 104
612 sd $s8, 96($sp)
613 .cfi_rel_offset 30, 96
614 sd $t0, 88($sp) # save original stack pointer stored in t0
615 .cfi_rel_offset 29, 88
616 sd $t8, 80($sp) # t8 holds caller's gp, now save it to the stack.
617 .cfi_rel_offset 28, 80 # Value from gp is pushed, so set the cfi offset accordingly.
618 sd $s7, 72($sp)
619 .cfi_rel_offset 23, 72
620 sd $s6, 64($sp)
621 .cfi_rel_offset 22, 64
622 sd $s5, 56($sp)
623 .cfi_rel_offset 21, 56
624 sd $s4, 48($sp)
625 .cfi_rel_offset 20, 48
626 sd $s3, 40($sp)
627 .cfi_rel_offset 19, 40
628 sd $s2, 32($sp)
629 .cfi_rel_offset 18, 32
630 sd $s1, 24($sp)
631 .cfi_rel_offset 17, 24
632 sd $s0, 16($sp)
633 .cfi_rel_offset 16, 16
634 sd $a4, 8($sp)
635 .cfi_rel_offset 8, 8
636 sd $a3, 0($sp)
637 .cfi_rel_offset 7, 0
638 move rSELF, $a5 # Save managed thread pointer into rSELF
639
640 daddiu $sp, $sp, -16
641 jal .Losr_entry
642 sd $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
643 daddiu $sp, $sp, 16
644
645 // Restore return value address and shorty address
646 ld $a4, 8($sp) # shorty address
647 .cfi_restore 8
648 ld $a3, 0($sp) # result value address
649 .cfi_restore 7
650
651 lbu $t1, 0($a4) # load return type
652 li $t2, 'D' # put char 'D' into t2
653 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'D'
654 li $t2, 'F' # put char 'F' into t2
655 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'F'
656 nop
657 b .Losr_exit
658 dsrl $v1, $v0, 32 # put high half of result in v1
659.Losr_fp_result:
660 mfc1 $v0, $f0
661 mfhc1 $v1, $f0 # put high half of FP result in v1
662.Losr_exit:
663 sw $v0, 0($a3) # store low half of result
664 sw $v1, 4($a3) # store high half of result
665
666 // Restore callee registers
667 ld $ra, 104($sp)
668 .cfi_restore 31
669 ld $s8, 96($sp)
670 .cfi_restore 30
671 ld $t0, 88($sp) # save SP into t0 for now
672 .cfi_restore 29
673 ld $t8, 80($sp) # Restore gp back to it's temp storage.
674 .cfi_restore 28
675 ld $s7, 72($sp)
676 .cfi_restore 23
677 ld $s6, 64($sp)
678 .cfi_restore 22
679 ld $s5, 56($sp)
680 .cfi_restore 21
681 ld $s4, 48($sp)
682 .cfi_restore 20
683 ld $s3, 40($sp)
684 .cfi_restore 19
685 ld $s2, 32($sp)
686 .cfi_restore 18
687 ld $s1, 24($sp)
688 .cfi_restore 17
689 ld $s0, 16($sp)
690 .cfi_restore 16
691 jalr $zero, $ra
692 move $sp, $t0
693
694.Losr_entry:
695 dsubu $sp, $sp, $a1 # Reserve space for callee stack
696 daddiu $a1, $a1, -8
697 daddu $t0, $a1, $sp
698 sw $ra, 0($t0) # Store low half of RA per compiler ABI
699 dsrl $t1, $ra, 32
700 sw $t1, 4($t0) # Store high half of RA per compiler ABI
701
702 // Copy arguments into callee stack
703 // Use simple copy routine for now.
704 // 4 bytes per slot.
705 // a0 = source address
706 // a1 = args length in bytes (does not include 8 bytes for RA)
707 // sp = destination address
708 beqz $a1, .Losr_loop_exit
709 daddiu $a1, $a1, -4
710 daddu $t1, $a0, $a1
711 daddu $t2, $sp, $a1
712.Losr_loop_entry:
713 lw $t0, 0($t1)
714 daddiu $t1, $t1, -4
715 sw $t0, 0($t2)
716 bne $sp, $t2, .Losr_loop_entry
717 daddiu $t2, $t2, -4
718
719.Losr_loop_exit:
720 move $t9, $a2
721 jalr $zero, $t9 # Jump to the OSR entry point.
722 nop
723END art_quick_osr_stub
724
725 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800726 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
727 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
728 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200729ENTRY_NO_GP art_quick_do_long_jump
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800730 l.d $f0, 0($a1)
731 l.d $f1, 8($a1)
732 l.d $f2, 16($a1)
733 l.d $f3, 24($a1)
734 l.d $f4, 32($a1)
735 l.d $f5, 40($a1)
736 l.d $f6, 48($a1)
737 l.d $f7, 56($a1)
738 l.d $f8, 64($a1)
739 l.d $f9, 72($a1)
740 l.d $f10, 80($a1)
741 l.d $f11, 88($a1)
742 l.d $f12, 96($a1)
743 l.d $f13, 104($a1)
744 l.d $f14, 112($a1)
745 l.d $f15, 120($a1)
746 l.d $f16, 128($a1)
747 l.d $f17, 136($a1)
748 l.d $f18, 144($a1)
749 l.d $f19, 152($a1)
750 l.d $f20, 160($a1)
751 l.d $f21, 168($a1)
752 l.d $f22, 176($a1)
753 l.d $f23, 184($a1)
754 l.d $f24, 192($a1)
755 l.d $f25, 200($a1)
756 l.d $f26, 208($a1)
757 l.d $f27, 216($a1)
758 l.d $f28, 224($a1)
759 l.d $f29, 232($a1)
760 l.d $f30, 240($a1)
761 l.d $f31, 248($a1)
762 .set push
763 .set nomacro
764 .set noat
765# no need to load zero
766 ld $at, 8($a0)
767 .set pop
768 ld $v0, 16($a0)
769 ld $v1, 24($a0)
770# a0 has to be loaded last
771 ld $a1, 40($a0)
772 ld $a2, 48($a0)
773 ld $a3, 56($a0)
774 ld $a4, 64($a0)
775 ld $a5, 72($a0)
776 ld $a6, 80($a0)
777 ld $a7, 88($a0)
778 ld $t0, 96($a0)
779 ld $t1, 104($a0)
780 ld $t2, 112($a0)
781 ld $t3, 120($a0)
782 ld $s0, 128($a0)
783 ld $s1, 136($a0)
784 ld $s2, 144($a0)
785 ld $s3, 152($a0)
786 ld $s4, 160($a0)
787 ld $s5, 168($a0)
788 ld $s6, 176($a0)
789 ld $s7, 184($a0)
790 ld $t8, 192($a0)
791 ld $t9, 200($a0)
792# no need to load k0, k1
793 ld $gp, 224($a0)
794 ld $sp, 232($a0)
795 ld $s8, 240($a0)
796 ld $ra, 248($a0)
797 ld $a0, 32($a0)
798 move $v0, $zero # clear result registers v0 and v1
Andreas Gampedbf056d2015-09-25 08:24:13 -0700799 jalr $zero, $t9 # do long jump (do not use ra, it must not be clobbered)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800800 move $v1, $zero
801END art_quick_do_long_jump
802
Maja Gagic6ea651f2015-02-24 16:55:04 +0100803 /*
804 * Called by managed code, saves most registers (forms basis of long jump
805 * context) and passes the bottom of the stack.
806 * artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200807 * the bottom of the thread. On entry a0 holds Throwable*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100808 */
809ENTRY art_quick_deliver_exception
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100810 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100811 dla $t9, artDeliverExceptionFromCode
812 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
813 move $a1, rSELF # pass Thread::Current
814END art_quick_deliver_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800815
Maja Gagic6ea651f2015-02-24 16:55:04 +0100816 /*
817 * Called by managed code to create and deliver a NullPointerException
818 */
819 .extern artThrowNullPointerExceptionFromCode
820ENTRY art_quick_throw_null_pointer_exception
821.Lart_quick_throw_null_pointer_exception_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100822 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100823 dla $t9, artThrowNullPointerExceptionFromCode
824 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
825 move $a0, rSELF # pass Thread::Current
826END art_quick_throw_null_pointer_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800827
Maja Gagic6ea651f2015-02-24 16:55:04 +0100828 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100829 * Call installed by a signal handler to create and deliver a NullPointerException
830 */
831 .extern artThrowNullPointerExceptionFromSignal
Vladimir Marko7aa75602016-09-07 15:09:21 +0100832ENTRY_NO_GP_CUSTOM_CFA art_quick_throw_null_pointer_exception_from_signal, FRAME_SIZE_SAVE_EVERYTHING
833 SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP
834 # Retrieve the fault address from the padding where the signal handler stores it.
835 ld $a0, (__SIZEOF_POINTER__)($sp)
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100836 dla $t9, artThrowNullPointerExceptionFromSignal
837 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uinptr_t, Thread*)
838 move $a1, rSELF # pass Thread::Current
839END art_quick_throw_null_pointer_exception
840
841 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100842 * Called by managed code to create and deliver an ArithmeticException
843 */
844 .extern artThrowDivZeroFromCode
845ENTRY art_quick_throw_div_zero
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100846 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100847 dla $t9, artThrowDivZeroFromCode
848 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
849 move $a0, rSELF # pass Thread::Current
850END art_quick_throw_div_zero
851
852 /*
853 * Called by managed code to create and deliver an
854 * ArrayIndexOutOfBoundsException
855 */
856 .extern artThrowArrayBoundsFromCode
857ENTRY art_quick_throw_array_bounds
858.Lart_quick_throw_array_bounds_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100859 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100860 dla $t9, artThrowArrayBoundsFromCode
861 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
862 move $a2, rSELF # pass Thread::Current
863END art_quick_throw_array_bounds
864
865 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100866 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
867 * as if thrown from a call to String.charAt().
868 */
869 .extern artThrowStringBoundsFromCode
870ENTRY art_quick_throw_string_bounds
871.Lart_quick_throw_string_bounds_gp_set:
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100872 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100873 dla $t9, artThrowStringBoundsFromCode
874 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
875 move $a2, rSELF # pass Thread::Current
876END art_quick_throw_string_bounds
877
878 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100879 * Called by managed code to create and deliver a StackOverflowError.
880 */
881 .extern artThrowStackOverflowFromCode
882ENTRY art_quick_throw_stack_overflow
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100883 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100884 dla $t9, artThrowStackOverflowFromCode
885 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
886 move $a0, rSELF # pass Thread::Current
887END art_quick_throw_stack_overflow
888
889 /*
890 * Called by managed code to create and deliver a NoSuchMethodError.
891 */
892 .extern artThrowNoSuchMethodFromCode
893ENTRY art_quick_throw_no_such_method
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100894 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100895 dla $t9, artThrowNoSuchMethodFromCode
896 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
897 move $a1, rSELF # pass Thread::Current
898END art_quick_throw_no_such_method
899
900 /*
901 * All generated callsites for interface invokes and invocation slow paths will load arguments
902 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
903 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
904 * stack and call the appropriate C helper.
905 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
906 *
907 * The helper will attempt to locate the target and return a 128-bit result in $v0/$v1 consisting
908 * of the target Method* in $v0 and method->code_ in $v1.
909 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700910 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
Maja Gagic6ea651f2015-02-24 16:55:04 +0100911 * thread and we branch to another stub to deliver it.
912 *
913 * On success this wrapper will restore arguments and *jump* to the target, leaving the ra
914 * pointing back to the original caller.
915 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700916.macro INVOKE_TRAMPOLINE_BODY cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100917 .extern \cxx_name
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100918 SETUP_SAVE_REFS_AND_ARGS_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100919 move $a2, rSELF # pass Thread::Current
920 jal \cxx_name # (method_idx, this, Thread*, $sp)
921 move $a3, $sp # pass $sp
Maja Gagic6ea651f2015-02-24 16:55:04 +0100922 move $a0, $v0 # save target Method*
923 move $t9, $v1 # save $v0->code_
Vladimir Markofd36f1f2016-08-03 18:49:58 +0100924 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +0100925 beq $v0, $zero, 1f
926 nop
927 jalr $zero, $t9
928 nop
9291:
930 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700931.endm
932.macro INVOKE_TRAMPOLINE c_name, cxx_name
933ENTRY \c_name
934 INVOKE_TRAMPOLINE_BODY \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100935END \c_name
936.endm
937
Maja Gagic6ea651f2015-02-24 16:55:04 +0100938INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
939
940INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
941INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
942INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
943INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800944
945 # On entry:
946 # t0 = shorty
947 # t1 = ptr to arg_array
948 # t2 = number of argument bytes remain
949 # v0 = ptr to stack frame where to copy arg_array
950 # This macro modifies t3, t9 and v0
951.macro LOOP_OVER_SHORTY_LOADING_REG gpu, fpu, label
952 lbu $t3, 0($t0) # get argument type from shorty
953 beqz $t3, \label
954 daddiu $t0, 1
955 li $t9, 68 # put char 'D' into t9
956 beq $t9, $t3, 1f # branch if result type char == 'D'
957 li $t9, 70 # put char 'F' into t9
958 beq $t9, $t3, 2f # branch if result type char == 'F'
959 li $t9, 74 # put char 'J' into t9
960 beq $t9, $t3, 3f # branch if result type char == 'J'
961 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +0100962 lw $\gpu, 0($t1)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800963 sw $\gpu, 0($v0)
964 daddiu $v0, 4
965 daddiu $t1, 4
966 b 4f
967 daddiu $t2, -4 # delay slot
968
9691: # found double
970 lwu $t3, 0($t1)
971 mtc1 $t3, $\fpu
972 sw $t3, 0($v0)
973 lwu $t3, 4($t1)
974 mthc1 $t3, $\fpu
975 sw $t3, 4($v0)
976 daddiu $v0, 8
977 daddiu $t1, 8
978 b 4f
979 daddiu $t2, -8 # delay slot
980
9812: # found float
982 lwu $t3, 0($t1)
983 mtc1 $t3, $\fpu
984 sw $t3, 0($v0)
985 daddiu $v0, 4
986 daddiu $t1, 4
987 b 4f
988 daddiu $t2, -4 # delay slot
989
9903: # found long (8 bytes)
991 lwu $t3, 0($t1)
992 sw $t3, 0($v0)
993 lwu $t9, 4($t1)
994 sw $t9, 4($v0)
995 dsll $t9, $t9, 32
996 or $\gpu, $t9, $t3
997 daddiu $v0, 8
998 daddiu $t1, 8
999 daddiu $t2, -8
10004:
1001.endm
1002
1003 /*
1004 * Invocation stub for quick code.
1005 * On entry:
1006 * a0 = method pointer
1007 * a1 = argument array that must at least contain the this ptr.
1008 * a2 = size of argument array in bytes
1009 * a3 = (managed) thread pointer
1010 * a4 = JValue* result
1011 * a5 = shorty
1012 */
Goran Jakovljevic04568812015-04-23 15:27:23 +02001013ENTRY_NO_GP art_quick_invoke_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001014 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra onto the stack
1015 daddiu $sp, $sp, -48
1016 .cfi_adjust_cfa_offset 48
1017 sd $ra, 40($sp)
1018 .cfi_rel_offset 31, 40
1019 sd $s8, 32($sp)
1020 .cfi_rel_offset 30, 32
1021 sd $s1, 24($sp)
1022 .cfi_rel_offset 17, 24
1023 sd $s0, 16($sp)
1024 .cfi_rel_offset 16, 16
1025 sd $a5, 8($sp)
1026 .cfi_rel_offset 9, 8
1027 sd $a4, 0($sp)
1028 .cfi_rel_offset 8, 0
1029
1030 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1031 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1032 move $s8, $sp # save sp in s8 (fp)
1033
Mathieu Chartiere401d142015-04-22 13:56:20 -07001034 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001035 dsrl $t3, $t3, 4 # shift the frame size right 4
1036 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1037 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1038
1039 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1040 daddiu $t1, $a1, 4 # t1 = ptr to arg_array[4] (skip this ptr)
1041 daddiu $t2, $a2, -4 # t2 = number of argument bytes remain (skip this ptr)
Nikola Veljkovic80f7a572015-06-02 17:27:53 +02001042 daddiu $v0, $sp, 12 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001043 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_fn
1044 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_fn
1045 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_fn
1046 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_fn
1047 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_fn
1048 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_fn
1049
1050 # copy arguments onto stack (t2 should be multiples of 4)
1051 ble $t2, $zero, call_fn # t2 = number of argument bytes remain
10521:
1053 lw $t3, 0($t1) # load from argument array
1054 daddiu $t1, $t1, 4
1055 sw $t3, 0($v0) # save to stack
1056 daddiu $t2, -4
1057 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1058 daddiu $v0, $v0, 4
1059
1060call_fn:
1061 # call method (a0 and a1 have been untouched)
1062 lwu $a1, 0($a1) # make a1 = this ptr
Mathieu Chartiere401d142015-04-22 13:56:20 -07001063 sw $a1, 8($sp) # copy this ptr (skip 8 bytes for ArtMethod*)
1064 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1065 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001066 jalr $t9 # call the method
1067 nop
1068 move $sp, $s8 # restore sp
1069
1070 # pop a4, a5, s1(rSELF), s8, ra off of the stack
1071 ld $a4, 0($sp)
1072 .cfi_restore 8
1073 ld $a5, 8($sp)
1074 .cfi_restore 9
1075 ld $s0, 16($sp)
1076 .cfi_restore 16
1077 ld $s1, 24($sp)
1078 .cfi_restore 17
1079 ld $s8, 32($sp)
1080 .cfi_restore 30
1081 ld $ra, 40($sp)
1082 .cfi_restore 31
1083 daddiu $sp, $sp, 48
1084 .cfi_adjust_cfa_offset -48
1085
1086 # a4 = JValue* result
1087 # a5 = shorty string
1088 lbu $t1, 0($a5) # get result type from shorty
1089 li $t2, 68 # put char 'D' into t2
1090 beq $t1, $t2, 1f # branch if result type char == 'D'
1091 li $t3, 70 # put char 'F' into t3
1092 beq $t1, $t3, 1f # branch if result type char == 'F'
1093 sw $v0, 0($a4) # store the result
1094 dsrl $v1, $v0, 32
1095 jalr $zero, $ra
1096 sw $v1, 4($a4) # store the other half of the result
10971:
1098 mfc1 $v0, $f0
1099 mfhc1 $v1, $f0
1100 sw $v0, 0($a4) # store the result
1101 jalr $zero, $ra
1102 sw $v1, 4($a4) # store the other half of the result
1103END art_quick_invoke_stub
1104
1105 /*
1106 * Invocation static stub for quick code.
1107 * On entry:
1108 * a0 = method pointer
1109 * a1 = argument array that must at least contain the this ptr.
1110 * a2 = size of argument array in bytes
1111 * a3 = (managed) thread pointer
1112 * a4 = JValue* result
1113 * a5 = shorty
1114 */
Goran Jakovljevic04568812015-04-23 15:27:23 +02001115ENTRY_NO_GP art_quick_invoke_static_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001116
1117 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra, onto the stack
1118 daddiu $sp, $sp, -48
1119 .cfi_adjust_cfa_offset 48
1120 sd $ra, 40($sp)
1121 .cfi_rel_offset 31, 40
1122 sd $s8, 32($sp)
1123 .cfi_rel_offset 30, 32
1124 sd $s1, 24($sp)
1125 .cfi_rel_offset 17, 24
1126 sd $s0, 16($sp)
1127 .cfi_rel_offset 16, 16
1128 sd $a5, 8($sp)
1129 .cfi_rel_offset 9, 8
1130 sd $a4, 0($sp)
1131 .cfi_rel_offset 8, 0
1132
1133 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1134 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1135 move $s8, $sp # save sp in s8 (fp)
1136
Mathieu Chartiere401d142015-04-22 13:56:20 -07001137 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001138 dsrl $t3, $t3, 4 # shift the frame size right 4
1139 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1140 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1141
1142 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1143 move $t1, $a1 # t1 = arg_array
1144 move $t2, $a2 # t2 = number of argument bytes remain
Mathieu Chartiere401d142015-04-22 13:56:20 -07001145 daddiu $v0, $sp, 8 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001146 LOOP_OVER_SHORTY_LOADING_REG a1, f13, call_sfn
1147 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_sfn
1148 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_sfn
1149 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_sfn
1150 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_sfn
1151 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_sfn
1152 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_sfn
1153
1154 # copy arguments onto stack (t2 should be multiples of 4)
1155 ble $t2, $zero, call_sfn # t2 = number of argument bytes remain
11561:
1157 lw $t3, 0($t1) # load from argument array
1158 daddiu $t1, $t1, 4
1159 sw $t3, 0($v0) # save to stack
1160 daddiu $t2, -4
1161 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1162 daddiu $v0, $v0, 4
1163
1164call_sfn:
1165 # call method (a0 has been untouched)
Mathieu Chartiere401d142015-04-22 13:56:20 -07001166 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1167 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001168 jalr $t9 # call the method
1169 nop
1170 move $sp, $s8 # restore sp
1171
1172 # pop a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra off of the stack
1173 ld $a4, 0($sp)
1174 .cfi_restore 8
1175 ld $a5, 8($sp)
1176 .cfi_restore 9
1177 ld $s0, 16($sp)
1178 .cfi_restore 16
1179 ld $s1, 24($sp)
1180 .cfi_restore 17
1181 ld $s8, 32($sp)
1182 .cfi_restore 30
1183 ld $ra, 40($sp)
1184 .cfi_restore 31
1185 daddiu $sp, $sp, 48
1186 .cfi_adjust_cfa_offset -48
1187
1188 # a4 = JValue* result
1189 # a5 = shorty string
1190 lbu $t1, 0($a5) # get result type from shorty
1191 li $t2, 68 # put char 'D' into t2
1192 beq $t1, $t2, 1f # branch if result type char == 'D'
1193 li $t3, 70 # put char 'F' into t3
1194 beq $t1, $t3, 1f # branch if result type char == 'F'
1195 sw $v0, 0($a4) # store the result
1196 dsrl $v1, $v0, 32
1197 jalr $zero, $ra
1198 sw $v1, 4($a4) # store the other half of the result
11991:
1200 mfc1 $v0, $f0
1201 mfhc1 $v1, $f0
1202 sw $v0, 0($a4) # store the result
1203 jalr $zero, $ra
1204 sw $v1, 4($a4) # store the other half of the result
1205END art_quick_invoke_static_stub
1206
Maja Gagic6ea651f2015-02-24 16:55:04 +01001207 /*
1208 * Entry from managed code that calls artHandleFillArrayDataFromCode and
1209 * delivers exception on failure.
1210 */
1211 .extern artHandleFillArrayDataFromCode
1212ENTRY art_quick_handle_fill_data
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001213 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
1214 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001215 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*)
1216 move $a3, rSELF # pass Thread::Current
1217 RETURN_IF_ZERO
1218END art_quick_handle_fill_data
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001219
Maja Gagic6ea651f2015-02-24 16:55:04 +01001220 /*
1221 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
1222 */
1223 .extern artLockObjectFromCode
1224ENTRY art_quick_lock_object
1225 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1226 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001227 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Maja Gagic6ea651f2015-02-24 16:55:04 +01001228 jal artLockObjectFromCode # (Object* obj, Thread*)
1229 move $a1, rSELF # pass Thread::Current
1230 RETURN_IF_ZERO
1231END art_quick_lock_object
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001232
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001233ENTRY art_quick_lock_object_no_inline
1234 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1235 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001236 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case we block
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001237 jal artLockObjectFromCode # (Object* obj, Thread*)
1238 move $a1, rSELF # pass Thread::Current
1239 RETURN_IF_ZERO
1240END art_quick_lock_object_no_inline
1241
Maja Gagic6ea651f2015-02-24 16:55:04 +01001242 /*
1243 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1244 */
1245 .extern artUnlockObjectFromCode
1246ENTRY art_quick_unlock_object
1247 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1248 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001249 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001250 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1251 move $a1, rSELF # pass Thread::Current
1252 RETURN_IF_ZERO
1253END art_quick_unlock_object
1254
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001255ENTRY art_quick_unlock_object_no_inline
1256 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1257 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001258 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case exception allocation triggers GC
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001259 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1260 move $a1, rSELF # pass Thread::Current
1261 RETURN_IF_ZERO
1262END art_quick_unlock_object_no_inline
1263
Maja Gagic6ea651f2015-02-24 16:55:04 +01001264 /*
1265 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1266 */
1267 .extern artThrowClassCastException
1268ENTRY art_quick_check_cast
1269 daddiu $sp, $sp, -32
1270 .cfi_adjust_cfa_offset 32
1271 sd $ra, 24($sp)
1272 .cfi_rel_offset 31, 24
1273 sd $t9, 16($sp)
1274 sd $a1, 8($sp)
1275 sd $a0, 0($sp)
1276 jal artIsAssignableFromCode
Goran Jakovljevic04568812015-04-23 15:27:23 +02001277 .cpreturn # Restore gp from t8 in branch delay slot.
1278 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001279 beq $v0, $zero, .Lthrow_class_cast_exception
1280 ld $ra, 24($sp)
1281 jalr $zero, $ra
1282 daddiu $sp, $sp, 32
1283 .cfi_adjust_cfa_offset -32
1284.Lthrow_class_cast_exception:
1285 ld $t9, 16($sp)
1286 ld $a1, 8($sp)
1287 ld $a0, 0($sp)
1288 daddiu $sp, $sp, 32
1289 .cfi_adjust_cfa_offset -32
Goran Jakovljevic04568812015-04-23 15:27:23 +02001290 SETUP_GP
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001291 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01001292 dla $t9, artThrowClassCastException
1293 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
1294 move $a2, rSELF # pass Thread::Current
1295END art_quick_check_cast
1296
Man Cao1aee9002015-07-14 22:31:42 -07001297
1298 /*
1299 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1300 * nReg is the register number for rReg.
1301 */
1302.macro POP_REG_NE rReg, nReg, offset, rExclude
1303 .ifnc \rReg, \rExclude
1304 ld \rReg, \offset($sp) # restore rReg
1305 .cfi_restore \nReg
1306 .endif
1307.endm
1308
1309 /*
1310 * Macro to insert read barrier, only used in art_quick_aput_obj.
1311 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1312 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1313 */
1314.macro READ_BARRIER rDest, rObj, offset
1315#ifdef USE_READ_BARRIER
1316 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 16B-aligned.
1317 daddiu $sp, $sp, -64
1318 .cfi_adjust_cfa_offset 64
1319 sd $ra, 56($sp)
1320 .cfi_rel_offset 31, 56
1321 sd $t9, 48($sp)
1322 .cfi_rel_offset 25, 48
1323 sd $t1, 40($sp)
1324 .cfi_rel_offset 13, 40
1325 sd $t0, 32($sp)
1326 .cfi_rel_offset 12, 32
1327 sd $a2, 16($sp) # padding slot at offset 24 (padding can be any slot in the 64B)
1328 .cfi_rel_offset 6, 16
1329 sd $a1, 8($sp)
1330 .cfi_rel_offset 5, 8
1331 sd $a0, 0($sp)
1332 .cfi_rel_offset 4, 0
1333
Man Cao63069212015-08-21 15:51:39 -07001334 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001335 .ifnc \rObj, $a1
1336 move $a1, \rObj # pass rObj
1337 .endif
1338 daddiu $a2, $zero, \offset # pass offset
1339 jal artReadBarrierSlow # artReadBarrierSlow(ref, rObj, offset)
1340 .cpreturn # Restore gp from t8 in branch delay slot.
1341 # t8 may be clobbered in artReadBarrierSlow.
1342 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1343 move \rDest, $v0 # save return value in rDest
1344 # (rDest cannot be v0 in art_quick_aput_obj)
1345
1346 ld $a0, 0($sp) # restore registers except rDest
1347 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1348 .cfi_restore 4
1349 ld $a1, 8($sp)
1350 .cfi_restore 5
1351 ld $a2, 16($sp)
1352 .cfi_restore 6
1353 POP_REG_NE $t0, 12, 32, \rDest
1354 POP_REG_NE $t1, 13, 40, \rDest
1355 ld $t9, 48($sp)
1356 .cfi_restore 25
1357 ld $ra, 56($sp) # restore $ra
1358 .cfi_restore 31
1359 daddiu $sp, $sp, 64
1360 .cfi_adjust_cfa_offset -64
1361 SETUP_GP # set up gp because we are not returning
1362#else
1363 lwu \rDest, \offset(\rObj)
1364 UNPOISON_HEAP_REF \rDest
1365#endif // USE_READ_BARRIER
1366.endm
1367
Maja Gagic6ea651f2015-02-24 16:55:04 +01001368 /*
1369 * Entry from managed code for array put operations of objects where the value being stored
1370 * needs to be checked for compatibility.
1371 * a0 = array, a1 = index, a2 = value
1372 */
1373ENTRY art_quick_aput_obj_with_null_and_bound_check
1374 bne $a0, $zero, .Lart_quick_aput_obj_with_bound_check_gp_set
1375 nop
1376 b .Lart_quick_throw_null_pointer_exception_gp_set
1377 nop
1378END art_quick_aput_obj_with_null_and_bound_check
1379
1380ENTRY art_quick_aput_obj_with_bound_check
1381 lwu $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
1382 sltu $t1, $a1, $t0
1383 bne $t1, $zero, .Lart_quick_aput_obj_gp_set
1384 nop
1385 move $a0, $a1
1386 b .Lart_quick_throw_array_bounds_gp_set
1387 move $a1, $t0
1388END art_quick_aput_obj_with_bound_check
1389
1390ENTRY art_quick_aput_obj
1391 beq $a2, $zero, .Ldo_aput_null
1392 nop
Man Cao1aee9002015-07-14 22:31:42 -07001393 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1394 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1395 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Maja Gagic6ea651f2015-02-24 16:55:04 +01001396 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
1397 nop
1398.Ldo_aput:
1399 dsll $a1, $a1, 2
1400 daddu $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001401 POISON_HEAP_REF $a2
Maja Gagic6ea651f2015-02-24 16:55:04 +01001402 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1403 ld $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1404 dsrl $t1, $a0, 7
1405 daddu $t1, $t1, $t0
1406 sb $t0, ($t1)
1407 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001408 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001409.Ldo_aput_null:
1410 dsll $a1, $a1, 2
1411 daddu $t0, $a0, $a1
1412 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1413 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001414 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001415.Lcheck_assignability:
1416 daddiu $sp, $sp, -64
1417 .cfi_adjust_cfa_offset 64
1418 sd $ra, 56($sp)
1419 .cfi_rel_offset 31, 56
1420 sd $t9, 24($sp)
1421 sd $a2, 16($sp)
1422 sd $a1, 8($sp)
1423 sd $a0, 0($sp)
1424 move $a1, $t1
1425 move $a0, $t0
1426 jal artIsAssignableFromCode # (Class*, Class*)
Goran Jakovljevic04568812015-04-23 15:27:23 +02001427 .cpreturn # Restore gp from t8 in branch delay slot.
1428 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001429 ld $ra, 56($sp)
1430 ld $t9, 24($sp)
1431 ld $a2, 16($sp)
1432 ld $a1, 8($sp)
1433 ld $a0, 0($sp)
1434 daddiu $sp, $sp, 64
1435 .cfi_adjust_cfa_offset -64
Goran Jakovljevic04568812015-04-23 15:27:23 +02001436 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001437 bne $v0, $zero, .Ldo_aput
1438 nop
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001439 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01001440 move $a1, $a2
1441 dla $t9, artThrowArrayStoreException
1442 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
1443 move $a2, rSELF # pass Thread::Current
1444END art_quick_aput_obj
1445
1446 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001447 * Called by managed code to resolve a static field and load a boolean primitive value.
1448 */
1449 .extern artGetBooleanStaticFromCode
1450ENTRY art_quick_get_boolean_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001451 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1452 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001453 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1454 move $a2, rSELF # pass Thread::Current
1455 RETURN_IF_NO_EXCEPTION
1456END art_quick_get_boolean_static
1457
1458 /*
1459 * Called by managed code to resolve a static field and load a byte primitive value.
1460 */
1461 .extern artGetByteStaticFromCode
1462ENTRY art_quick_get_byte_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001463 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1464 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001465 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1466 move $a2, rSELF # pass Thread::Current
1467 RETURN_IF_NO_EXCEPTION
1468END art_quick_get_byte_static
1469
1470 /*
1471 * Called by managed code to resolve a static field and load a char primitive value.
1472 */
1473 .extern artGetCharStaticFromCode
1474ENTRY art_quick_get_char_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001475 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1476 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001477 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1478 move $a2, rSELF # pass Thread::Current
1479 RETURN_IF_NO_EXCEPTION
1480END art_quick_get_char_static
1481
1482 /*
1483 * Called by managed code to resolve a static field and load a short primitive value.
1484 */
1485 .extern artGetShortStaticFromCode
1486ENTRY art_quick_get_short_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001487 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1488 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001489 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1490 move $a2, rSELF # pass Thread::Current
1491 RETURN_IF_NO_EXCEPTION
1492END art_quick_get_short_static
1493
1494 /*
1495 * Called by managed code to resolve a static field and load a 32-bit primitive value.
1496 */
1497 .extern artGet32StaticFromCode
1498ENTRY art_quick_get32_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001499 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1500 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001501 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1502 move $a2, rSELF # pass Thread::Current
1503 RETURN_IF_NO_EXCEPTION
1504END art_quick_get32_static
1505
1506 /*
1507 * Called by managed code to resolve a static field and load a 64-bit primitive value.
1508 */
1509 .extern artGet64StaticFromCode
1510ENTRY art_quick_get64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001511 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1512 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001513 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1514 move $a2, rSELF # pass Thread::Current
1515 RETURN_IF_NO_EXCEPTION
1516END art_quick_get64_static
1517
1518 /*
1519 * Called by managed code to resolve a static field and load an object reference.
1520 */
1521 .extern artGetObjStaticFromCode
1522ENTRY art_quick_get_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001523 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1524 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001525 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1526 move $a2, rSELF # pass Thread::Current
1527 RETURN_IF_NO_EXCEPTION
1528END art_quick_get_obj_static
1529
1530 /*
1531 * Called by managed code to resolve an instance field and load a boolean primitive value.
1532 */
1533 .extern artGetBooleanInstanceFromCode
1534ENTRY art_quick_get_boolean_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001535 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1536 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001537 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1538 move $a3, rSELF # pass Thread::Current
1539 RETURN_IF_NO_EXCEPTION
1540END art_quick_get_boolean_instance
1541
1542 /*
1543 * Called by managed code to resolve an instance field and load a byte primitive value.
1544 */
1545 .extern artGetByteInstanceFromCode
1546ENTRY art_quick_get_byte_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001547 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1548 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001549 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1550 move $a3, rSELF # pass Thread::Current
1551 RETURN_IF_NO_EXCEPTION
1552END art_quick_get_byte_instance
1553
1554 /*
1555 * Called by managed code to resolve an instance field and load a char primitive value.
1556 */
1557 .extern artGetCharInstanceFromCode
1558ENTRY art_quick_get_char_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001559 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1560 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001561 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1562 move $a3, rSELF # pass Thread::Current
1563 RETURN_IF_NO_EXCEPTION
1564END art_quick_get_char_instance
1565
1566 /*
1567 * Called by managed code to resolve an instance field and load a short primitive value.
1568 */
1569 .extern artGetShortInstanceFromCode
1570ENTRY art_quick_get_short_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001571 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1572 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001573 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1574 move $a3, rSELF # pass Thread::Current
1575 RETURN_IF_NO_EXCEPTION
1576END art_quick_get_short_instance
1577
1578 /*
1579 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1580 */
1581 .extern artGet32InstanceFromCode
1582ENTRY art_quick_get32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001583 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1584 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001585 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1586 move $a3, rSELF # pass Thread::Current
1587 RETURN_IF_NO_EXCEPTION
1588END art_quick_get32_instance
1589
1590 /*
1591 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1592 */
1593 .extern artGet64InstanceFromCode
1594ENTRY art_quick_get64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001595 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1596 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001597 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1598 move $a3, rSELF # pass Thread::Current
1599 RETURN_IF_NO_EXCEPTION
1600END art_quick_get64_instance
1601
1602 /*
1603 * Called by managed code to resolve an instance field and load an object reference.
1604 */
1605 .extern artGetObjInstanceFromCode
1606ENTRY art_quick_get_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001607 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1608 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001609 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1610 move $a3, rSELF # pass Thread::Current
1611 RETURN_IF_NO_EXCEPTION
1612END art_quick_get_obj_instance
1613
1614 /*
1615 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1616 */
1617 .extern artSet8StaticFromCode
1618ENTRY art_quick_set8_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001619 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1620 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001621 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
1622 move $a3, rSELF # pass Thread::Current
1623 RETURN_IF_ZERO
1624END art_quick_set8_static
1625
1626 /*
1627 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1628 */
1629 .extern artSet16StaticFromCode
1630ENTRY art_quick_set16_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001631 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1632 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001633 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*)
1634 move $a3, rSELF # pass Thread::Current
1635 RETURN_IF_ZERO
1636END art_quick_set16_static
1637
1638 /*
1639 * Called by managed code to resolve a static field and store a 32-bit primitive value.
1640 */
1641 .extern artSet32StaticFromCode
1642ENTRY art_quick_set32_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001643 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1644 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001645 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
1646 move $a3, rSELF # pass Thread::Current
1647 RETURN_IF_ZERO
1648END art_quick_set32_static
1649
1650 /*
1651 * Called by managed code to resolve a static field and store a 64-bit primitive value.
1652 */
1653 .extern artSet64StaticFromCode
1654ENTRY art_quick_set64_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001655 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001656 # a2 contains the new val
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001657 ld $a1, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001658 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
1659 move $a3, rSELF # pass Thread::Current
1660 RETURN_IF_ZERO
1661END art_quick_set64_static
1662
1663 /*
1664 * Called by managed code to resolve a static field and store an object reference.
1665 */
1666 .extern artSetObjStaticFromCode
1667ENTRY art_quick_set_obj_static
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001668 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1669 ld $a2, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001670 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
1671 move $a3, rSELF # pass Thread::Current
1672 RETURN_IF_ZERO
1673END art_quick_set_obj_static
1674
1675 /*
1676 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1677 */
1678 .extern artSet8InstanceFromCode
1679ENTRY art_quick_set8_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001680 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1681 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001682 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1683 move $a4, rSELF # pass Thread::Current
1684 RETURN_IF_ZERO
1685END art_quick_set8_instance
1686
1687 /*
1688 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1689 */
1690 .extern artSet16InstanceFromCode
1691ENTRY art_quick_set16_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001692 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1693 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001694 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1695 move $a4, rSELF # pass Thread::Current
1696 RETURN_IF_ZERO
1697END art_quick_set16_instance
1698
1699 /*
1700 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1701 */
1702 .extern artSet32InstanceFromCode
1703ENTRY art_quick_set32_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001704 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1705 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001706 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1707 move $a4, rSELF # pass Thread::Current
1708 RETURN_IF_ZERO
1709END art_quick_set32_instance
1710
1711 /*
1712 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1713 */
1714 .extern artSet64InstanceFromCode
1715ENTRY art_quick_set64_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001716 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1717 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001718 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1719 move $a4, rSELF # pass Thread::Current
1720 RETURN_IF_ZERO
1721END art_quick_set64_instance
1722
1723 /*
1724 * Called by managed code to resolve an instance field and store an object reference.
1725 */
1726 .extern artSetObjInstanceFromCode
1727ENTRY art_quick_set_obj_instance
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001728 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
1729 ld $a3, FRAME_SIZE_SAVE_REFS_ONLY($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001730 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1731 move $a4, rSELF # pass Thread::Current
1732 RETURN_IF_ZERO
1733END art_quick_set_obj_instance
1734
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001735// Macro to facilitate adding new allocation entrypoints.
1736.macro ONE_ARG_DOWNCALL name, entrypoint, return
1737 .extern \entrypoint
1738ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001739 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001740 jal \entrypoint
1741 move $a1, rSELF # pass Thread::Current
1742 \return
1743END \name
1744.endm
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001745
1746// Macro to facilitate adding new allocation entrypoints.
1747.macro TWO_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001748 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001749ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001750 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001751 jal \entrypoint
1752 move $a2, rSELF # pass Thread::Current
1753 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001754END \name
1755.endm
1756
1757.macro THREE_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001758 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001759ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001760 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Maja Gagic6ea651f2015-02-24 16:55:04 +01001761 jal \entrypoint
1762 move $a3, rSELF # pass Thread::Current
1763 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001764END \name
1765.endm
1766
Vladimir Markoe85e1232015-04-28 14:14:58 +01001767.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1768 .extern \entrypoint
1769ENTRY \name
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001770 SETUP_SAVE_REFS_ONLY_FRAME # save callee saves in case of GC
Vladimir Markoe85e1232015-04-28 14:14:58 +01001771 jal \entrypoint
1772 move $a4, rSELF # pass Thread::Current
1773 \return
1774END \name
1775.endm
1776
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001777// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001778GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001779
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001780// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1781ENTRY art_quick_alloc_object_rosalloc
1782
1783 # Fast path rosalloc allocation
1784 # a0: type_idx
1785 # a1: ArtMethod*
1786 # s1: Thread::Current
1787 # -----------------------------
1788 # t0: class
1789 # t1: object size
1790 # t2: rosalloc run
1791 # t3: thread stack top offset
1792 # a4: thread stack bottom offset
1793 # v0: free list head
1794 #
1795 # a5, a6 : temps
1796
1797 ld $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_64($a1) # Load dex cache resolved types array.
1798
1799 dsll $a5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1800 daddu $a5, $t0, $a5 # Compute the index.
1801 lwu $t0, 0($a5) # Load class (t0).
1802 beqzc $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1803
1804 li $a6, MIRROR_CLASS_STATUS_INITIALIZED
1805 lwu $a5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1806 bnec $a5, $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1807
1808 # Add a fake dependence from the following access flag and size loads to the status load. This
1809 # is to prevent those loads from being reordered above the status load and reading wrong values.
1810 xor $a5, $a5, $a5
1811 daddu $t0, $t0, $a5
1812
1813 lwu $a5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1814 li $a6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1815 and $a6, $a5, $a6
1816 bnezc $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1817
1818 ld $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation stack
1819 ld $a4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # has any room left.
1820 bgeuc $t3, $a4, .Lart_quick_alloc_object_rosalloc_slow_path
1821
1822 lwu $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1823 li $a5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1824 # allocation.
1825 bltuc $a5, $t1, .Lart_quick_alloc_object_rosalloc_slow_path
1826
1827 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1828 # quantum size and divide by the quantum size and subtract by 1.
1829 daddiu $t1, $t1, -1 # Decrease obj size and shift right by
1830 dsrl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # quantum.
1831
1832 dsll $t2, $t1, POINTER_SIZE_SHIFT
1833 daddu $t2, $t2, $s1
1834 ld $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1835
1836 # Load the free list head (v0).
1837 # NOTE: this will be the return val.
1838 ld $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1839 beqzc $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1840
1841 # Load the next pointer of the head and update the list head with the next pointer.
1842 ld $a5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1843 sd $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1844
1845 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1846 # asserted to match.
1847
1848#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1849#error "Class pointer needs to overwrite next pointer."
1850#endif
1851
1852 POISON_HEAP_REF $t0
1853 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1854
1855 # Push the new object onto the thread local allocation stack and increment the thread local
1856 # allocation stack top.
1857 sd $v0, 0($t3)
1858 daddiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1859 sd $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1860
1861 # Decrement the size of the free list.
1862 lw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1863 addiu $a5, $a5, -1
1864 sw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1865
1866 sync # Fence.
1867
1868 jalr $zero, $ra
1869 .cpreturn # Restore gp from t8 in branch delay slot.
1870
1871.Lart_quick_alloc_object_rosalloc_slow_path:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001872 SETUP_SAVE_REFS_ONLY_FRAME
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001873 jal artAllocObjectFromCodeRosAlloc
1874 move $a2 ,$s1 # Pass self as argument.
1875 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1876
1877END art_quick_alloc_object_rosalloc
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001878
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001879GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1880GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1881
Maja Gagic6ea651f2015-02-24 16:55:04 +01001882 /*
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001883 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1884 * exception on error. On success the String is returned. A0 holds the string index. The fast
1885 * path check for hit in strings cache has already been performed.
1886 */
1887ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1888
1889 /*
1890 * Entry from managed code when uninitialized static storage, this stub will run the class
1891 * initializer and deliver the exception on error. On success the static storage base is
1892 * returned.
1893 */
1894ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1895
1896 /*
1897 * Entry from managed code when dex cache misses for a type_idx.
1898 */
1899ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1900
1901 /*
1902 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1903 * miss.
1904 */
1905ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1906
1907 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001908 * Called by managed code when the value in rSUSPEND has been decremented to 0.
1909 */
1910 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001911ENTRY_NO_GP art_quick_test_suspend
1912 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1913 bne rSUSPEND, $zero, 1f
Maja Gagic6ea651f2015-02-24 16:55:04 +01001914 daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1915 jalr $zero, $ra
Vladimir Marko952dbb12016-07-28 12:01:51 +01001916 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +010019171:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001918 SETUP_SAVE_EVERYTHING_FRAME # save everything for stack crawl
Maja Gagic6ea651f2015-02-24 16:55:04 +01001919 jal artTestSuspendFromCode # (Thread*)
1920 move $a0, rSELF
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001921 RESTORE_SAVE_EVERYTHING_FRAME
Vladimir Marko952dbb12016-07-28 12:01:51 +01001922 jalr $zero, $ra
1923 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +01001924END art_quick_test_suspend
Douglas Leung6461d192015-01-30 18:13:58 -08001925
1926 /*
1927 * Called by managed code that is attempting to call a method on a proxy class. On entry
1928 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1929 */
1930 .extern artQuickProxyInvokeHandler
1931ENTRY art_quick_proxy_invoke_handler
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001932 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Douglas Leung6461d192015-01-30 18:13:58 -08001933 move $a2, rSELF # pass Thread::Current
1934 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
1935 move $a3, $sp # pass $sp
1936 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1937 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001938 RESTORE_SAVE_REFS_ONLY_FRAME
Douglas Leung6461d192015-01-30 18:13:58 -08001939 bne $t0, $zero, 1f
1940 dmtc1 $v0, $f0 # place return value to FP return value
1941 jalr $zero, $ra
1942 dmtc1 $v1, $f1 # place return value to FP return value
19431:
1944 DELIVER_PENDING_EXCEPTION
1945END art_quick_proxy_invoke_handler
1946
Maja Gagic6ea651f2015-02-24 16:55:04 +01001947 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001948 * Called to resolve an imt conflict.
1949 * a0 is the conflict ArtMethod.
1950 * t0 is a hidden argument that holds the target interface method's dex method index.
1951 *
1952 * Mote that this stub writes to a0, t0 and t1.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001953 */
1954ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001955 ld $t1, 0($sp) # Load referrer.
1956 ld $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_64($t1) # Load dex cache methods array.
1957 dsll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1958 daddu $t0, $t1, $t0 # Add offset to base.
1959 ld $t0, 0($t0) # Load interface method.
1960 ld $a0, ART_METHOD_JNI_OFFSET_64($a0) # Load ImtConflictTable.
1961
1962.Limt_table_iterate:
1963 ld $t1, 0($a0) # Load next entry in ImtConflictTable.
1964 # Branch if found.
1965 beq $t1, $t0, .Limt_table_found
1966 nop
1967 # If the entry is null, the interface method is not in the ImtConflictTable.
1968 beqzc $t1, .Lconflict_trampoline
1969 # Iterate over the entries of the ImtConflictTable.
1970 daddiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1971 bc .Limt_table_iterate
1972
1973.Limt_table_found:
1974 # We successfully hit an entry in the table. Load the target method and jump to it.
1975 ld $a0, __SIZEOF_POINTER__($a0)
1976 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)
1977 jr $t9
1978 .cpreturn # Restore gp from t8 in branch delay slot.
1979
1980.Lconflict_trampoline:
1981 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001982 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Maja Gagic6ea651f2015-02-24 16:55:04 +01001983END art_quick_imt_conflict_trampoline
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001984
1985 .extern artQuickResolutionTrampoline
1986ENTRY art_quick_resolution_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001987 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001988 move $a2, rSELF # pass Thread::Current
1989 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
1990 move $a3, $sp # pass $sp
1991 beq $v0, $zero, 1f
Mathieu Chartiere401d142015-04-22 13:56:20 -07001992 ld $a0, 0($sp) # load resolved method in $a0
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001993 # artQuickResolutionTrampoline puts resolved method in *SP
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001994 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001995 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
1996 jalr $zero, $t9 # tail call to method
1997 nop
19981:
Vladimir Markofd36f1f2016-08-03 18:49:58 +01001999 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampecc7c39d2015-01-30 17:04:45 -08002000 DELIVER_PENDING_EXCEPTION
2001END art_quick_resolution_trampoline
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002002
2003 .extern artQuickGenericJniTrampoline
2004 .extern artQuickGenericJniEndTrampoline
2005ENTRY art_quick_generic_jni_trampoline
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002006 SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_A0
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002007 move $s8, $sp # save $sp
2008
2009 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
2010 move $a0, rSELF # pass Thread::Current
2011 move $a1, $sp # pass $sp
2012 jal artQuickGenericJniTrampoline # (Thread*, SP)
2013 daddiu $sp, $sp, -5120 # reserve space on the stack
2014
2015 # The C call will have registered the complete save-frame on success.
2016 # The result of the call is:
2017 # v0: ptr to native code, 0 on error.
2018 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
2019 beq $v0, $zero, 1f # check entry error
2020 move $t9, $v0 # save the code ptr
2021 move $sp, $v1 # release part of the alloca
2022
2023 # Load parameters from stack into registers
2024 ld $a0, 0($sp)
2025 ld $a1, 8($sp)
2026 ld $a2, 16($sp)
2027 ld $a3, 24($sp)
2028 ld $a4, 32($sp)
2029 ld $a5, 40($sp)
2030 ld $a6, 48($sp)
2031 ld $a7, 56($sp)
2032 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
2033 l.d $f12, 0($sp)
2034 l.d $f13, 8($sp)
2035 l.d $f14, 16($sp)
2036 l.d $f15, 24($sp)
2037 l.d $f16, 32($sp)
2038 l.d $f17, 40($sp)
2039 l.d $f18, 48($sp)
2040 l.d $f19, 56($sp)
2041 jalr $t9 # native call
2042 daddiu $sp, $sp, 64
2043
2044 # result sign extension is handled in C code
2045 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
2046 move $a0, rSELF # pass Thread::Current
2047 move $a1, $v0
2048 jal artQuickGenericJniEndTrampoline
2049 dmfc1 $a2, $f0
2050
2051 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002052 bne $t0, $zero, 1f # check for pending exceptions
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002053 move $sp, $s8 # tear down the alloca
2054
2055 # tear dpown the callee-save frame
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002056 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002057
2058 jalr $zero, $ra
2059 dmtc1 $v0, $f0 # place return value to FP return value
2060
20611:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002062 ld $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2063 # This will create a new save-all frame, required by the runtime.
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002064 DELIVER_PENDING_EXCEPTION
2065END art_quick_generic_jni_trampoline
2066
2067 .extern artQuickToInterpreterBridge
2068ENTRY art_quick_to_interpreter_bridge
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002069 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002070 move $a1, rSELF # pass Thread::Current
2071 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
2072 move $a2, $sp # pass $sp
2073 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
2074 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002075 RESTORE_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002076 bne $t0, $zero, 1f
2077 dmtc1 $v0, $f0 # place return value to FP return value
2078 jalr $zero, $ra
2079 dmtc1 $v1, $f1 # place return value to FP return value
20801:
2081 DELIVER_PENDING_EXCEPTION
2082END art_quick_to_interpreter_bridge
2083
2084 /*
2085 * Routine that intercepts method calls and returns.
2086 */
2087 .extern artInstrumentationMethodEntryFromCode
2088 .extern artInstrumentationMethodExitFromCode
2089ENTRY art_quick_instrumentation_entry
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002090 SETUP_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002091 daddiu $sp, $sp, -16 # space for saving arg0
2092 .cfi_adjust_cfa_offset 16
2093 sd $a0, 0($sp) # save arg0
2094 move $a3, $ra # pass $ra
2095 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, RA)
2096 move $a2, rSELF # pass Thread::Current
2097 move $t9, $v0 # $t9 holds reference to code
2098 ld $a0, 0($sp) # restore arg0
2099 daddiu $sp, $sp, 16 # remove args
2100 .cfi_adjust_cfa_offset -16
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002101 RESTORE_SAVE_REFS_AND_ARGS_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002102 jalr $t9 # call method
2103 nop
2104END art_quick_instrumentation_entry
2105 /* intentional fallthrough */
2106 .global art_quick_instrumentation_exit
2107art_quick_instrumentation_exit:
2108 .cfi_startproc
Goran Jakovljevic04568812015-04-23 15:27:23 +02002109 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002110 move $ra, $zero # link register is to here, so clobber with 0 for later checks
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002111 SETUP_SAVE_REFS_ONLY_FRAME
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002112 move $t0, $sp # remember bottom of caller's frame
2113 daddiu $sp, $sp, -16 # save return values and set up args
2114 .cfi_adjust_cfa_offset 16
2115 sd $v0, 0($sp)
2116 .cfi_rel_offset 2, 0
2117 s.d $f0, 8($sp)
2118 mov.d $f15, $f0 # pass fpr result
2119 move $a2, $v0 # pass gpr result
2120 move $a1, $t0 # pass $sp
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002121 move $a0, rSELF # pass Thread::Current
Goran Jakovljevic04568812015-04-23 15:27:23 +02002122 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
2123 .cpreturn # Restore gp from t8 in branch delay slot. gp is not used anymore,
2124 # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
2125
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002126 move $t9, $v0 # set aside returned link register
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002127 move $ra, $v1 # set link register for deoptimization
2128 ld $v0, 0($sp) # restore return values
2129 l.d $f0, 8($sp)
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002130 jalr $zero, $t9 # return
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002131 # restore stack, 16 bytes of saved values + ref_only callee save frame
2132 daddiu $sp, $sp, 16+FRAME_SIZE_SAVE_REFS_ONLY
2133 .cfi_adjust_cfa_offset -(16+FRAME_SIZE_SAVE_REFS_ONLY)
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002134END art_quick_instrumentation_exit
2135
Maja Gagic6ea651f2015-02-24 16:55:04 +01002136 /*
2137 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2138 * will long jump to the upcall with a special exception of -1.
2139 */
2140 .extern artDeoptimize
2141 .extern artEnterInterpreterFromDeoptimize
2142ENTRY art_quick_deoptimize
Vladimir Markofd36f1f2016-08-03 18:49:58 +01002143 SETUP_SAVE_ALL_CALLEE_SAVES_FRAME
Maja Gagic6ea651f2015-02-24 16:55:04 +01002144 jal artDeoptimize # artDeoptimize(Thread*, SP)
2145 # Returns caller method's frame size.
2146 move $a0, rSELF # pass Thread::current
2147END art_quick_deoptimize
2148
Sebastien Hertz07474662015-08-25 15:12:33 +00002149 /*
2150 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2151 * will long jump to the upcall with a special exception of -1.
2152 */
2153 .extern artDeoptimizeFromCompiledCode
Vladimir Marko239d6ea2016-09-05 10:44:04 +01002154ENTRY_NO_GP art_quick_deoptimize_from_compiled_code
2155 SETUP_SAVE_EVERYTHING_FRAME
Sebastien Hertz07474662015-08-25 15:12:33 +00002156 jal artDeoptimizeFromCompiledCode # artDeoptimizeFromCompiledCode(Thread*, SP)
2157 # Returns caller method's frame size.
2158 move $a0, rSELF # pass Thread::current
2159END art_quick_deoptimize_from_compiled_code
2160
Chris Larsen9701c2e2015-09-04 17:22:47 -07002161 .set push
2162 .set noat
2163/* java.lang.String.compareTo(String anotherString) */
2164ENTRY_NO_GP art_quick_string_compareto
2165/* $a0 holds address of "this" */
2166/* $a1 holds address of "anotherString" */
2167 beq $a0,$a1,9f # this and anotherString are the same object
2168 move $v0,$zero
2169
2170 lw $a2,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2171 lw $a3,MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002172 MINu $t2, $a2, $a3
2173# $t2 now holds min(this.length(),anotherString.length())
Chris Larsen9701c2e2015-09-04 17:22:47 -07002174
2175 beqz $t2,9f # while min(this.length(),anotherString.length())-i != 0
2176 subu $v0,$a2,$a3 # if $t2==0 return
2177 # (this.length() - anotherString.length())
21781:
2179 lhu $t0,MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2180 lhu $t1,MIRROR_STRING_VALUE_OFFSET($a1)
2181 bne $t0,$t1,9f # if this.charAt(i) != anotherString.charAt(i)
2182 subu $v0,$t0,$t1 # return (this.charAt(i) - anotherString.charAt(i))
2183 daddiu $a0,$a0,2 # point at this.charAt(i++)
2184 subu $t2,$t2,1 # new value of
2185 # min(this.length(),anotherString.length())-i
2186 bnez $t2,1b
2187 daddiu $a1,$a1,2 # point at anotherString.charAt(i++)
2188 subu $v0,$a2,$a3
2189
21909:
2191 j $ra
2192 nop
2193END art_quick_string_compareto
2194
2195/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2196ENTRY_NO_GP art_quick_indexof
2197/* $a0 holds address of "this" */
Chris Larsencf283da2016-01-19 16:45:35 -08002198/* $a1 holds "ch" */
2199/* $a2 holds "fromIndex" */
Chris Larsen9701c2e2015-09-04 17:22:47 -07002200 lw $t0,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002201 slt $at, $a2, $zero # if fromIndex < 0
2202 seleqz $a2, $a2, $at # fromIndex = 0;
2203 subu $t0,$t0,$a2 # this.length() - fromIndex
2204 blez $t0,6f # if this.length()-fromIndex <= 0
Chris Larsen9701c2e2015-09-04 17:22:47 -07002205 li $v0,-1 # return -1;
2206
2207 sll $v0,$a2,1 # $a0 += $a2 * 2
2208 daddu $a0,$a0,$v0 # " " " " "
Chris Larsencf283da2016-01-19 16:45:35 -08002209 move $v0,$a2 # Set i to fromIndex.
Chris Larsen9701c2e2015-09-04 17:22:47 -07002210
22111:
2212 lhu $t3,MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2213 beq $t3,$a1,6f # return i;
2214 daddu $a0,$a0,2 # i++
2215 subu $t0,$t0,1 # this.length() - i
2216 bnez $t0,1b # while this.length() - i > 0
2217 addu $v0,$v0,1 # i++
2218
2219 li $v0,-1 # if this.length() - i <= 0
2220 # return -1;
2221
22226:
2223 j $ra
2224 nop
2225END art_quick_indexof
2226
2227 .set pop