1 /* src/vm/jit/mips/asmpart.S - Java-C interface functions for MIPS
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "vm/jit/mips/md-abi.h"
31 #include "vm/jit/mips/md-asm.h"
33 #include "vm/jit/abi-asm.h"
34 #include "vm/jit/methodheader.h"
41 /* export functions ***********************************************************/
43 .globl asm_vm_call_method
44 .globl asm_vm_call_method_int
45 .globl asm_vm_call_method_long
46 .globl asm_vm_call_method_float
47 .globl asm_vm_call_method_double
48 .globl asm_vm_call_method_exception_handler
49 .globl asm_vm_call_method_end
51 .globl asm_call_jit_compiler
53 .globl asm_handle_exception
54 .globl asm_handle_nat_exception
56 .globl asm_abstractmethoderror
58 .globl compare_and_swap
61 /* asm_vm_call_method **********************************************************
63 * This function calls a Java-method (which possibly needs compilation) *
64 * with up to 4 address parameters. *
66 * This functions calls the JIT-compiler which eventually translates the *
67 * method into machine code. *
69 * A possibly throwed exception will be returned to the caller as function *
70 * return value, so the java method cannot return a fucntion value (this *
71 * function usually calls 'main' and '<clinit>' which do not return a *
75 * javaobject_header *asm_calljavafunction (methodinfo *m, *
76 * void *arg1, void *arg2, void *arg3, void *arg4); *
78 *******************************************************************************/
80 .ent asm_vm_call_method
84 #if SIZEOF_VOID_P == 8
86 .dword 0 /* catch type all */
87 .dword 0 /* handler pc */
89 .dword 0 /* start pc */
90 .word 1 /* extable size */
91 .word 0 /* 4-byte ALIGNMENT PADDING */
92 .dword 0 /* line number table start */
93 .dword 0 /* line number table size */
97 .word 0 /* frame size */
98 .dword 0 /* codeinfo pointer */
100 #else /* SIZEOF_VOID_P == 8 */
102 .word 0 /* catch type all */
103 .word 0 /* handler pc */
105 .word 0 /* start pc */
106 .word 1 /* extable size */
107 .word 0 /* line number table start */
108 .word 0 /* line number table size */
109 .word 0 /* fltsave */
110 .word 0 /* intsave */
112 .word 0 /* frame size */
113 .word 0 /* method pointer (pointer to name) */
115 #endif /* SIZEOF_VOID_P == 8 */
118 asm_vm_call_method_int:
119 asm_vm_call_method_long:
120 asm_vm_call_method_float:
121 asm_vm_call_method_double:
122 .set noreorder /* XXX we need to recompute pv */
124 aaddiu sp,sp,-12*8 /* allocate stack space (only 11 needed)*/
125 ast ra,0*8(sp) /* save return address */
127 bal L_asm_vm_call_method_compute_pv
128 ast pv,1*8(sp) /* procedure vector */
129 L_asm_vm_call_method_compute_pv:
132 ast s0,3*8(sp) /* save callee saved register */
133 ast a0,4*8(sp) /* save method PV */
135 #if SIZEOF_VOID_P == 8
136 sdc1 fss0,5*8(sp) /* save non JavaABI saved flt registers */
144 move t0,a1 /* address of data structure */
145 move t1,a2 /* stack argument count */
146 move s0,sp /* save stack pointer */
148 #if SIZEOF_VOID_P == 8
168 #else /* SIZEOF_VOID_P == 8 */
170 # if WORDS_BIGENDIAN == 1
182 # if !defined(ENABLE_SOFT_FLOAT)
187 #endif /* SIZEOF_VOID_P == 8 */
189 beqz t1,L_asm_vm_call_method_stack_copy_done
192 sll t2,t1,3 /* calculate stackframe size (* 8) */
193 asubu sp,sp,t2 /* create stackframe */
194 move t2,sp /* temporary stack pointer */
196 L_asm_vm_call_method_stack_copy_loop:
197 #if SIZEOF_VOID_P == 8
198 ld t3,16*8(t0) /* load argument */
199 sd t3,0(t2) /* store argument on stack */
201 # if !defined(ENABLE_SOFT_FLOAT)
202 lw t3,6*8+0(t0) /* load argument */
204 sw t3,0(t2) /* store argument on stack */
211 aaddi t1,t1,-1 /* subtract 1 argument */
212 aaddi t0,t0,8 /* load address of next argument */
213 aaddi t2,t2,8 /* increase stack pointer */
215 bgtz t1,L_asm_vm_call_method_stack_copy_loop
218 L_asm_vm_call_method_stack_copy_done:
219 ala mptr,4*8(s0) /* get address of PV */
220 ald pv,0*8(mptr) /* load PV */
223 L_asm_vm_call_method_recompute_pv:
224 #if SIZEOF_VOID_P == 8
225 aaddiu pv,ra,-76*4 /* recompute procedure vector */
227 aaddiu pv,ra,(asm_vm_call_method - L_asm_vm_call_method_recompute_pv)
230 .set reorder /* XXX we need to recompute pv */
232 move sp,s0 /* restore stack pointer */
235 ald ra,0*8(sp) /* restore return address */
236 ald pv,1*8(sp) /* restore procedure vector */
239 #if SIZEOF_VOID_P == 8
240 ldc1 fss0,5*8(sp) /* restore non JavaABI saved flt regs */
248 aaddiu sp,sp,12*8 /* free stack space */
251 asm_vm_call_method_exception_handler:
252 move sp,s0 /* restore stack pointer */
253 #if SIZEOF_VOID_P == 4
254 aaddiu sp,sp,-4*4 /* reserve space for 1 argument */
258 jal builtin_throw_exception
259 #if SIZEOF_VOID_P == 4
262 asm_vm_call_method_end:
265 .end asm_vm_call_method
268 /****************** function asm_call_jit_compiler *****************************
270 * invokes the compiler for untranslated JavaVM methods. *
272 * Register REG_ITEMP1 contains a pointer to the method info structure *
273 * (prepared by createcompilerstub). Using the return address in R31 and the *
274 * offset in the LDA instruction or using the value in methodptr R25 the *
275 * patching address for storing the method address can be computed: *
277 * method address was either loaded using *
278 * M_ALD (REG_PV, REG_PV, a) ; invokestatic/special ($28) *
279 * M_JSR (REG_RA, REG_PV); *
281 * M_LDA (REG_PV, REG_RA, val) *
283 * M_ALD (REG_PV, REG_METHODPTR, m) ; invokevirtual/interface ($25) *
284 * M_JSR (REG_RA, REG_PV); *
286 * in the static case the method pointer can be computed using the *
287 * return address and the lda function following the jmp instruction *
289 *******************************************************************************/
291 .ent asm_call_jit_compiler
293 asm_call_jit_compiler:
294 #if SIZEOF_VOID_P == 8
296 aaddiu sp,sp,-(ARG_CNT+2)*8 /* +2: keep stack 16-bytes aligned */
298 ast ra,0*8(sp) /* save return address */
300 SAVE_ARGUMENT_REGISTERS(1)
302 move a0,itmp1 /* pass methodinfo pointer */
303 move a1,mptr /* pass method pointer */
304 aaddiu a2,sp,(ARG_CNT+2)*8 /* pass java sp */
306 jal jit_asm_compile /* call jit compiler */
309 ald ra,0*8(sp) /* restore return address */
311 RESTORE_ARGUMENT_REGISTERS(1)
313 aaddiu sp,sp,(ARG_CNT+2)*8 /* remove stack frame */
315 #else /* SIZEOF_VOID_P == 8 */
317 aaddiu sp,sp,-(ARG_CNT+2)*8 /* +4: keep stack 16-bytes aligned */
319 ast ra,4*4+0*4(sp) /* save return address */
321 SAVE_ARGUMENT_REGISTERS(6)
323 move a0,itmp1 /* pass methodinfo pointer */
324 move a1,mptr /* pass method pointer */
325 aaddiu a2,sp,(ARG_CNT+2)*8 /* pass java sp */
327 jal jit_asm_compile /* call jit compiler */
330 ald ra,4*4+0*4(sp) /* restore return address */
332 RESTORE_ARGUMENT_REGISTERS(6)
334 aaddiu sp,sp,(ARG_CNT+2)*8 /* remove stack frame */
336 #endif /* SIZEOF_VOID_P == 8 */
338 beqz pv,L_asm_call_jit_compiler_exception
340 jr pv /* and call method. The method returns */
341 /* directly to the caller (ra). */
343 L_asm_call_jit_compiler_exception:
346 jal exceptions_get_and_clear_exception
350 move xptr,v0 /* get exception */
351 aaddiu xpc,ra,-4 /* exception address is RA - 4 */
352 b asm_handle_nat_exception
354 .end asm_call_jit_compiler
357 /* asm_handle_exception ********************************************************
359 This function handles an exception. It does not use the usual calling
360 conventions. The exception pointer is passed in REG_ITMP1 and the
361 pc from the exception raising position is passed in REG_ITMP2. It searches
362 the local exception table for a handler. If no one is found, it unwinds
363 stacks and continues searching the callers.
365 *******************************************************************************/
367 .ent asm_handle_nat_exception
369 asm_handle_nat_exception:
370 L_asm_handle_exception_stack_loop:
371 #if SIZEOF_VOID_P == 8
372 aaddiu sp,sp,-6*8 /* keep stack 16-byte aligned */
373 ast xptr,0*8(sp) /* save exception pointer */
374 ast xpc,1*8(sp) /* save exception pc */
375 ast ra,3*8(sp) /* save RA */
376 ast zero,4*8(sp) /* save maybe-leaf flag (cleared) */
378 aaddiu sp,sp,-(4*4+6*8) /* allocate stack */
379 ast xptr,4*4+0*8(sp) /* save exception pointer */
380 ast xpc,4*4+1*8(sp) /* save exception pc */
381 ast ra,4*4+3*8(sp) /* save return address */
382 ast zero,4*4+4*8(sp) /* save maybe-leaf flag (cleared) */
385 move a0,ra /* pass RA */
386 jal md_codegen_get_pv_from_pc /* get PV from RA */
388 #if SIZEOF_VOID_P == 8
389 ast v0,2*8(sp) /* save PV */
391 ald a0,0*8(sp) /* pass xptr */
392 ald a1,1*8(sp) /* pass xpc */
393 move a2,v0 /* pass PV */
394 aaddiu a3,sp,6*8 /* pass Java SP */
396 ast v0,4*4+2*8(sp) /* save data segment pointer */
398 ald a0,4*4+0*8(sp) /* pass exception pointer */
399 ald a1,4*4+1*8(sp) /* pass exception pc */
400 move a2,v0 /* pass data segment pointer */
401 aaddiu a3,sp,(4*4+6*8) /* pass Java stack pointer */
404 b L_asm_handle_exception_continue
406 .aent asm_handle_exception
408 asm_handle_exception:
409 aaddiu sp,sp,-(ARG_CNT+TMP_CNT)*8 /* create maybe-leaf stackframe */
411 SAVE_ARGUMENT_REGISTERS(0) /* we save arg and temp registers in */
412 SAVE_TEMPORARY_REGISTERS(ARG_CNT) /* case this is a leaf method */
414 #if SIZEOF_VOID_P == 8
415 aaddiu sp,sp,-6*8 /* allocate stack */
416 ast xptr,0*8(sp) /* save exception pointer */
417 ast pv,2*8(sp) /* save PV */
418 ast ra,3*8(sp) /* save RA */
419 addu t0,zero,1 /* set maybe-leaf flag */
420 ast t0,4*8(sp) /* save maybe-leaf flag */
422 aaddiu sp,sp,-(4*4+6*8) /* allocate stack */
423 ast xptr,4*4+0*8(sp) /* save exception pointer */
424 ast xpc,4*4+1*8(sp) /* save exception pc */
425 ast pv,4*4+2*8(sp) /* save data segment pointer */
426 ast ra,4*4+3*8(sp) /* save return address */
427 addu t0,zero,1 /* set maybe-leaf flag */
428 ast t0,4*4+4*8(sp) /* save maybe-leaf flag */
431 move a0,xptr /* pass xptr */
432 move a1,xpc /* pass xpc */
433 move a2,pv /* pass PV */
435 #if SIZEOF_VOID_P == 8
436 aaddiu a3,sp,(ARG_CNT+TMP_CNT+6)*8 /* pass Java SP */
438 aaddiu a3,sp,4*4+(ARG_CNT+TMP_CNT+6)*8 /* pass Java stack pointer */
441 L_asm_handle_exception_continue:
442 jal exceptions_handle_exception
444 beqz v0,L_asm_handle_exception_not_catched
446 move xpc,v0 /* move handlerpc into xpc */
448 #if SIZEOF_VOID_P == 8
449 ald xptr,0*8(sp) /* restore exception pointer */
450 ald pv,2*8(sp) /* restore PV */
451 ald ra,3*8(sp) /* restore RA */
452 ald t0,4*8(sp) /* get maybe-leaf flag */
453 aaddiu sp,sp,6*8 /* free stackframe */
455 ald xptr,4*4+0*8(sp) /* restore exception pointer */
456 ald pv,4*4+2*8(sp) /* restore data segment pointer */
457 ald ra,4*4+3*8(sp) /* restore return address */
458 ald t0,4*4+4*8(sp) /* get maybe-leaf flag */
459 aaddiu sp,sp,4*4+6*8 /* free stackframe */
462 beqz t0,L_asm_handle_exception_no_leaf
464 RESTORE_ARGUMENT_REGISTERS(0) /* if this is a leaf method, we have */
465 RESTORE_TEMPORARY_REGISTERS(ARG_CNT)/* to restore arg and temp registers */
467 aaddiu sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
469 L_asm_handle_exception_no_leaf:
470 jr xpc /* jump to the handler */
472 L_asm_handle_exception_not_catched:
473 #if SIZEOF_VOID_P == 8
474 ald xptr,0*8(sp) /* restore xptr */
475 ald pv,2*8(sp) /* restore PV */
476 ald ra,3*8(sp) /* restore RA */
477 ald t0,4*8(sp) /* get maybe-leaf flag */
478 aaddiu sp,sp,6*8 /* free stackframe */
480 ald xptr,4*4+0*8(sp) /* restore xptr */
481 ald pv,4*4+2*8(sp) /* restore PV */
482 ald ra,4*4+3*8(sp) /* restore RA */
483 ald t0,4*4+4*8(sp) /* get maybe-leaf flag */
484 aaddiu sp,sp,4*4+6*8 /* free stackframe */
487 beqz t0,L_asm_handle_exception_no_leaf_stack
489 aaddiu sp,sp,(ARG_CNT+TMP_CNT)*8 /* remove maybe-leaf stackframe */
490 move t0,zero /* clear the maybe-leaf flag */
492 L_asm_handle_exception_no_leaf_stack:
493 lw t1,FrameSize(pv) /* get frame size */
494 aaddu t1,sp,t1 /* pointer to save area */
496 lw t2,IsLeaf(pv) /* is leaf procedure */
497 bnez t2,L_asm_handle_exception_no_ra_restore
499 ald ra,-1*8(t1) /* restore ra */
500 aaddiu t1,t1,-8 /* t1-- */
502 L_asm_handle_exception_no_ra_restore:
503 move xpc,ra /* the new xpc is ra */
504 lw t2,IntSave(pv) /* t1 = saved int register count */
505 ala t3,ex_int2 /* t3 = current pc */
506 sll t2,t2,2 /* t2 = register count * 4 */
507 asubu t3,t3,t2 /* t3 = IntSave - 4 * register count */
508 jr t3 /* jump to save position */
520 sll t2,t2,1 /* t2 = register count * 4 * 2 */
521 asubu t1,t1,t2 /* t1 = t0 - 8 * register count */
523 lw t2,FltSave(pv) /* t2 = saved flt register count */
524 ala t3,ex_flt2 /* t3 = current pc */
525 sll t2,t2,2 /* t2 = register count * 4 */
526 asubu t3,t3,t2 /* t3 = ex_int_sav - 4 * register count */
527 jr t3 /* jump to save position */
529 #if SIZEOF_VOID_P == 8
534 #else /* SIZEOF_VOID_P == 8 */
535 # if !defined(ENABLE_SOFT_FLOAT)
542 # endif /* !defined(ENABLE_SOFT_FLOAT) */
543 #endif /* SIZEOF_VOID_P == 8 */
546 lw t1,FrameSize(pv) /* get frame size */
547 aaddu sp,sp,t1 /* unwind stack */
548 b L_asm_handle_exception_stack_loop
550 .end asm_handle_nat_exception
553 /* asm_abstractmethoderror *****************************************************
555 Creates and throws an AbstractMethodError.
557 *******************************************************************************/
559 .ent asm_abstractmethoderror
561 asm_abstractmethoderror:
562 aaddiu sp,sp,-2*8 /* create stackframe */
563 ast ra,0*8(sp) /* save return address */
564 aaddiu a0,sp,2*8 /* pass java sp */
565 move a1,ra /* pass exception address */
566 jal exceptions_asm_new_abstractmethoderror
567 ald ra,0*8(sp) /* restore return address */
568 aaddiu sp,sp,2*8 /* remove stackframe */
570 move xptr,v0 /* get exception pointer */
571 aaddiu xpc,ra,-4 /* exception address is ra - 4 */
572 b asm_handle_nat_exception
574 .end asm_abstractmethoderror
577 .ent compare_and_swap
590 .end compare_and_swap
593 /* disable exec-stacks ********************************************************/
595 #if defined(__linux__) && defined(__ELF__)
596 .section .note.GNU-stack,"",%progbits
601 * These are local overrides for various environment variables in Emacs.
602 * Please do not remove this and leave it at the end of the file, where
603 * Emacs will automagically detect them.
604 * ---------------------------------------------------------------------
607 * indent-tabs-mode: t
611 * vim:noexpandtab:sw=4:ts=4: