blob: 0a379098f5b633deae531a0f5551997ed450f4d2 [file] [log] [blame]
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "asm_support_mips64.S"
18
19#include "arch/quick_alloc_entrypoints.S"
20
21 .set noreorder
22 .balign 16
23
24 /* Deliver the given exception */
25 .extern artDeliverExceptionFromCode
26 /* Deliver an exception pending on a thread */
27 .extern artDeliverPendingExceptionFromCode
28
29 /*
Goran Jakovljevic04568812015-04-23 15:27:23 +020030 * Macro that sets up $gp and stores the previous $gp value to $t8.
31 * This macro modifies v1 and t8.
32 */
33.macro SETUP_GP
34 move $v1, $ra
35 bal 1f
36 nop
371:
38 .cpsetup $ra, $t8, 1b
39 move $ra, $v1
40.endm
41
42 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -080043 * Macro that sets up the callee save frame to conform with
44 * Runtime::CreateCalleeSaveMethod(kSaveAll)
45 * callee-save: padding + $f24-$f31 + $s0-$s7 + $gp + $ra + $s8 = 19 total + 1x8 bytes padding
46 */
47.macro SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
48 daddiu $sp, $sp, -160
49 .cfi_adjust_cfa_offset 160
50
51 // Ugly compile-time check, but we only have the preprocessor.
52#if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVE != 160)
53#error "SAVE_ALL_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
54#endif
55
56 sd $ra, 152($sp)
57 .cfi_rel_offset 31, 152
58 sd $s8, 144($sp)
59 .cfi_rel_offset 30, 144
Goran Jakovljevic04568812015-04-23 15:27:23 +020060 sd $t8, 136($sp) # t8 holds caller's gp, now save it to the stack.
61 .cfi_rel_offset 28, 136 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080062 sd $s7, 128($sp)
63 .cfi_rel_offset 23, 128
64 sd $s6, 120($sp)
65 .cfi_rel_offset 22, 120
66 sd $s5, 112($sp)
67 .cfi_rel_offset 21, 112
68 sd $s4, 104($sp)
69 .cfi_rel_offset 20, 104
70 sd $s3, 96($sp)
71 .cfi_rel_offset 19, 96
72 sd $s2, 88($sp)
73 .cfi_rel_offset 18, 88
74 sd $s1, 80($sp)
75 .cfi_rel_offset 17, 80
76 sd $s0, 72($sp)
77 .cfi_rel_offset 16, 72
78
79 // FP callee-saves
80 s.d $f31, 64($sp)
81 s.d $f30, 56($sp)
82 s.d $f29, 48($sp)
83 s.d $f28, 40($sp)
84 s.d $f27, 32($sp)
85 s.d $f26, 24($sp)
86 s.d $f25, 16($sp)
87 s.d $f24, 8($sp)
88
89 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +020090 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
91 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +020092 ld $t1, RUNTIME_SAVE_ALL_CALLEE_SAVE_FRAME_OFFSET($t1)
93 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -080094 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
95.endm
96
97 /*
98 * Macro that sets up the callee save frame to conform with
99 * Runtime::CreateCalleeSaveMethod(kRefsOnly). Restoration assumes
100 * non-moving GC.
101 * Does not include rSUSPEND or rSELF
102 * callee-save: padding + $s2-$s7 + $gp + $ra + $s8 = 9 total + 1x8 bytes padding
103 */
104.macro SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
105 daddiu $sp, $sp, -80
106 .cfi_adjust_cfa_offset 80
107
108 // Ugly compile-time check, but we only have the preprocessor.
109#if (FRAME_SIZE_REFS_ONLY_CALLEE_SAVE != 80)
110#error "REFS_ONLY_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
111#endif
112
113 sd $ra, 72($sp)
114 .cfi_rel_offset 31, 72
115 sd $s8, 64($sp)
116 .cfi_rel_offset 30, 64
Goran Jakovljevic04568812015-04-23 15:27:23 +0200117 sd $t8, 56($sp) # t8 holds caller's gp, now save it to the stack.
118 .cfi_rel_offset 28, 56 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800119 sd $s7, 48($sp)
120 .cfi_rel_offset 23, 48
121 sd $s6, 40($sp)
122 .cfi_rel_offset 22, 40
123 sd $s5, 32($sp)
124 .cfi_rel_offset 21, 32
125 sd $s4, 24($sp)
126 .cfi_rel_offset 20, 24
127 sd $s3, 16($sp)
128 .cfi_rel_offset 19, 16
129 sd $s2, 8($sp)
130 .cfi_rel_offset 18, 8
131 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200132 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
133 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200134 ld $t1, RUNTIME_REFS_ONLY_CALLEE_SAVE_FRAME_OFFSET($t1)
135 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800136 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
137.endm
138
139.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
140 ld $ra, 72($sp)
141 .cfi_restore 31
142 ld $s8, 64($sp)
143 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200144 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800145 .cfi_restore 28
146 ld $s7, 48($sp)
147 .cfi_restore 23
148 ld $s6, 40($sp)
149 .cfi_restore 22
150 ld $s5, 32($sp)
151 .cfi_restore 21
152 ld $s4, 24($sp)
153 .cfi_restore 20
154 ld $s3, 16($sp)
155 .cfi_restore 19
156 ld $s2, 8($sp)
157 .cfi_restore 18
158 daddiu $sp, $sp, 80
159 .cfi_adjust_cfa_offset -80
Goran Jakovljevic04568812015-04-23 15:27:23 +0200160 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800161.endm
162
163.macro RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME_AND_RETURN
164 ld $ra, 72($sp)
165 .cfi_restore 31
166 ld $s8, 64($sp)
167 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200168 ld $t8, 56($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800169 .cfi_restore 28
170 ld $s7, 48($sp)
171 .cfi_restore 23
172 ld $s6, 40($sp)
173 .cfi_restore 22
174 ld $s5, 32($sp)
175 .cfi_restore 21
176 ld $s4, 24($sp)
177 .cfi_restore 20
178 ld $s3, 16($sp)
179 .cfi_restore 19
180 ld $s2, 8($sp)
181 .cfi_restore 18
Goran Jakovljevic04568812015-04-23 15:27:23 +0200182 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800183 jalr $zero, $ra
184 daddiu $sp, $sp, 80
185 .cfi_adjust_cfa_offset -80
186.endm
187
188// This assumes the top part of these stack frame types are identical.
189#define REFS_AND_ARGS_MINUS_REFS_SIZE (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE - FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
190
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800191.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
192 daddiu $sp, $sp, -208
193 .cfi_adjust_cfa_offset 208
194
195 // Ugly compile-time check, but we only have the preprocessor.
196#if (FRAME_SIZE_REFS_AND_ARGS_CALLEE_SAVE != 208)
197#error "REFS_AND_ARGS_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
198#endif
199
200 sd $ra, 200($sp) # = kQuickCalleeSaveFrame_RefAndArgs_LrOffset
201 .cfi_rel_offset 31, 200
202 sd $s8, 192($sp)
203 .cfi_rel_offset 30, 192
Goran Jakovljevic04568812015-04-23 15:27:23 +0200204 sd $t8, 184($sp) # t8 holds caller's gp, now save it to the stack.
205 .cfi_rel_offset 28, 184 # Value from gp is pushed, so set the cfi offset accordingly.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800206 sd $s7, 176($sp)
207 .cfi_rel_offset 23, 176
208 sd $s6, 168($sp)
209 .cfi_rel_offset 22, 168
210 sd $s5, 160($sp)
211 .cfi_rel_offset 21, 160
212 sd $s4, 152($sp)
213 .cfi_rel_offset 20, 152
214 sd $s3, 144($sp)
215 .cfi_rel_offset 19, 144
216 sd $s2, 136($sp)
217 .cfi_rel_offset 18, 136
218
219 sd $a7, 128($sp)
220 .cfi_rel_offset 11, 128
221 sd $a6, 120($sp)
222 .cfi_rel_offset 10, 120
223 sd $a5, 112($sp)
224 .cfi_rel_offset 9, 112
225 sd $a4, 104($sp)
226 .cfi_rel_offset 8, 104
227 sd $a3, 96($sp)
228 .cfi_rel_offset 7, 96
229 sd $a2, 88($sp)
230 .cfi_rel_offset 6, 88
231 sd $a1, 80($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset
232 .cfi_rel_offset 5, 80
233
234 s.d $f19, 72($sp)
235 s.d $f18, 64($sp)
236 s.d $f17, 56($sp)
237 s.d $f16, 48($sp)
238 s.d $f15, 40($sp)
239 s.d $f14, 32($sp)
240 s.d $f13, 24($sp) # = kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset
241 s.d $f12, 16($sp) # This isn't necessary to store.
Douglas Leung8223b802015-04-28 17:22:29 -0700242 # 1x8 bytes padding + Method*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800243.endm
244
Douglas Leung8223b802015-04-28 17:22:29 -0700245 /*
246 * Macro that sets up the callee save frame to conform with
247 * Runtime::CreateCalleeSaveMethod(kRefsAndArgs). Restoration assumes
248 * non-moving GC.
249 * callee-save: padding + $f12-$f19 + $a1-$a7 + $s2-$s7 + $gp + $ra + $s8 = 24 total + 1 words padding + Method*
250 */
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800251.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
252 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
253 # load appropriate callee-save-method
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200254 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
255 ld $t1, 0($t1)
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200256 ld $t1, RUNTIME_REFS_AND_ARGS_CALLEE_SAVE_FRAME_OFFSET($t1)
257 sd $t1, 0($sp) # Place Method* at bottom of stack.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800258 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
259.endm
260
Douglas Leung8223b802015-04-28 17:22:29 -0700261.macro SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
262 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_INTERNAL
Mathieu Chartiere401d142015-04-22 13:56:20 -0700263 sd $a0, 0($sp) # Place Method* at bottom of stack.
Douglas Leung8223b802015-04-28 17:22:29 -0700264 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF) # Place sp in Thread::Current()->top_quick_frame.
265.endm
266
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800267.macro RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
268 ld $ra, 200($sp)
269 .cfi_restore 31
270 ld $s8, 192($sp)
271 .cfi_restore 30
Goran Jakovljevic04568812015-04-23 15:27:23 +0200272 ld $t8, 184($sp) # Restore gp back to it's temp storage.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800273 .cfi_restore 28
274 ld $s7, 176($sp)
275 .cfi_restore 23
276 ld $s6, 168($sp)
277 .cfi_restore 22
278 ld $s5, 160($sp)
279 .cfi_restore 21
280 ld $s4, 152($sp)
281 .cfi_restore 20
282 ld $s3, 144($sp)
283 .cfi_restore 19
284 ld $s2, 136($sp)
285 .cfi_restore 18
286
287 ld $a7, 128($sp)
288 .cfi_restore 11
289 ld $a6, 120($sp)
290 .cfi_restore 10
291 ld $a5, 112($sp)
292 .cfi_restore 9
293 ld $a4, 104($sp)
294 .cfi_restore 8
295 ld $a3, 96($sp)
296 .cfi_restore 7
297 ld $a2, 88($sp)
298 .cfi_restore 6
299 ld $a1, 80($sp)
300 .cfi_restore 5
301
302 l.d $f19, 72($sp)
303 l.d $f18, 64($sp)
304 l.d $f17, 56($sp)
305 l.d $f16, 48($sp)
306 l.d $f15, 40($sp)
307 l.d $f14, 32($sp)
308 l.d $f13, 24($sp)
309 l.d $f12, 16($sp)
310
Goran Jakovljevic04568812015-04-23 15:27:23 +0200311 .cpreturn
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800312 daddiu $sp, $sp, 208
313 .cfi_adjust_cfa_offset -208
314.endm
315
316 /*
Vladimir Marko952dbb12016-07-28 12:01:51 +0100317 * Macro that sets up the callee save frame to conform with
318 * Runtime::CreateCalleeSaveMethod(kSaveEverything).
319 * callee-save: $at + $v0-$v1 + $a0-$a7 + $t0-$t3 + $s0-$s7 + $t8-$t9 + $gp + $s8 + $ra + $s8,
320 * $f0-$f31; 28(GPR)+ 32(FPR) + 1x8 bytes padding + method*
321 * This macro sets up $gp; entrypoints using it should start with ENTRY_NO_GP.
322 */
323.macro SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME
324 daddiu $sp, $sp, -496
325 .cfi_adjust_cfa_offset 496
326
327 // Ugly compile-time check, but we only have the preprocessor.
328#if (FRAME_SIZE_SAVE_EVERYTHING_CALLEE_SAVE != 496)
329#error "SAVE_EVERYTHING_CALLEE_SAVE_FRAME(MIPS64) size not as expected."
330#endif
331
332 // Save core registers.
333 sd $ra, 488($sp)
334 .cfi_rel_offset 31, 488
335 sd $s8, 480($sp)
336 .cfi_rel_offset 30, 480
337 sd $gp, 472($sp)
338 .cfi_rel_offset 28, 472
339 sd $t9, 464($sp)
340 .cfi_rel_offset 25, 464
341 sd $t8, 456($sp)
342 .cfi_rel_offset 24, 456
343 sd $s7, 448($sp)
344 .cfi_rel_offset 23, 448
345 sd $s6, 440($sp)
346 .cfi_rel_offset 22, 440
347 sd $s5, 432($sp)
348 .cfi_rel_offset 21, 432
349 sd $s4, 424($sp)
350 .cfi_rel_offset 20, 424
351 sd $s3, 416($sp)
352 .cfi_rel_offset 19, 416
353 sd $s2, 408($sp)
354 .cfi_rel_offset 18, 408
355 sd $s1, 400($sp)
356 .cfi_rel_offset 17, 400
357 sd $s0, 392($sp)
358 .cfi_rel_offset 16, 392
359 sd $t3, 384($sp)
360 .cfi_rel_offset 15, 384
361 sd $t2, 376($sp)
362 .cfi_rel_offset 14, 376
363 sd $t1, 368($sp)
364 .cfi_rel_offset 13, 368
365 sd $t0, 360($sp)
366 .cfi_rel_offset 12, 360
367 sd $a7, 352($sp)
368 .cfi_rel_offset 11, 352
369 sd $a6, 344($sp)
370 .cfi_rel_offset 10, 344
371 sd $a5, 336($sp)
372 .cfi_rel_offset 9, 336
373 sd $a4, 328($sp)
374 .cfi_rel_offset 8, 328
375 sd $a3, 320($sp)
376 .cfi_rel_offset 7, 320
377 sd $a2, 312($sp)
378 .cfi_rel_offset 6, 312
379 sd $a1, 304($sp)
380 .cfi_rel_offset 5, 304
381 sd $a0, 296($sp)
382 .cfi_rel_offset 4, 296
383 sd $v1, 288($sp)
384 .cfi_rel_offset 3, 288
385 sd $v0, 280($sp)
386 .cfi_rel_offset 2, 280
387
388 // Set up $gp, clobbering $ra and using the branch delay slot for a useful instruction.
389 bal 1f
390 sd $at, 272($sp)
391 .cfi_rel_offset 1, 272
3921:
393 // TODO: Can we avoid the unnecessary move $t8<-$gp?
394 .cpsetup $ra, $t8, 1b
395
396 // Save FP registers.
397 s.d $f31, 264($sp)
398 s.d $f30, 256($sp)
399 s.d $f29, 248($sp)
400 s.d $f28, 240($sp)
401 s.d $f27, 232($sp)
402 s.d $f26, 224($sp)
403 s.d $f25, 216($sp)
404 s.d $f24, 208($sp)
405 s.d $f23, 200($sp)
406 s.d $f22, 192($sp)
407 s.d $f21, 184($sp)
408 s.d $f20, 176($sp)
409 s.d $f19, 168($sp)
410 s.d $f18, 160($sp)
411 s.d $f17, 152($sp)
412 s.d $f16, 144($sp)
413 s.d $f15, 136($sp)
414 s.d $f14, 128($sp)
415 s.d $f13, 120($sp)
416 s.d $f12, 112($sp)
417 s.d $f11, 104($sp)
418 s.d $f10, 96($sp)
419 s.d $f9, 88($sp)
420 s.d $f8, 80($sp)
421 s.d $f7, 72($sp)
422 s.d $f6, 64($sp)
423 s.d $f5, 56($sp)
424 s.d $f4, 48($sp)
425 s.d $f3, 40($sp)
426 s.d $f2, 32($sp)
427 s.d $f1, 24($sp)
428 s.d $f0, 16($sp)
429
430 # load appropriate callee-save-method
431 ld $t1, %got(_ZN3art7Runtime9instance_E)($gp)
432 ld $t1, 0($t1)
433 ld $t1, RUNTIME_SAVE_EVERYTHING_CALLEE_SAVE_FRAME_OFFSET($t1)
434 sd $t1, 0($sp) # Place ArtMethod* at bottom of stack.
435 # Place sp in Thread::Current()->top_quick_frame.
436 sd $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
437.endm
438
439.macro RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME
440 // Restore FP registers.
441 l.d $f31, 264($sp)
442 l.d $f30, 256($sp)
443 l.d $f29, 248($sp)
444 l.d $f28, 240($sp)
445 l.d $f27, 232($sp)
446 l.d $f26, 224($sp)
447 l.d $f25, 216($sp)
448 l.d $f24, 208($sp)
449 l.d $f23, 200($sp)
450 l.d $f22, 192($sp)
451 l.d $f21, 184($sp)
452 l.d $f20, 176($sp)
453 l.d $f19, 168($sp)
454 l.d $f18, 160($sp)
455 l.d $f17, 152($sp)
456 l.d $f16, 144($sp)
457 l.d $f15, 136($sp)
458 l.d $f14, 128($sp)
459 l.d $f13, 120($sp)
460 l.d $f12, 112($sp)
461 l.d $f11, 104($sp)
462 l.d $f10, 96($sp)
463 l.d $f9, 88($sp)
464 l.d $f8, 80($sp)
465 l.d $f7, 72($sp)
466 l.d $f6, 64($sp)
467 l.d $f5, 56($sp)
468 l.d $f4, 48($sp)
469 l.d $f3, 40($sp)
470 l.d $f2, 32($sp)
471 l.d $f1, 24($sp)
472 l.d $f0, 16($sp)
473
474 // Restore core registers.
475 ld $ra, 488($sp)
476 .cfi_restore 31
477 ld $s8, 480($sp)
478 .cfi_restore 30
479 ld $gp, 472($sp)
480 .cfi_restore 28
481 ld $t9, 464($sp)
482 .cfi_restore 25
483 ld $t8, 456($sp)
484 .cfi_restore 24
485 ld $s7, 448($sp)
486 .cfi_restore 23
487 ld $s6, 440($sp)
488 .cfi_restore 22
489 ld $s5, 432($sp)
490 .cfi_restore 21
491 ld $s4, 424($sp)
492 .cfi_restore 20
493 ld $s3, 416($sp)
494 .cfi_restore 19
495 ld $s2, 408($sp)
496 .cfi_restore 18
497 ld $s1, 400($sp)
498 .cfi_restore 17
499 ld $s0, 392($sp)
500 .cfi_restore 16
501 ld $t3, 384($sp)
502 .cfi_restore 15
503 ld $t2, 376($sp)
504 .cfi_restore 14
505 ld $t1, 368($sp)
506 .cfi_restore 13
507 ld $t0, 360($sp)
508 .cfi_restore 12
509 ld $a7, 352($sp)
510 .cfi_restore 11
511 ld $a6, 344($sp)
512 .cfi_restore 10
513 ld $a5, 336($sp)
514 .cfi_restore 9
515 ld $a4, 328($sp)
516 .cfi_restore 8
517 ld $a3, 320($sp)
518 .cfi_restore 7
519 ld $a2, 312($sp)
520 .cfi_restore 6
521 ld $a1, 304($sp)
522 .cfi_restore 5
523 ld $a0, 296($sp)
524 .cfi_restore 4
525 ld $v1, 288($sp)
526 .cfi_restore 3
527 ld $v0, 280($sp)
528 .cfi_restore 2
529 ld $at, 272($sp)
530 .cfi_restore 1
531
532 .cpreturn
533 daddiu $sp, $sp, 496
534 .cfi_adjust_cfa_offset -496
535.endm
536
537 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800538 * Macro that set calls through to artDeliverPendingExceptionFromCode,
539 * where the pending
540 * exception is Thread::Current()->exception_
541 */
542.macro DELIVER_PENDING_EXCEPTION
Goran Jakovljevic04568812015-04-23 15:27:23 +0200543 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800544 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME # save callee saves for throw
545 dla $t9, artDeliverPendingExceptionFromCode
546 jalr $zero, $t9 # artDeliverPendingExceptionFromCode(Thread*)
547 move $a0, rSELF # pass Thread::Current
548.endm
549
550.macro RETURN_IF_NO_EXCEPTION
551 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
552 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
553 bne $t0, $zero, 1f # success if no exception is pending
554 nop
555 jalr $zero, $ra
556 nop
5571:
558 DELIVER_PENDING_EXCEPTION
559.endm
560
561.macro RETURN_IF_ZERO
562 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
563 bne $v0, $zero, 1f # success?
564 nop
565 jalr $zero, $ra # return on success
566 nop
5671:
568 DELIVER_PENDING_EXCEPTION
569.endm
570
571.macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
572 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
573 beq $v0, $zero, 1f # success?
574 nop
575 jalr $zero, $ra # return on success
576 nop
5771:
578 DELIVER_PENDING_EXCEPTION
579.endm
580
581 /*
Goran Jakovljevic3bc13812016-03-22 17:16:05 +0100582 * On stack replacement stub.
583 * On entry:
584 * a0 = stack to copy
585 * a1 = size of stack
586 * a2 = pc to call
587 * a3 = JValue* result
588 * a4 = shorty
589 * a5 = thread
590 */
591ENTRY art_quick_osr_stub
592 move $t0, $sp # save stack pointer
593 daddiu $t1, $sp, -112 # reserve stack space
594 dsrl $t1, $t1, 4 # enforce 16 byte stack alignment
595 dsll $sp, $t1, 4 # update stack pointer
596
597 // Save callee general purpose registers, SP, T8(GP), RA, A3, and A4 (8x14 bytes)
598 sd $ra, 104($sp)
599 .cfi_rel_offset 31, 104
600 sd $s8, 96($sp)
601 .cfi_rel_offset 30, 96
602 sd $t0, 88($sp) # save original stack pointer stored in t0
603 .cfi_rel_offset 29, 88
604 sd $t8, 80($sp) # t8 holds caller's gp, now save it to the stack.
605 .cfi_rel_offset 28, 80 # Value from gp is pushed, so set the cfi offset accordingly.
606 sd $s7, 72($sp)
607 .cfi_rel_offset 23, 72
608 sd $s6, 64($sp)
609 .cfi_rel_offset 22, 64
610 sd $s5, 56($sp)
611 .cfi_rel_offset 21, 56
612 sd $s4, 48($sp)
613 .cfi_rel_offset 20, 48
614 sd $s3, 40($sp)
615 .cfi_rel_offset 19, 40
616 sd $s2, 32($sp)
617 .cfi_rel_offset 18, 32
618 sd $s1, 24($sp)
619 .cfi_rel_offset 17, 24
620 sd $s0, 16($sp)
621 .cfi_rel_offset 16, 16
622 sd $a4, 8($sp)
623 .cfi_rel_offset 8, 8
624 sd $a3, 0($sp)
625 .cfi_rel_offset 7, 0
626 move rSELF, $a5 # Save managed thread pointer into rSELF
627
628 daddiu $sp, $sp, -16
629 jal .Losr_entry
630 sd $zero, 0($sp) # Store null for ArtMethod* at bottom of frame
631 daddiu $sp, $sp, 16
632
633 // Restore return value address and shorty address
634 ld $a4, 8($sp) # shorty address
635 .cfi_restore 8
636 ld $a3, 0($sp) # result value address
637 .cfi_restore 7
638
639 lbu $t1, 0($a4) # load return type
640 li $t2, 'D' # put char 'D' into t2
641 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'D'
642 li $t2, 'F' # put char 'F' into t2
643 beq $t1, $t2, .Losr_fp_result # branch if result type char == 'F'
644 nop
645 b .Losr_exit
646 dsrl $v1, $v0, 32 # put high half of result in v1
647.Losr_fp_result:
648 mfc1 $v0, $f0
649 mfhc1 $v1, $f0 # put high half of FP result in v1
650.Losr_exit:
651 sw $v0, 0($a3) # store low half of result
652 sw $v1, 4($a3) # store high half of result
653
654 // Restore callee registers
655 ld $ra, 104($sp)
656 .cfi_restore 31
657 ld $s8, 96($sp)
658 .cfi_restore 30
659 ld $t0, 88($sp) # save SP into t0 for now
660 .cfi_restore 29
661 ld $t8, 80($sp) # Restore gp back to it's temp storage.
662 .cfi_restore 28
663 ld $s7, 72($sp)
664 .cfi_restore 23
665 ld $s6, 64($sp)
666 .cfi_restore 22
667 ld $s5, 56($sp)
668 .cfi_restore 21
669 ld $s4, 48($sp)
670 .cfi_restore 20
671 ld $s3, 40($sp)
672 .cfi_restore 19
673 ld $s2, 32($sp)
674 .cfi_restore 18
675 ld $s1, 24($sp)
676 .cfi_restore 17
677 ld $s0, 16($sp)
678 .cfi_restore 16
679 jalr $zero, $ra
680 move $sp, $t0
681
682.Losr_entry:
683 dsubu $sp, $sp, $a1 # Reserve space for callee stack
684 daddiu $a1, $a1, -8
685 daddu $t0, $a1, $sp
686 sw $ra, 0($t0) # Store low half of RA per compiler ABI
687 dsrl $t1, $ra, 32
688 sw $t1, 4($t0) # Store high half of RA per compiler ABI
689
690 // Copy arguments into callee stack
691 // Use simple copy routine for now.
692 // 4 bytes per slot.
693 // a0 = source address
694 // a1 = args length in bytes (does not include 8 bytes for RA)
695 // sp = destination address
696 beqz $a1, .Losr_loop_exit
697 daddiu $a1, $a1, -4
698 daddu $t1, $a0, $a1
699 daddu $t2, $sp, $a1
700.Losr_loop_entry:
701 lw $t0, 0($t1)
702 daddiu $t1, $t1, -4
703 sw $t0, 0($t2)
704 bne $sp, $t2, .Losr_loop_entry
705 daddiu $t2, $t2, -4
706
707.Losr_loop_exit:
708 move $t9, $a2
709 jalr $zero, $t9 # Jump to the OSR entry point.
710 nop
711END art_quick_osr_stub
712
713 /*
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800714 * On entry $a0 is uint32_t* gprs_ and $a1 is uint32_t* fprs_
715 * FIXME: just guessing about the shape of the jmpbuf. Where will pc be?
716 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200717ENTRY_NO_GP art_quick_do_long_jump
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800718 l.d $f0, 0($a1)
719 l.d $f1, 8($a1)
720 l.d $f2, 16($a1)
721 l.d $f3, 24($a1)
722 l.d $f4, 32($a1)
723 l.d $f5, 40($a1)
724 l.d $f6, 48($a1)
725 l.d $f7, 56($a1)
726 l.d $f8, 64($a1)
727 l.d $f9, 72($a1)
728 l.d $f10, 80($a1)
729 l.d $f11, 88($a1)
730 l.d $f12, 96($a1)
731 l.d $f13, 104($a1)
732 l.d $f14, 112($a1)
733 l.d $f15, 120($a1)
734 l.d $f16, 128($a1)
735 l.d $f17, 136($a1)
736 l.d $f18, 144($a1)
737 l.d $f19, 152($a1)
738 l.d $f20, 160($a1)
739 l.d $f21, 168($a1)
740 l.d $f22, 176($a1)
741 l.d $f23, 184($a1)
742 l.d $f24, 192($a1)
743 l.d $f25, 200($a1)
744 l.d $f26, 208($a1)
745 l.d $f27, 216($a1)
746 l.d $f28, 224($a1)
747 l.d $f29, 232($a1)
748 l.d $f30, 240($a1)
749 l.d $f31, 248($a1)
750 .set push
751 .set nomacro
752 .set noat
753# no need to load zero
754 ld $at, 8($a0)
755 .set pop
756 ld $v0, 16($a0)
757 ld $v1, 24($a0)
758# a0 has to be loaded last
759 ld $a1, 40($a0)
760 ld $a2, 48($a0)
761 ld $a3, 56($a0)
762 ld $a4, 64($a0)
763 ld $a5, 72($a0)
764 ld $a6, 80($a0)
765 ld $a7, 88($a0)
766 ld $t0, 96($a0)
767 ld $t1, 104($a0)
768 ld $t2, 112($a0)
769 ld $t3, 120($a0)
770 ld $s0, 128($a0)
771 ld $s1, 136($a0)
772 ld $s2, 144($a0)
773 ld $s3, 152($a0)
774 ld $s4, 160($a0)
775 ld $s5, 168($a0)
776 ld $s6, 176($a0)
777 ld $s7, 184($a0)
778 ld $t8, 192($a0)
779 ld $t9, 200($a0)
780# no need to load k0, k1
781 ld $gp, 224($a0)
782 ld $sp, 232($a0)
783 ld $s8, 240($a0)
784 ld $ra, 248($a0)
785 ld $a0, 32($a0)
786 move $v0, $zero # clear result registers v0 and v1
Andreas Gampedbf056d2015-09-25 08:24:13 -0700787 jalr $zero, $t9 # do long jump (do not use ra, it must not be clobbered)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800788 move $v1, $zero
789END art_quick_do_long_jump
790
Maja Gagic6ea651f2015-02-24 16:55:04 +0100791 /*
792 * Called by managed code, saves most registers (forms basis of long jump
793 * context) and passes the bottom of the stack.
794 * artDeliverExceptionFromCode will place the callee save Method* at
Lazar Trsic84bc06e2015-06-10 16:05:46 +0200795 * the bottom of the thread. On entry a0 holds Throwable*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100796 */
797ENTRY art_quick_deliver_exception
798 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
799 dla $t9, artDeliverExceptionFromCode
800 jalr $zero, $t9 # artDeliverExceptionFromCode(Throwable*, Thread*)
801 move $a1, rSELF # pass Thread::Current
802END art_quick_deliver_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800803
Maja Gagic6ea651f2015-02-24 16:55:04 +0100804 /*
805 * Called by managed code to create and deliver a NullPointerException
806 */
807 .extern artThrowNullPointerExceptionFromCode
808ENTRY art_quick_throw_null_pointer_exception
809.Lart_quick_throw_null_pointer_exception_gp_set:
810 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
811 dla $t9, artThrowNullPointerExceptionFromCode
812 jalr $zero, $t9 # artThrowNullPointerExceptionFromCode(Thread*)
813 move $a0, rSELF # pass Thread::Current
814END art_quick_throw_null_pointer_exception
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800815
Maja Gagic6ea651f2015-02-24 16:55:04 +0100816 /*
Nicolas Geoffraye8e11272016-06-28 18:08:46 +0100817 * Call installed by a signal handler to create and deliver a NullPointerException
818 */
819 .extern artThrowNullPointerExceptionFromSignal
820ENTRY art_quick_throw_null_pointer_exception_from_signal
821 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
822 dla $t9, artThrowNullPointerExceptionFromSignal
823 jalr $zero, $t9 # artThrowNullPointerExceptionFromSignal(uinptr_t, Thread*)
824 move $a1, rSELF # pass Thread::Current
825END art_quick_throw_null_pointer_exception
826
827 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100828 * Called by managed code to create and deliver an ArithmeticException
829 */
830 .extern artThrowDivZeroFromCode
831ENTRY art_quick_throw_div_zero
832 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
833 dla $t9, artThrowDivZeroFromCode
834 jalr $zero, $t9 # artThrowDivZeroFromCode(Thread*)
835 move $a0, rSELF # pass Thread::Current
836END art_quick_throw_div_zero
837
838 /*
839 * Called by managed code to create and deliver an
840 * ArrayIndexOutOfBoundsException
841 */
842 .extern artThrowArrayBoundsFromCode
843ENTRY art_quick_throw_array_bounds
844.Lart_quick_throw_array_bounds_gp_set:
845 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
846 dla $t9, artThrowArrayBoundsFromCode
847 jalr $zero, $t9 # artThrowArrayBoundsFromCode(index, limit, Thread*)
848 move $a2, rSELF # pass Thread::Current
849END art_quick_throw_array_bounds
850
851 /*
Vladimir Marko87f3fcb2016-04-28 15:52:11 +0100852 * Called by managed code to create and deliver a StringIndexOutOfBoundsException
853 * as if thrown from a call to String.charAt().
854 */
855 .extern artThrowStringBoundsFromCode
856ENTRY art_quick_throw_string_bounds
857.Lart_quick_throw_string_bounds_gp_set:
858 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
859 dla $t9, artThrowStringBoundsFromCode
860 jalr $zero, $t9 # artThrowStringBoundsFromCode(index, limit, Thread*)
861 move $a2, rSELF # pass Thread::Current
862END art_quick_throw_string_bounds
863
864 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +0100865 * Called by managed code to create and deliver a StackOverflowError.
866 */
867 .extern artThrowStackOverflowFromCode
868ENTRY art_quick_throw_stack_overflow
869 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
870 dla $t9, artThrowStackOverflowFromCode
871 jalr $zero, $t9 # artThrowStackOverflowFromCode(Thread*)
872 move $a0, rSELF # pass Thread::Current
873END art_quick_throw_stack_overflow
874
875 /*
876 * Called by managed code to create and deliver a NoSuchMethodError.
877 */
878 .extern artThrowNoSuchMethodFromCode
879ENTRY art_quick_throw_no_such_method
880 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
881 dla $t9, artThrowNoSuchMethodFromCode
882 jalr $zero, $t9 # artThrowNoSuchMethodFromCode(method_idx, Thread*)
883 move $a1, rSELF # pass Thread::Current
884END art_quick_throw_no_such_method
885
886 /*
887 * All generated callsites for interface invokes and invocation slow paths will load arguments
888 * as usual - except instead of loading arg0/$a0 with the target Method*, arg0/$a0 will contain
889 * the method_idx. This wrapper will save arg1-arg3, load the caller's Method*, align the
890 * stack and call the appropriate C helper.
891 * NOTE: "this" is first visable argument of the target, and so can be found in arg1/$a1.
892 *
893 * The helper will attempt to locate the target and return a 128-bit result in $v0/$v1 consisting
894 * of the target Method* in $v0 and method->code_ in $v1.
895 *
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700896 * If unsuccessful, the helper will return null/null. There will be a pending exception in the
Maja Gagic6ea651f2015-02-24 16:55:04 +0100897 * thread and we branch to another stub to deliver it.
898 *
899 * On success this wrapper will restore arguments and *jump* to the target, leaving the ra
900 * pointing back to the original caller.
901 */
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700902.macro INVOKE_TRAMPOLINE_BODY cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100903 .extern \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100904 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME # save callee saves in case allocation triggers GC
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100905 move $a2, rSELF # pass Thread::Current
906 jal \cxx_name # (method_idx, this, Thread*, $sp)
907 move $a3, $sp # pass $sp
Maja Gagic6ea651f2015-02-24 16:55:04 +0100908 move $a0, $v0 # save target Method*
909 move $t9, $v1 # save $v0->code_
910 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
911 beq $v0, $zero, 1f
912 nop
913 jalr $zero, $t9
914 nop
9151:
916 DELIVER_PENDING_EXCEPTION
Andreas Gampe3031c8d2015-07-13 20:11:06 -0700917.endm
918.macro INVOKE_TRAMPOLINE c_name, cxx_name
919ENTRY \c_name
920 INVOKE_TRAMPOLINE_BODY \cxx_name
Maja Gagic6ea651f2015-02-24 16:55:04 +0100921END \c_name
922.endm
923
Maja Gagic6ea651f2015-02-24 16:55:04 +0100924INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck
925
926INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck
927INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck
928INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck
929INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800930
931 # On entry:
932 # t0 = shorty
933 # t1 = ptr to arg_array
934 # t2 = number of argument bytes remain
935 # v0 = ptr to stack frame where to copy arg_array
936 # This macro modifies t3, t9 and v0
937.macro LOOP_OVER_SHORTY_LOADING_REG gpu, fpu, label
938 lbu $t3, 0($t0) # get argument type from shorty
939 beqz $t3, \label
940 daddiu $t0, 1
941 li $t9, 68 # put char 'D' into t9
942 beq $t9, $t3, 1f # branch if result type char == 'D'
943 li $t9, 70 # put char 'F' into t9
944 beq $t9, $t3, 2f # branch if result type char == 'F'
945 li $t9, 74 # put char 'J' into t9
946 beq $t9, $t3, 3f # branch if result type char == 'J'
947 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +0100948 lw $\gpu, 0($t1)
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800949 sw $\gpu, 0($v0)
950 daddiu $v0, 4
951 daddiu $t1, 4
952 b 4f
953 daddiu $t2, -4 # delay slot
954
9551: # found double
956 lwu $t3, 0($t1)
957 mtc1 $t3, $\fpu
958 sw $t3, 0($v0)
959 lwu $t3, 4($t1)
960 mthc1 $t3, $\fpu
961 sw $t3, 4($v0)
962 daddiu $v0, 8
963 daddiu $t1, 8
964 b 4f
965 daddiu $t2, -8 # delay slot
966
9672: # found float
968 lwu $t3, 0($t1)
969 mtc1 $t3, $\fpu
970 sw $t3, 0($v0)
971 daddiu $v0, 4
972 daddiu $t1, 4
973 b 4f
974 daddiu $t2, -4 # delay slot
975
9763: # found long (8 bytes)
977 lwu $t3, 0($t1)
978 sw $t3, 0($v0)
979 lwu $t9, 4($t1)
980 sw $t9, 4($v0)
981 dsll $t9, $t9, 32
982 or $\gpu, $t9, $t3
983 daddiu $v0, 8
984 daddiu $t1, 8
985 daddiu $t2, -8
9864:
987.endm
988
989 /*
990 * Invocation stub for quick code.
991 * On entry:
992 * a0 = method pointer
993 * a1 = argument array that must at least contain the this ptr.
994 * a2 = size of argument array in bytes
995 * a3 = (managed) thread pointer
996 * a4 = JValue* result
997 * a5 = shorty
998 */
Goran Jakovljevic04568812015-04-23 15:27:23 +0200999ENTRY_NO_GP art_quick_invoke_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001000 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra onto the stack
1001 daddiu $sp, $sp, -48
1002 .cfi_adjust_cfa_offset 48
1003 sd $ra, 40($sp)
1004 .cfi_rel_offset 31, 40
1005 sd $s8, 32($sp)
1006 .cfi_rel_offset 30, 32
1007 sd $s1, 24($sp)
1008 .cfi_rel_offset 17, 24
1009 sd $s0, 16($sp)
1010 .cfi_rel_offset 16, 16
1011 sd $a5, 8($sp)
1012 .cfi_rel_offset 9, 8
1013 sd $a4, 0($sp)
1014 .cfi_rel_offset 8, 0
1015
1016 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1017 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1018 move $s8, $sp # save sp in s8 (fp)
1019
Mathieu Chartiere401d142015-04-22 13:56:20 -07001020 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001021 dsrl $t3, $t3, 4 # shift the frame size right 4
1022 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1023 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1024
1025 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1026 daddiu $t1, $a1, 4 # t1 = ptr to arg_array[4] (skip this ptr)
1027 daddiu $t2, $a2, -4 # t2 = number of argument bytes remain (skip this ptr)
Nikola Veljkovic80f7a572015-06-02 17:27:53 +02001028 daddiu $v0, $sp, 12 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001029 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_fn
1030 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_fn
1031 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_fn
1032 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_fn
1033 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_fn
1034 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_fn
1035
1036 # copy arguments onto stack (t2 should be multiples of 4)
1037 ble $t2, $zero, call_fn # t2 = number of argument bytes remain
10381:
1039 lw $t3, 0($t1) # load from argument array
1040 daddiu $t1, $t1, 4
1041 sw $t3, 0($v0) # save to stack
1042 daddiu $t2, -4
1043 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1044 daddiu $v0, $v0, 4
1045
1046call_fn:
1047 # call method (a0 and a1 have been untouched)
1048 lwu $a1, 0($a1) # make a1 = this ptr
Mathieu Chartiere401d142015-04-22 13:56:20 -07001049 sw $a1, 8($sp) # copy this ptr (skip 8 bytes for ArtMethod*)
1050 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1051 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001052 jalr $t9 # call the method
1053 nop
1054 move $sp, $s8 # restore sp
1055
1056 # pop a4, a5, s1(rSELF), s8, ra off of the stack
1057 ld $a4, 0($sp)
1058 .cfi_restore 8
1059 ld $a5, 8($sp)
1060 .cfi_restore 9
1061 ld $s0, 16($sp)
1062 .cfi_restore 16
1063 ld $s1, 24($sp)
1064 .cfi_restore 17
1065 ld $s8, 32($sp)
1066 .cfi_restore 30
1067 ld $ra, 40($sp)
1068 .cfi_restore 31
1069 daddiu $sp, $sp, 48
1070 .cfi_adjust_cfa_offset -48
1071
1072 # a4 = JValue* result
1073 # a5 = shorty string
1074 lbu $t1, 0($a5) # get result type from shorty
1075 li $t2, 68 # put char 'D' into t2
1076 beq $t1, $t2, 1f # branch if result type char == 'D'
1077 li $t3, 70 # put char 'F' into t3
1078 beq $t1, $t3, 1f # branch if result type char == 'F'
1079 sw $v0, 0($a4) # store the result
1080 dsrl $v1, $v0, 32
1081 jalr $zero, $ra
1082 sw $v1, 4($a4) # store the other half of the result
10831:
1084 mfc1 $v0, $f0
1085 mfhc1 $v1, $f0
1086 sw $v0, 0($a4) # store the result
1087 jalr $zero, $ra
1088 sw $v1, 4($a4) # store the other half of the result
1089END art_quick_invoke_stub
1090
1091 /*
1092 * Invocation static stub for quick code.
1093 * On entry:
1094 * a0 = method pointer
1095 * a1 = argument array that must at least contain the this ptr.
1096 * a2 = size of argument array in bytes
1097 * a3 = (managed) thread pointer
1098 * a4 = JValue* result
1099 * a5 = shorty
1100 */
Goran Jakovljevic04568812015-04-23 15:27:23 +02001101ENTRY_NO_GP art_quick_invoke_static_stub
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001102
1103 # push a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra, onto the stack
1104 daddiu $sp, $sp, -48
1105 .cfi_adjust_cfa_offset 48
1106 sd $ra, 40($sp)
1107 .cfi_rel_offset 31, 40
1108 sd $s8, 32($sp)
1109 .cfi_rel_offset 30, 32
1110 sd $s1, 24($sp)
1111 .cfi_rel_offset 17, 24
1112 sd $s0, 16($sp)
1113 .cfi_rel_offset 16, 16
1114 sd $a5, 8($sp)
1115 .cfi_rel_offset 9, 8
1116 sd $a4, 0($sp)
1117 .cfi_rel_offset 8, 0
1118
1119 daddiu $s0, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1120 move $s1, $a3 # move managed thread pointer into s1 (rSELF)
1121 move $s8, $sp # save sp in s8 (fp)
1122
Mathieu Chartiere401d142015-04-22 13:56:20 -07001123 daddiu $t3, $a2, 24 # add 8 for ArtMethod* and 16 for stack alignment
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001124 dsrl $t3, $t3, 4 # shift the frame size right 4
1125 dsll $t3, $t3, 4 # shift the frame size left 4 to align to 16 bytes
1126 dsubu $sp, $sp, $t3 # reserve stack space for argument array
1127
1128 daddiu $t0, $a5, 1 # t0 = shorty[1] (skip 1 for return type)
1129 move $t1, $a1 # t1 = arg_array
1130 move $t2, $a2 # t2 = number of argument bytes remain
Mathieu Chartiere401d142015-04-22 13:56:20 -07001131 daddiu $v0, $sp, 8 # v0 points to where to copy arg_array
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001132 LOOP_OVER_SHORTY_LOADING_REG a1, f13, call_sfn
1133 LOOP_OVER_SHORTY_LOADING_REG a2, f14, call_sfn
1134 LOOP_OVER_SHORTY_LOADING_REG a3, f15, call_sfn
1135 LOOP_OVER_SHORTY_LOADING_REG a4, f16, call_sfn
1136 LOOP_OVER_SHORTY_LOADING_REG a5, f17, call_sfn
1137 LOOP_OVER_SHORTY_LOADING_REG a6, f18, call_sfn
1138 LOOP_OVER_SHORTY_LOADING_REG a7, f19, call_sfn
1139
1140 # copy arguments onto stack (t2 should be multiples of 4)
1141 ble $t2, $zero, call_sfn # t2 = number of argument bytes remain
11421:
1143 lw $t3, 0($t1) # load from argument array
1144 daddiu $t1, $t1, 4
1145 sw $t3, 0($v0) # save to stack
1146 daddiu $t2, -4
1147 bgt $t2, $zero, 1b # t2 = number of argument bytes remain
1148 daddiu $v0, $v0, 4
1149
1150call_sfn:
1151 # call method (a0 has been untouched)
Mathieu Chartiere401d142015-04-22 13:56:20 -07001152 sd $zero, 0($sp) # store null for ArtMethod* at bottom of frame
1153 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0) # get pointer to the code
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001154 jalr $t9 # call the method
1155 nop
1156 move $sp, $s8 # restore sp
1157
1158 # pop a4, a5, s0(rSUSPEND), s1(rSELF), s8, ra off of the stack
1159 ld $a4, 0($sp)
1160 .cfi_restore 8
1161 ld $a5, 8($sp)
1162 .cfi_restore 9
1163 ld $s0, 16($sp)
1164 .cfi_restore 16
1165 ld $s1, 24($sp)
1166 .cfi_restore 17
1167 ld $s8, 32($sp)
1168 .cfi_restore 30
1169 ld $ra, 40($sp)
1170 .cfi_restore 31
1171 daddiu $sp, $sp, 48
1172 .cfi_adjust_cfa_offset -48
1173
1174 # a4 = JValue* result
1175 # a5 = shorty string
1176 lbu $t1, 0($a5) # get result type from shorty
1177 li $t2, 68 # put char 'D' into t2
1178 beq $t1, $t2, 1f # branch if result type char == 'D'
1179 li $t3, 70 # put char 'F' into t3
1180 beq $t1, $t3, 1f # branch if result type char == 'F'
1181 sw $v0, 0($a4) # store the result
1182 dsrl $v1, $v0, 32
1183 jalr $zero, $ra
1184 sw $v1, 4($a4) # store the other half of the result
11851:
1186 mfc1 $v0, $f0
1187 mfhc1 $v1, $f0
1188 sw $v0, 0($a4) # store the result
1189 jalr $zero, $ra
1190 sw $v1, 4($a4) # store the other half of the result
1191END art_quick_invoke_static_stub
1192
Maja Gagic6ea651f2015-02-24 16:55:04 +01001193 /*
1194 * Entry from managed code that calls artHandleFillArrayDataFromCode and
1195 * delivers exception on failure.
1196 */
1197 .extern artHandleFillArrayDataFromCode
1198ENTRY art_quick_handle_fill_data
1199 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001200 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001201 jal artHandleFillArrayDataFromCode # (payload offset, Array*, method, Thread*)
1202 move $a3, rSELF # pass Thread::Current
1203 RETURN_IF_ZERO
1204END art_quick_handle_fill_data
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001205
Maja Gagic6ea651f2015-02-24 16:55:04 +01001206 /*
1207 * Entry from managed code that calls artLockObjectFromCode, may block for GC.
1208 */
1209 .extern artLockObjectFromCode
1210ENTRY art_quick_lock_object
1211 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1212 nop
1213 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
1214 jal artLockObjectFromCode # (Object* obj, Thread*)
1215 move $a1, rSELF # pass Thread::Current
1216 RETURN_IF_ZERO
1217END art_quick_lock_object
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001218
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001219ENTRY art_quick_lock_object_no_inline
1220 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1221 nop
1222 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case we block
1223 jal artLockObjectFromCode # (Object* obj, Thread*)
1224 move $a1, rSELF # pass Thread::Current
1225 RETURN_IF_ZERO
1226END art_quick_lock_object_no_inline
1227
Maja Gagic6ea651f2015-02-24 16:55:04 +01001228 /*
1229 * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure.
1230 */
1231 .extern artUnlockObjectFromCode
1232ENTRY art_quick_unlock_object
1233 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1234 nop
1235 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
1236 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1237 move $a1, rSELF # pass Thread::Current
1238 RETURN_IF_ZERO
1239END art_quick_unlock_object
1240
Andreas Gampec7ed09b2016-04-25 20:08:55 -07001241ENTRY art_quick_unlock_object_no_inline
1242 beq $a0, $zero, .Lart_quick_throw_null_pointer_exception_gp_set
1243 nop
1244 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case exception allocation triggers GC
1245 jal artUnlockObjectFromCode # (Object* obj, Thread*)
1246 move $a1, rSELF # pass Thread::Current
1247 RETURN_IF_ZERO
1248END art_quick_unlock_object_no_inline
1249
Maja Gagic6ea651f2015-02-24 16:55:04 +01001250 /*
1251 * Entry from managed code that calls artCheckCastFromCode and delivers exception on failure.
1252 */
1253 .extern artThrowClassCastException
1254ENTRY art_quick_check_cast
1255 daddiu $sp, $sp, -32
1256 .cfi_adjust_cfa_offset 32
1257 sd $ra, 24($sp)
1258 .cfi_rel_offset 31, 24
1259 sd $t9, 16($sp)
1260 sd $a1, 8($sp)
1261 sd $a0, 0($sp)
1262 jal artIsAssignableFromCode
Goran Jakovljevic04568812015-04-23 15:27:23 +02001263 .cpreturn # Restore gp from t8 in branch delay slot.
1264 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001265 beq $v0, $zero, .Lthrow_class_cast_exception
1266 ld $ra, 24($sp)
1267 jalr $zero, $ra
1268 daddiu $sp, $sp, 32
1269 .cfi_adjust_cfa_offset -32
1270.Lthrow_class_cast_exception:
1271 ld $t9, 16($sp)
1272 ld $a1, 8($sp)
1273 ld $a0, 0($sp)
1274 daddiu $sp, $sp, 32
1275 .cfi_adjust_cfa_offset -32
Goran Jakovljevic04568812015-04-23 15:27:23 +02001276 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001277 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1278 dla $t9, artThrowClassCastException
1279 jalr $zero, $t9 # artThrowClassCastException (Class*, Class*, Thread*)
1280 move $a2, rSELF # pass Thread::Current
1281END art_quick_check_cast
1282
Man Cao1aee9002015-07-14 22:31:42 -07001283
1284 /*
1285 * Restore rReg's value from offset($sp) if rReg is not the same as rExclude.
1286 * nReg is the register number for rReg.
1287 */
1288.macro POP_REG_NE rReg, nReg, offset, rExclude
1289 .ifnc \rReg, \rExclude
1290 ld \rReg, \offset($sp) # restore rReg
1291 .cfi_restore \nReg
1292 .endif
1293.endm
1294
1295 /*
1296 * Macro to insert read barrier, only used in art_quick_aput_obj.
1297 * rObj and rDest are registers, offset is a defined literal such as MIRROR_OBJECT_CLASS_OFFSET.
1298 * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path.
1299 */
1300.macro READ_BARRIER rDest, rObj, offset
1301#ifdef USE_READ_BARRIER
1302 # saved registers used in art_quick_aput_obj: a0-a2, t0-t1, t9, ra. 16B-aligned.
1303 daddiu $sp, $sp, -64
1304 .cfi_adjust_cfa_offset 64
1305 sd $ra, 56($sp)
1306 .cfi_rel_offset 31, 56
1307 sd $t9, 48($sp)
1308 .cfi_rel_offset 25, 48
1309 sd $t1, 40($sp)
1310 .cfi_rel_offset 13, 40
1311 sd $t0, 32($sp)
1312 .cfi_rel_offset 12, 32
1313 sd $a2, 16($sp) # padding slot at offset 24 (padding can be any slot in the 64B)
1314 .cfi_rel_offset 6, 16
1315 sd $a1, 8($sp)
1316 .cfi_rel_offset 5, 8
1317 sd $a0, 0($sp)
1318 .cfi_rel_offset 4, 0
1319
Man Cao63069212015-08-21 15:51:39 -07001320 # move $a0, \rRef # pass ref in a0 (no-op for now since parameter ref is unused)
Man Cao1aee9002015-07-14 22:31:42 -07001321 .ifnc \rObj, $a1
1322 move $a1, \rObj # pass rObj
1323 .endif
1324 daddiu $a2, $zero, \offset # pass offset
1325 jal artReadBarrierSlow # artReadBarrierSlow(ref, rObj, offset)
1326 .cpreturn # Restore gp from t8 in branch delay slot.
1327 # t8 may be clobbered in artReadBarrierSlow.
1328 # No need to unpoison return value in v0, artReadBarrierSlow() would do the unpoisoning.
1329 move \rDest, $v0 # save return value in rDest
1330 # (rDest cannot be v0 in art_quick_aput_obj)
1331
1332 ld $a0, 0($sp) # restore registers except rDest
1333 # (rDest can only be t0 or t1 in art_quick_aput_obj)
1334 .cfi_restore 4
1335 ld $a1, 8($sp)
1336 .cfi_restore 5
1337 ld $a2, 16($sp)
1338 .cfi_restore 6
1339 POP_REG_NE $t0, 12, 32, \rDest
1340 POP_REG_NE $t1, 13, 40, \rDest
1341 ld $t9, 48($sp)
1342 .cfi_restore 25
1343 ld $ra, 56($sp) # restore $ra
1344 .cfi_restore 31
1345 daddiu $sp, $sp, 64
1346 .cfi_adjust_cfa_offset -64
1347 SETUP_GP # set up gp because we are not returning
1348#else
1349 lwu \rDest, \offset(\rObj)
1350 UNPOISON_HEAP_REF \rDest
1351#endif // USE_READ_BARRIER
1352.endm
1353
Maja Gagic6ea651f2015-02-24 16:55:04 +01001354 /*
1355 * Entry from managed code for array put operations of objects where the value being stored
1356 * needs to be checked for compatibility.
1357 * a0 = array, a1 = index, a2 = value
1358 */
1359ENTRY art_quick_aput_obj_with_null_and_bound_check
1360 bne $a0, $zero, .Lart_quick_aput_obj_with_bound_check_gp_set
1361 nop
1362 b .Lart_quick_throw_null_pointer_exception_gp_set
1363 nop
1364END art_quick_aput_obj_with_null_and_bound_check
1365
1366ENTRY art_quick_aput_obj_with_bound_check
1367 lwu $t0, MIRROR_ARRAY_LENGTH_OFFSET($a0)
1368 sltu $t1, $a1, $t0
1369 bne $t1, $zero, .Lart_quick_aput_obj_gp_set
1370 nop
1371 move $a0, $a1
1372 b .Lart_quick_throw_array_bounds_gp_set
1373 move $a1, $t0
1374END art_quick_aput_obj_with_bound_check
1375
1376ENTRY art_quick_aput_obj
1377 beq $a2, $zero, .Ldo_aput_null
1378 nop
Man Cao1aee9002015-07-14 22:31:42 -07001379 READ_BARRIER $t0, $a0, MIRROR_OBJECT_CLASS_OFFSET
1380 READ_BARRIER $t1, $a2, MIRROR_OBJECT_CLASS_OFFSET
1381 READ_BARRIER $t0, $t0, MIRROR_CLASS_COMPONENT_TYPE_OFFSET
Maja Gagic6ea651f2015-02-24 16:55:04 +01001382 bne $t1, $t0, .Lcheck_assignability # value's type == array's component type - trivial assignability
1383 nop
1384.Ldo_aput:
1385 dsll $a1, $a1, 2
1386 daddu $t0, $a0, $a1
Hiroshi Yamauchibfa5eb62015-05-29 15:04:41 -07001387 POISON_HEAP_REF $a2
Maja Gagic6ea651f2015-02-24 16:55:04 +01001388 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1389 ld $t0, THREAD_CARD_TABLE_OFFSET(rSELF)
1390 dsrl $t1, $a0, 7
1391 daddu $t1, $t1, $t0
1392 sb $t0, ($t1)
1393 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001394 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001395.Ldo_aput_null:
1396 dsll $a1, $a1, 2
1397 daddu $t0, $a0, $a1
1398 sw $a2, MIRROR_OBJECT_ARRAY_DATA_OFFSET($t0)
1399 jalr $zero, $ra
Goran Jakovljevic04568812015-04-23 15:27:23 +02001400 .cpreturn # Restore gp from t8 in branch delay slot.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001401.Lcheck_assignability:
1402 daddiu $sp, $sp, -64
1403 .cfi_adjust_cfa_offset 64
1404 sd $ra, 56($sp)
1405 .cfi_rel_offset 31, 56
1406 sd $t9, 24($sp)
1407 sd $a2, 16($sp)
1408 sd $a1, 8($sp)
1409 sd $a0, 0($sp)
1410 move $a1, $t1
1411 move $a0, $t0
1412 jal artIsAssignableFromCode # (Class*, Class*)
Goran Jakovljevic04568812015-04-23 15:27:23 +02001413 .cpreturn # Restore gp from t8 in branch delay slot.
1414 # t8 may be clobbered in artIsAssignableFromCode.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001415 ld $ra, 56($sp)
1416 ld $t9, 24($sp)
1417 ld $a2, 16($sp)
1418 ld $a1, 8($sp)
1419 ld $a0, 0($sp)
1420 daddiu $sp, $sp, 64
1421 .cfi_adjust_cfa_offset -64
Goran Jakovljevic04568812015-04-23 15:27:23 +02001422 SETUP_GP
Maja Gagic6ea651f2015-02-24 16:55:04 +01001423 bne $v0, $zero, .Ldo_aput
1424 nop
1425 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
1426 move $a1, $a2
1427 dla $t9, artThrowArrayStoreException
1428 jalr $zero, $t9 # artThrowArrayStoreException(Class*, Class*, Thread*)
1429 move $a2, rSELF # pass Thread::Current
1430END art_quick_aput_obj
1431
1432 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001433 * Called by managed code to resolve a static field and load a boolean primitive value.
1434 */
1435 .extern artGetBooleanStaticFromCode
1436ENTRY art_quick_get_boolean_static
1437 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001438 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001439 jal artGetBooleanStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1440 move $a2, rSELF # pass Thread::Current
1441 RETURN_IF_NO_EXCEPTION
1442END art_quick_get_boolean_static
1443
1444 /*
1445 * Called by managed code to resolve a static field and load a byte primitive value.
1446 */
1447 .extern artGetByteStaticFromCode
1448ENTRY art_quick_get_byte_static
1449 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001450 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001451 jal artGetByteStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1452 move $a2, rSELF # pass Thread::Current
1453 RETURN_IF_NO_EXCEPTION
1454END art_quick_get_byte_static
1455
1456 /*
1457 * Called by managed code to resolve a static field and load a char primitive value.
1458 */
1459 .extern artGetCharStaticFromCode
1460ENTRY art_quick_get_char_static
1461 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001462 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001463 jal artGetCharStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1464 move $a2, rSELF # pass Thread::Current
1465 RETURN_IF_NO_EXCEPTION
1466END art_quick_get_char_static
1467
1468 /*
1469 * Called by managed code to resolve a static field and load a short primitive value.
1470 */
1471 .extern artGetShortStaticFromCode
1472ENTRY art_quick_get_short_static
1473 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001474 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001475 jal artGetShortStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1476 move $a2, rSELF # pass Thread::Current
1477 RETURN_IF_NO_EXCEPTION
1478END art_quick_get_short_static
1479
1480 /*
1481 * Called by managed code to resolve a static field and load a 32-bit primitive value.
1482 */
1483 .extern artGet32StaticFromCode
1484ENTRY art_quick_get32_static
1485 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001486 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001487 jal artGet32StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1488 move $a2, rSELF # pass Thread::Current
1489 RETURN_IF_NO_EXCEPTION
1490END art_quick_get32_static
1491
1492 /*
1493 * Called by managed code to resolve a static field and load a 64-bit primitive value.
1494 */
1495 .extern artGet64StaticFromCode
1496ENTRY art_quick_get64_static
1497 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001498 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001499 jal artGet64StaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1500 move $a2, rSELF # pass Thread::Current
1501 RETURN_IF_NO_EXCEPTION
1502END art_quick_get64_static
1503
1504 /*
1505 * Called by managed code to resolve a static field and load an object reference.
1506 */
1507 .extern artGetObjStaticFromCode
1508ENTRY art_quick_get_obj_static
1509 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001510 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001511 jal artGetObjStaticFromCode # (uint32_t field_idx, const Method* referrer, Thread*)
1512 move $a2, rSELF # pass Thread::Current
1513 RETURN_IF_NO_EXCEPTION
1514END art_quick_get_obj_static
1515
1516 /*
1517 * Called by managed code to resolve an instance field and load a boolean primitive value.
1518 */
1519 .extern artGetBooleanInstanceFromCode
1520ENTRY art_quick_get_boolean_instance
1521 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001522 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001523 jal artGetBooleanInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1524 move $a3, rSELF # pass Thread::Current
1525 RETURN_IF_NO_EXCEPTION
1526END art_quick_get_boolean_instance
1527
1528 /*
1529 * Called by managed code to resolve an instance field and load a byte primitive value.
1530 */
1531 .extern artGetByteInstanceFromCode
1532ENTRY art_quick_get_byte_instance
1533 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001534 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001535 jal artGetByteInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1536 move $a3, rSELF # pass Thread::Current
1537 RETURN_IF_NO_EXCEPTION
1538END art_quick_get_byte_instance
1539
1540 /*
1541 * Called by managed code to resolve an instance field and load a char primitive value.
1542 */
1543 .extern artGetCharInstanceFromCode
1544ENTRY art_quick_get_char_instance
1545 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001546 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001547 jal artGetCharInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1548 move $a3, rSELF # pass Thread::Current
1549 RETURN_IF_NO_EXCEPTION
1550END art_quick_get_char_instance
1551
1552 /*
1553 * Called by managed code to resolve an instance field and load a short primitive value.
1554 */
1555 .extern artGetShortInstanceFromCode
1556ENTRY art_quick_get_short_instance
1557 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001558 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001559 jal artGetShortInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1560 move $a3, rSELF # pass Thread::Current
1561 RETURN_IF_NO_EXCEPTION
1562END art_quick_get_short_instance
1563
1564 /*
1565 * Called by managed code to resolve an instance field and load a 32-bit primitive value.
1566 */
1567 .extern artGet32InstanceFromCode
1568ENTRY art_quick_get32_instance
1569 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001570 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001571 jal artGet32InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1572 move $a3, rSELF # pass Thread::Current
1573 RETURN_IF_NO_EXCEPTION
1574END art_quick_get32_instance
1575
1576 /*
1577 * Called by managed code to resolve an instance field and load a 64-bit primitive value.
1578 */
1579 .extern artGet64InstanceFromCode
1580ENTRY art_quick_get64_instance
1581 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001582 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001583 jal artGet64InstanceFromCode # (field_idx, Object*, referrer, Thread*)
1584 move $a3, rSELF # pass Thread::Current
1585 RETURN_IF_NO_EXCEPTION
1586END art_quick_get64_instance
1587
1588 /*
1589 * Called by managed code to resolve an instance field and load an object reference.
1590 */
1591 .extern artGetObjInstanceFromCode
1592ENTRY art_quick_get_obj_instance
1593 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001594 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001595 jal artGetObjInstanceFromCode # (field_idx, Object*, referrer, Thread*)
1596 move $a3, rSELF # pass Thread::Current
1597 RETURN_IF_NO_EXCEPTION
1598END art_quick_get_obj_instance
1599
1600 /*
1601 * Called by managed code to resolve a static field and store a 8-bit primitive value.
1602 */
1603 .extern artSet8StaticFromCode
1604ENTRY art_quick_set8_static
1605 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001606 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001607 jal artSet8StaticFromCode # (field_idx, new_val, referrer, Thread*)
1608 move $a3, rSELF # pass Thread::Current
1609 RETURN_IF_ZERO
1610END art_quick_set8_static
1611
1612 /*
1613 * Called by managed code to resolve a static field and store a 16-bit primitive value.
1614 */
1615 .extern artSet16StaticFromCode
1616ENTRY art_quick_set16_static
1617 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001618 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001619 jal artSet16StaticFromCode # (field_idx, new_val, referrer, Thread*)
1620 move $a3, rSELF # pass Thread::Current
1621 RETURN_IF_ZERO
1622END art_quick_set16_static
1623
1624 /*
1625 * Called by managed code to resolve a static field and store a 32-bit primitive value.
1626 */
1627 .extern artSet32StaticFromCode
1628ENTRY art_quick_set32_static
1629 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001630 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001631 jal artSet32StaticFromCode # (field_idx, new_val, referrer, Thread*)
1632 move $a3, rSELF # pass Thread::Current
1633 RETURN_IF_ZERO
1634END art_quick_set32_static
1635
1636 /*
1637 * Called by managed code to resolve a static field and store a 64-bit primitive value.
1638 */
1639 .extern artSet64StaticFromCode
1640ENTRY art_quick_set64_static
1641 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Calin Juravlee460d1d2015-09-29 04:52:17 +01001642 # a2 contains the new val
Mathieu Chartiere401d142015-04-22 13:56:20 -07001643 ld $a1, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001644 jal artSet64StaticFromCode # (field_idx, referrer, new_val, Thread*)
1645 move $a3, rSELF # pass Thread::Current
1646 RETURN_IF_ZERO
1647END art_quick_set64_static
1648
1649 /*
1650 * Called by managed code to resolve a static field and store an object reference.
1651 */
1652 .extern artSetObjStaticFromCode
1653ENTRY art_quick_set_obj_static
1654 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001655 ld $a2, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001656 jal artSetObjStaticFromCode # (field_idx, new_val, referrer, Thread*)
1657 move $a3, rSELF # pass Thread::Current
1658 RETURN_IF_ZERO
1659END art_quick_set_obj_static
1660
1661 /*
1662 * Called by managed code to resolve an instance field and store a 8-bit primitive value.
1663 */
1664 .extern artSet8InstanceFromCode
1665ENTRY art_quick_set8_instance
1666 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001667 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001668 jal artSet8InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1669 move $a4, rSELF # pass Thread::Current
1670 RETURN_IF_ZERO
1671END art_quick_set8_instance
1672
1673 /*
1674 * Called by managed code to resolve an instance field and store a 16-bit primitive value.
1675 */
1676 .extern artSet16InstanceFromCode
1677ENTRY art_quick_set16_instance
1678 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001679 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001680 jal artSet16InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1681 move $a4, rSELF # pass Thread::Current
1682 RETURN_IF_ZERO
1683END art_quick_set16_instance
1684
1685 /*
1686 * Called by managed code to resolve an instance field and store a 32-bit primitive value.
1687 */
1688 .extern artSet32InstanceFromCode
1689ENTRY art_quick_set32_instance
1690 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001691 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001692 jal artSet32InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1693 move $a4, rSELF # pass Thread::Current
1694 RETURN_IF_ZERO
1695END art_quick_set32_instance
1696
1697 /*
1698 * Called by managed code to resolve an instance field and store a 64-bit primitive value.
1699 */
1700 .extern artSet64InstanceFromCode
1701ENTRY art_quick_set64_instance
1702 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001703 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001704 jal artSet64InstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1705 move $a4, rSELF # pass Thread::Current
1706 RETURN_IF_ZERO
1707END art_quick_set64_instance
1708
1709 /*
1710 * Called by managed code to resolve an instance field and store an object reference.
1711 */
1712 .extern artSetObjInstanceFromCode
1713ENTRY art_quick_set_obj_instance
1714 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Mathieu Chartiere401d142015-04-22 13:56:20 -07001715 ld $a3, FRAME_SIZE_REFS_ONLY_CALLEE_SAVE($sp) # pass referrer's Method*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001716 jal artSetObjInstanceFromCode # (field_idx, Object*, new_val, referrer, Thread*)
1717 move $a4, rSELF # pass Thread::Current
1718 RETURN_IF_ZERO
1719END art_quick_set_obj_instance
1720
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001721// Macro to facilitate adding new allocation entrypoints.
1722.macro ONE_ARG_DOWNCALL name, entrypoint, return
1723 .extern \entrypoint
1724ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001725 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001726 jal \entrypoint
1727 move $a1, rSELF # pass Thread::Current
1728 \return
1729END \name
1730.endm
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001731
1732// Macro to facilitate adding new allocation entrypoints.
1733.macro TWO_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001734 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001735ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001736 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1737 jal \entrypoint
1738 move $a2, rSELF # pass Thread::Current
1739 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001740END \name
1741.endm
1742
1743.macro THREE_ARG_DOWNCALL name, entrypoint, return
Maja Gagic6ea651f2015-02-24 16:55:04 +01001744 .extern \entrypoint
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001745ENTRY \name
Maja Gagic6ea651f2015-02-24 16:55:04 +01001746 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1747 jal \entrypoint
1748 move $a3, rSELF # pass Thread::Current
1749 \return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001750END \name
1751.endm
1752
Vladimir Markoe85e1232015-04-28 14:14:58 +01001753.macro FOUR_ARG_DOWNCALL name, entrypoint, return
1754 .extern \entrypoint
1755ENTRY \name
1756 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME # save callee saves in case of GC
1757 jal \entrypoint
1758 move $a4, rSELF # pass Thread::Current
1759 \return
1760END \name
1761.endm
1762
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001763// Generate the allocation entrypoints for each allocator.
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001764GENERATE_ALLOC_ENTRYPOINTS_FOR_EACH_ALLOCATOR
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001765
Goran Jakovljevic982a9a82015-12-21 12:00:54 +01001766// A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc).
1767ENTRY art_quick_alloc_object_rosalloc
1768
1769 # Fast path rosalloc allocation
1770 # a0: type_idx
1771 # a1: ArtMethod*
1772 # s1: Thread::Current
1773 # -----------------------------
1774 # t0: class
1775 # t1: object size
1776 # t2: rosalloc run
1777 # t3: thread stack top offset
1778 # a4: thread stack bottom offset
1779 # v0: free list head
1780 #
1781 # a5, a6 : temps
1782
1783 ld $t0, ART_METHOD_DEX_CACHE_TYPES_OFFSET_64($a1) # Load dex cache resolved types array.
1784
1785 dsll $a5, $a0, COMPRESSED_REFERENCE_SIZE_SHIFT # Shift the value.
1786 daddu $a5, $t0, $a5 # Compute the index.
1787 lwu $t0, 0($a5) # Load class (t0).
1788 beqzc $t0, .Lart_quick_alloc_object_rosalloc_slow_path
1789
1790 li $a6, MIRROR_CLASS_STATUS_INITIALIZED
1791 lwu $a5, MIRROR_CLASS_STATUS_OFFSET($t0) # Check class status.
1792 bnec $a5, $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1793
1794 # Add a fake dependence from the following access flag and size loads to the status load. This
1795 # is to prevent those loads from being reordered above the status load and reading wrong values.
1796 xor $a5, $a5, $a5
1797 daddu $t0, $t0, $a5
1798
1799 lwu $a5, MIRROR_CLASS_ACCESS_FLAGS_OFFSET($t0) # Check if access flags has
1800 li $a6, ACCESS_FLAGS_CLASS_IS_FINALIZABLE # kAccClassIsFinalizable.
1801 and $a6, $a5, $a6
1802 bnezc $a6, .Lart_quick_alloc_object_rosalloc_slow_path
1803
1804 ld $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1) # Check if thread local allocation stack
1805 ld $a4, THREAD_LOCAL_ALLOC_STACK_END_OFFSET($s1) # has any room left.
1806 bgeuc $t3, $a4, .Lart_quick_alloc_object_rosalloc_slow_path
1807
1808 lwu $t1, MIRROR_CLASS_OBJECT_SIZE_OFFSET($t0) # Load object size (t1).
1809 li $a5, ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE # Check if size is for a thread local
1810 # allocation.
1811 bltuc $a5, $t1, .Lart_quick_alloc_object_rosalloc_slow_path
1812
1813 # Compute the rosalloc bracket index from the size. Allign up the size by the rosalloc bracket
1814 # quantum size and divide by the quantum size and subtract by 1.
1815 daddiu $t1, $t1, -1 # Decrease obj size and shift right by
1816 dsrl $t1, $t1, ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT # quantum.
1817
1818 dsll $t2, $t1, POINTER_SIZE_SHIFT
1819 daddu $t2, $t2, $s1
1820 ld $t2, THREAD_ROSALLOC_RUNS_OFFSET($t2) # Load rosalloc run (t2).
1821
1822 # Load the free list head (v0).
1823 # NOTE: this will be the return val.
1824 ld $v0, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1825 beqzc $v0, .Lart_quick_alloc_object_rosalloc_slow_path
1826
1827 # Load the next pointer of the head and update the list head with the next pointer.
1828 ld $a5, ROSALLOC_SLOT_NEXT_OFFSET($v0)
1829 sd $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)($t2)
1830
1831 # Store the class pointer in the header. This also overwrites the first pointer. The offsets are
1832 # asserted to match.
1833
1834#if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET
1835#error "Class pointer needs to overwrite next pointer."
1836#endif
1837
1838 POISON_HEAP_REF $t0
1839 sw $t0, MIRROR_OBJECT_CLASS_OFFSET($v0)
1840
1841 # Push the new object onto the thread local allocation stack and increment the thread local
1842 # allocation stack top.
1843 sd $v0, 0($t3)
1844 daddiu $t3, $t3, COMPRESSED_REFERENCE_SIZE
1845 sd $t3, THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET($s1)
1846
1847 # Decrement the size of the free list.
1848 lw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1849 addiu $a5, $a5, -1
1850 sw $a5, (ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)($t2)
1851
1852 sync # Fence.
1853
1854 jalr $zero, $ra
1855 .cpreturn # Restore gp from t8 in branch delay slot.
1856
1857.Lart_quick_alloc_object_rosalloc_slow_path:
1858 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
1859 jal artAllocObjectFromCodeRosAlloc
1860 move $a2 ,$s1 # Pass self as argument.
1861 RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1862
1863END art_quick_alloc_object_rosalloc
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001864
Hiroshi Yamauchi10d4c082016-02-24 12:51:18 -08001865GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB)
1866GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB)
1867
Maja Gagic6ea651f2015-02-24 16:55:04 +01001868 /*
Vladimir Marko5ea536a2015-04-20 20:11:30 +01001869 * Entry from managed code to resolve a string, this stub will allocate a String and deliver an
1870 * exception on error. On success the String is returned. A0 holds the string index. The fast
1871 * path check for hit in strings cache has already been performed.
1872 */
1873ONE_ARG_DOWNCALL art_quick_resolve_string, artResolveStringFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1874
1875 /*
1876 * Entry from managed code when uninitialized static storage, this stub will run the class
1877 * initializer and deliver the exception on error. On success the static storage base is
1878 * returned.
1879 */
1880ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1881
1882 /*
1883 * Entry from managed code when dex cache misses for a type_idx.
1884 */
1885ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1886
1887 /*
1888 * Entry from managed code when type_idx needs to be checked for access and dex cache may also
1889 * miss.
1890 */
1891ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER
1892
1893 /*
Maja Gagic6ea651f2015-02-24 16:55:04 +01001894 * Called by managed code when the value in rSUSPEND has been decremented to 0.
1895 */
1896 .extern artTestSuspendFromCode
Vladimir Marko952dbb12016-07-28 12:01:51 +01001897ENTRY_NO_GP art_quick_test_suspend
1898 lh rSUSPEND, THREAD_FLAGS_OFFSET(rSELF)
1899 bne rSUSPEND, $zero, 1f
Maja Gagic6ea651f2015-02-24 16:55:04 +01001900 daddiu rSUSPEND, $zero, SUSPEND_CHECK_INTERVAL # reset rSUSPEND to SUSPEND_CHECK_INTERVAL
1901 jalr $zero, $ra
Vladimir Marko952dbb12016-07-28 12:01:51 +01001902 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +010019031:
Vladimir Marko952dbb12016-07-28 12:01:51 +01001904 SETUP_SAVE_EVERYTHING_CALLEE_SAVE_FRAME # save everything for stack crawl
Maja Gagic6ea651f2015-02-24 16:55:04 +01001905 jal artTestSuspendFromCode # (Thread*)
1906 move $a0, rSELF
Vladimir Marko952dbb12016-07-28 12:01:51 +01001907 RESTORE_SAVE_EVERYTHING_CALLEE_SAVE_FRAME
1908 jalr $zero, $ra
1909 nop
Maja Gagic6ea651f2015-02-24 16:55:04 +01001910END art_quick_test_suspend
Douglas Leung6461d192015-01-30 18:13:58 -08001911
1912 /*
1913 * Called by managed code that is attempting to call a method on a proxy class. On entry
1914 * r0 holds the proxy method; r1, r2 and r3 may contain arguments.
1915 */
1916 .extern artQuickProxyInvokeHandler
1917ENTRY art_quick_proxy_invoke_handler
Douglas Leung8223b802015-04-28 17:22:29 -07001918 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
Douglas Leung6461d192015-01-30 18:13:58 -08001919 move $a2, rSELF # pass Thread::Current
1920 jal artQuickProxyInvokeHandler # (Method* proxy method, receiver, Thread*, SP)
1921 move $a3, $sp # pass $sp
1922 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
1923 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
1924 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
1925 bne $t0, $zero, 1f
1926 dmtc1 $v0, $f0 # place return value to FP return value
1927 jalr $zero, $ra
1928 dmtc1 $v1, $f1 # place return value to FP return value
19291:
1930 DELIVER_PENDING_EXCEPTION
1931END art_quick_proxy_invoke_handler
1932
Maja Gagic6ea651f2015-02-24 16:55:04 +01001933 /*
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001934 * Called to resolve an imt conflict.
1935 * a0 is the conflict ArtMethod.
1936 * t0 is a hidden argument that holds the target interface method's dex method index.
1937 *
1938 * Mote that this stub writes to a0, t0 and t1.
Maja Gagic6ea651f2015-02-24 16:55:04 +01001939 */
1940ENTRY art_quick_imt_conflict_trampoline
Goran Jakovljevic59028d92016-03-29 18:05:03 +02001941 ld $t1, 0($sp) # Load referrer.
1942 ld $t1, ART_METHOD_DEX_CACHE_METHODS_OFFSET_64($t1) # Load dex cache methods array.
1943 dsll $t0, $t0, POINTER_SIZE_SHIFT # Calculate offset.
1944 daddu $t0, $t1, $t0 # Add offset to base.
1945 ld $t0, 0($t0) # Load interface method.
1946 ld $a0, ART_METHOD_JNI_OFFSET_64($a0) # Load ImtConflictTable.
1947
1948.Limt_table_iterate:
1949 ld $t1, 0($a0) # Load next entry in ImtConflictTable.
1950 # Branch if found.
1951 beq $t1, $t0, .Limt_table_found
1952 nop
1953 # If the entry is null, the interface method is not in the ImtConflictTable.
1954 beqzc $t1, .Lconflict_trampoline
1955 # Iterate over the entries of the ImtConflictTable.
1956 daddiu $a0, $a0, 2 * __SIZEOF_POINTER__ # Iterate to the next entry.
1957 bc .Limt_table_iterate
1958
1959.Limt_table_found:
1960 # We successfully hit an entry in the table. Load the target method and jump to it.
1961 ld $a0, __SIZEOF_POINTER__($a0)
1962 ld $t9, ART_METHOD_QUICK_CODE_OFFSET_64($a0)
1963 jr $t9
1964 .cpreturn # Restore gp from t8 in branch delay slot.
1965
1966.Lconflict_trampoline:
1967 # Call the runtime stub to populate the ImtConflictTable and jump to the resolved method.
Andreas Gampe3031c8d2015-07-13 20:11:06 -07001968 INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline
Maja Gagic6ea651f2015-02-24 16:55:04 +01001969END art_quick_imt_conflict_trampoline
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001970
1971 .extern artQuickResolutionTrampoline
1972ENTRY art_quick_resolution_trampoline
1973 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1974 move $a2, rSELF # pass Thread::Current
1975 jal artQuickResolutionTrampoline # (Method* called, receiver, Thread*, SP)
1976 move $a3, $sp # pass $sp
1977 beq $v0, $zero, 1f
Mathieu Chartiere401d142015-04-22 13:56:20 -07001978 ld $a0, 0($sp) # load resolved method in $a0
Andreas Gampecc7c39d2015-01-30 17:04:45 -08001979 # artQuickResolutionTrampoline puts resolved method in *SP
1980 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1981 move $t9, $v0 # code pointer must be in $t9 to generate the global pointer
1982 jalr $zero, $t9 # tail call to method
1983 nop
19841:
1985 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
1986 DELIVER_PENDING_EXCEPTION
1987END art_quick_resolution_trampoline
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001988
1989 .extern artQuickGenericJniTrampoline
1990 .extern artQuickGenericJniEndTrampoline
1991ENTRY art_quick_generic_jni_trampoline
Douglas Leung8223b802015-04-28 17:22:29 -07001992 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME_WITH_METHOD_IN_A0
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001993 move $s8, $sp # save $sp
1994
1995 # prepare for call to artQuickGenericJniTrampoline(Thread*, SP)
1996 move $a0, rSELF # pass Thread::Current
1997 move $a1, $sp # pass $sp
1998 jal artQuickGenericJniTrampoline # (Thread*, SP)
1999 daddiu $sp, $sp, -5120 # reserve space on the stack
2000
2001 # The C call will have registered the complete save-frame on success.
2002 # The result of the call is:
2003 # v0: ptr to native code, 0 on error.
2004 # v1: ptr to the bottom of the used area of the alloca, can restore stack till here.
2005 beq $v0, $zero, 1f # check entry error
2006 move $t9, $v0 # save the code ptr
2007 move $sp, $v1 # release part of the alloca
2008
2009 # Load parameters from stack into registers
2010 ld $a0, 0($sp)
2011 ld $a1, 8($sp)
2012 ld $a2, 16($sp)
2013 ld $a3, 24($sp)
2014 ld $a4, 32($sp)
2015 ld $a5, 40($sp)
2016 ld $a6, 48($sp)
2017 ld $a7, 56($sp)
2018 # Load FPRs the same as GPRs. Look at BuildNativeCallFrameStateMachine.
2019 l.d $f12, 0($sp)
2020 l.d $f13, 8($sp)
2021 l.d $f14, 16($sp)
2022 l.d $f15, 24($sp)
2023 l.d $f16, 32($sp)
2024 l.d $f17, 40($sp)
2025 l.d $f18, 48($sp)
2026 l.d $f19, 56($sp)
2027 jalr $t9 # native call
2028 daddiu $sp, $sp, 64
2029
2030 # result sign extension is handled in C code
2031 # prepare for call to artQuickGenericJniEndTrampoline(Thread*, result, result_f)
2032 move $a0, rSELF # pass Thread::Current
2033 move $a1, $v0
2034 jal artQuickGenericJniEndTrampoline
2035 dmfc1 $a2, $f0
2036
2037 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002038 bne $t0, $zero, 1f # check for pending exceptions
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002039 move $sp, $s8 # tear down the alloca
2040
2041 # tear dpown the callee-save frame
2042 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
2043
2044 jalr $zero, $ra
2045 dmtc1 $v0, $f0 # place return value to FP return value
2046
20471:
Nicolas Geoffray126d6592015-03-03 14:28:35 +00002048 ld $sp, THREAD_TOP_QUICK_FRAME_OFFSET(rSELF)
2049 # This will create a new save-all frame, required by the runtime.
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002050 DELIVER_PENDING_EXCEPTION
2051END art_quick_generic_jni_trampoline
2052
2053 .extern artQuickToInterpreterBridge
2054ENTRY art_quick_to_interpreter_bridge
2055 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
2056 move $a1, rSELF # pass Thread::Current
2057 jal artQuickToInterpreterBridge # (Method* method, Thread*, SP)
2058 move $a2, $sp # pass $sp
2059 ld $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
2060 daddiu $sp, $sp, REFS_AND_ARGS_MINUS_REFS_SIZE # skip a0-a7 and f12-f19
2061 RESTORE_REFS_ONLY_CALLEE_SAVE_FRAME
2062 bne $t0, $zero, 1f
2063 dmtc1 $v0, $f0 # place return value to FP return value
2064 jalr $zero, $ra
2065 dmtc1 $v1, $f1 # place return value to FP return value
20661:
2067 DELIVER_PENDING_EXCEPTION
2068END art_quick_to_interpreter_bridge
2069
2070 /*
2071 * Routine that intercepts method calls and returns.
2072 */
2073 .extern artInstrumentationMethodEntryFromCode
2074 .extern artInstrumentationMethodExitFromCode
2075ENTRY art_quick_instrumentation_entry
2076 SETUP_REFS_AND_ARGS_CALLEE_SAVE_FRAME
2077 daddiu $sp, $sp, -16 # space for saving arg0
2078 .cfi_adjust_cfa_offset 16
2079 sd $a0, 0($sp) # save arg0
2080 move $a3, $ra # pass $ra
2081 jal artInstrumentationMethodEntryFromCode # (Method*, Object*, Thread*, RA)
2082 move $a2, rSELF # pass Thread::Current
2083 move $t9, $v0 # $t9 holds reference to code
2084 ld $a0, 0($sp) # restore arg0
2085 daddiu $sp, $sp, 16 # remove args
2086 .cfi_adjust_cfa_offset -16
2087 RESTORE_REFS_AND_ARGS_CALLEE_SAVE_FRAME
2088 jalr $t9 # call method
2089 nop
2090END art_quick_instrumentation_entry
2091 /* intentional fallthrough */
2092 .global art_quick_instrumentation_exit
2093art_quick_instrumentation_exit:
2094 .cfi_startproc
Goran Jakovljevic04568812015-04-23 15:27:23 +02002095 SETUP_GP
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002096 move $ra, $zero # link register is to here, so clobber with 0 for later checks
2097 SETUP_REFS_ONLY_CALLEE_SAVE_FRAME
2098 move $t0, $sp # remember bottom of caller's frame
2099 daddiu $sp, $sp, -16 # save return values and set up args
2100 .cfi_adjust_cfa_offset 16
2101 sd $v0, 0($sp)
2102 .cfi_rel_offset 2, 0
2103 s.d $f0, 8($sp)
2104 mov.d $f15, $f0 # pass fpr result
2105 move $a2, $v0 # pass gpr result
2106 move $a1, $t0 # pass $sp
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002107 move $a0, rSELF # pass Thread::Current
Goran Jakovljevic04568812015-04-23 15:27:23 +02002108 jal artInstrumentationMethodExitFromCode # (Thread*, SP, gpr_res, fpr_res)
2109 .cpreturn # Restore gp from t8 in branch delay slot. gp is not used anymore,
2110 # and t8 may be clobbered in artInstrumentationMethodExitFromCode.
2111
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002112 move $t9, $v0 # set aside returned link register
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002113 move $ra, $v1 # set link register for deoptimization
2114 ld $v0, 0($sp) # restore return values
2115 l.d $f0, 8($sp)
Douglas Leungf96e8bd2015-03-27 15:38:30 -07002116 jalr $zero, $t9 # return
Andreas Gampe1a5c4062015-01-15 12:10:47 -08002117 daddiu $sp, $sp, 16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE # 16 bytes of saved values + ref_only callee save frame
2118 .cfi_adjust_cfa_offset -(16+FRAME_SIZE_REFS_ONLY_CALLEE_SAVE)
2119END art_quick_instrumentation_exit
2120
Maja Gagic6ea651f2015-02-24 16:55:04 +01002121 /*
2122 * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization
2123 * will long jump to the upcall with a special exception of -1.
2124 */
2125 .extern artDeoptimize
2126 .extern artEnterInterpreterFromDeoptimize
2127ENTRY art_quick_deoptimize
2128 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
2129 jal artDeoptimize # artDeoptimize(Thread*, SP)
2130 # Returns caller method's frame size.
2131 move $a0, rSELF # pass Thread::current
2132END art_quick_deoptimize
2133
Sebastien Hertz07474662015-08-25 15:12:33 +00002134 /*
2135 * Compiled code has requested that we deoptimize into the interpreter. The deoptimization
2136 * will long jump to the upcall with a special exception of -1.
2137 */
2138 .extern artDeoptimizeFromCompiledCode
2139ENTRY art_quick_deoptimize_from_compiled_code
2140 SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
2141 jal artDeoptimizeFromCompiledCode # artDeoptimizeFromCompiledCode(Thread*, SP)
2142 # Returns caller method's frame size.
2143 move $a0, rSELF # pass Thread::current
2144END art_quick_deoptimize_from_compiled_code
2145
Chris Larsen9701c2e2015-09-04 17:22:47 -07002146 .set push
2147 .set noat
2148/* java.lang.String.compareTo(String anotherString) */
2149ENTRY_NO_GP art_quick_string_compareto
2150/* $a0 holds address of "this" */
2151/* $a1 holds address of "anotherString" */
2152 beq $a0,$a1,9f # this and anotherString are the same object
2153 move $v0,$zero
2154
2155 lw $a2,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
2156 lw $a3,MIRROR_STRING_COUNT_OFFSET($a1) # anotherString.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002157 MINu $t2, $a2, $a3
2158# $t2 now holds min(this.length(),anotherString.length())
Chris Larsen9701c2e2015-09-04 17:22:47 -07002159
2160 beqz $t2,9f # while min(this.length(),anotherString.length())-i != 0
2161 subu $v0,$a2,$a3 # if $t2==0 return
2162 # (this.length() - anotherString.length())
21631:
2164 lhu $t0,MIRROR_STRING_VALUE_OFFSET($a0) # while this.charAt(i) == anotherString.charAt(i)
2165 lhu $t1,MIRROR_STRING_VALUE_OFFSET($a1)
2166 bne $t0,$t1,9f # if this.charAt(i) != anotherString.charAt(i)
2167 subu $v0,$t0,$t1 # return (this.charAt(i) - anotherString.charAt(i))
2168 daddiu $a0,$a0,2 # point at this.charAt(i++)
2169 subu $t2,$t2,1 # new value of
2170 # min(this.length(),anotherString.length())-i
2171 bnez $t2,1b
2172 daddiu $a1,$a1,2 # point at anotherString.charAt(i++)
2173 subu $v0,$a2,$a3
2174
21759:
2176 j $ra
2177 nop
2178END art_quick_string_compareto
2179
2180/* java.lang.String.indexOf(int ch, int fromIndex=0) */
2181ENTRY_NO_GP art_quick_indexof
2182/* $a0 holds address of "this" */
Chris Larsencf283da2016-01-19 16:45:35 -08002183/* $a1 holds "ch" */
2184/* $a2 holds "fromIndex" */
Chris Larsen9701c2e2015-09-04 17:22:47 -07002185 lw $t0,MIRROR_STRING_COUNT_OFFSET($a0) # this.length()
Chris Larsencf283da2016-01-19 16:45:35 -08002186 slt $at, $a2, $zero # if fromIndex < 0
2187 seleqz $a2, $a2, $at # fromIndex = 0;
2188 subu $t0,$t0,$a2 # this.length() - fromIndex
2189 blez $t0,6f # if this.length()-fromIndex <= 0
Chris Larsen9701c2e2015-09-04 17:22:47 -07002190 li $v0,-1 # return -1;
2191
2192 sll $v0,$a2,1 # $a0 += $a2 * 2
2193 daddu $a0,$a0,$v0 # " " " " "
Chris Larsencf283da2016-01-19 16:45:35 -08002194 move $v0,$a2 # Set i to fromIndex.
Chris Larsen9701c2e2015-09-04 17:22:47 -07002195
21961:
2197 lhu $t3,MIRROR_STRING_VALUE_OFFSET($a0) # if this.charAt(i) == ch
2198 beq $t3,$a1,6f # return i;
2199 daddu $a0,$a0,2 # i++
2200 subu $t0,$t0,1 # this.length() - i
2201 bnez $t0,1b # while this.length() - i > 0
2202 addu $v0,$v0,1 # i++
2203
2204 li $v0,-1 # if this.length() - i <= 0
2205 # return -1;
2206
22076:
2208 j $ra
2209 nop
2210END art_quick_indexof
2211
2212 .set pop