* src/vm/jit/linenumbertable.c: New file.
[cacao.git] / src / vm / jit / sparc64 / asmpart.S
index 6567e1da392e0a839b698eb49b84c4cf0369a7f9..3f5a74b1f25f7a7c747c321ac38560060d9d0dd9 100644 (file)
@@ -1,6 +1,6 @@
-/* src/vm/jit/sparc64/asmpart.S - Java-C interface functions for Sparc
+/* src/vm/jit/sparc64/asmpart.S - Java-C interface functions for Sparc64
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Andreas Krall
-            Reinhard Grafl
-            Alexander Jordan
-
-   Changes: 
-
-   $Id: asmpart.S 4749 2006-04-11 10:20:18Z twisti $
-
 */
 
 
 #include "config.h"
 
-#include "vm/jit/sparc64/md-abi.h"
-#include "offsets.h"
 #include "md-asm.h"
 
+#include "vm/jit/sparc64/md-abi.h"
+
+
        .register %g2,#scratch                         /* define as scratch       */
        .register %g3,#scratch                    /* XXX  reserve for application */
        .text
@@ -53,6 +44,7 @@
        .global asm_vm_call_method_float  
        .global asm_vm_call_method_double 
        .global asm_vm_call_method_exception_handler
+       .global asm_vm_call_method_end
 
        .global asm_call_jit_compiler
 
 
        .global asm_abstractmethoderror
        
-       .global asm_criticalsections
-       .global asm_getclassvalues_atomic
+       .global asm_store_fp_state_reg
+       .global asm_load_fp_state_reg
 
 
 /* asm_vm_call_method ******************************************************
  *                                                                         *
  * This function calls a Java-method (which possibly needs compilation)    *
  *
+ * If the java method is throwing an exception, NULL will be returned.
+ *
  * C-prototype:
  *  java_objectheader *asm_vm_call_method(methodinfo *m, s4 vmargscount,
  *                                              vm_arg *vmargs);
 
        .align 8        /* v9: All data types are aligned to their size */
 
-       .xword 0                         /* catch type all */
-       .xword 0                         /* handler pc */
-       .xword 0                         /* end pc */
-       .xword 0                         /* start pc */
-       .word  1                         /* extable size */
-       .word  0                         /* ALIGNMENT PADDING */
-       .xword 0                         /* line number table start */
-       .xword 0                         /* line number table size */
-       .word  0                         /* ALIGNMENT PADDING */
        .word  0                         /* fltsave */
        .word  1                         /* intsave */
        .word  0                         /* isleaf */
-       .word  0                         /* IsSync */
        .word  0                         /* frame size */
        .xword 0                         /* method pointer (pointer to name)*/ 
 
@@ -100,67 +84,53 @@ asm_vm_call_method_long:
 asm_vm_call_method_float: 
 asm_vm_call_method_double:
        
-       save %sp,-144,%sp                                /* 16 reg-save + 2 */
-
-
-       /* %i2 not needed after _nocopy -> calculate in branch delay */
-
-       brlez %i1, calljava_nocopy
+       save %sp,-((JITSTACK_CNT+2)*8),%sp
+       add %sp,JITSTACK,%l1               /* pointer to usable stack      */
+
+       /* i0: PV               */
+       /* i1: ptr to arg array */
+       /* i2: num stackargs    */
+
+       ldx [%i1+0*8],%o0
+       ldx [%i1+1*8],%o1
+       ldx [%i1+2*8],%o2
+       ldx [%i1+3*8],%o3
+       ldx [%i1+4*8],%o4
+
+       ldd [%i1+5*8],fa0
+       ldd [%i1+6*8],fa1
+       ldd [%i1+7*8],fa2
+       ldd [%i1+8*8],fa3
+       ldd [%i1+9*8],fa4
+
+       brlez %i2, calljava_nocopy
+       nop /* delay: fill me! */
        
-       dec %i1   /* branch delay */
-       ldx [%i2 + offvmargdata],%o0
-       ldd [%i2 + offvmargdata],fa0
-       brlez %i1,calljava_nocopy
-
-       dec %i1   /* branch delay */
-       ldx [%i2 + (offvmargdata+sizevmarg*1)],%o1
-       ldd [%i2 + (offvmargdata+sizevmarg*1)],fa1
-       brlez %i1,calljava_nocopy
-
-       dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*2)],%o2
-       ldd [%i2 + (offvmargdata+sizevmarg*2)],fa2
-       brlez %i1,calljava_nocopy
-
-       dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*3)],%o3
-       ldd [%i2 + (offvmargdata+sizevmarg*3)],fa3
-       brlez %i1,calljava_nocopy
-
-       dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*4)],%o4
-       ldd [%i2 + (offvmargdata+sizevmarg*4)],fa4
-
-calljava_argsloaded:   
-       brlez %i1, calljava_nocopy
-       nop
-       sllx %i1,3,%l0                     /* remaining args * 8           */
-       add %sp,16*8+bias,%l1              /* right above window save area */
+       sllx %i2,3,%l0                     /* remaining args * 8           */
        sub %sp,%l0,%sp                    /* allocate more stack space    */
+       add %sp,JITSTACK,%l1               /* adjust stack begin pointer   */
        
-calljava_copyloop:
-       ldx [%i2 + (offvmargdata+sizevmarg*5)],%l0
-       stx %l0,[%l1]
-       inc sizevmarg,%i2                  /* src++                        */
-       subcc %i1,1,%i1                    /* arg_count--                  */
-       bnz %xcc, calljava_copyloop        /* use cc from previous instr   */
+asm_vm_call_copyloop:
+       ldx [%i1+10*8],%l0                 /* load argument from array     */
+       stx %l0,[%l1]                      /* store argument to stack      */
+
+       inc 8,%i1                          /* src++                        */
+       subcc %i2,1,%i2                    /* arg_count--                  */
+       bnz %xcc, asm_vm_call_copyloop     /* use cc from previous instr   */
        inc 8,%l1                          /* dst++ (delay)                */
-       
+
 
 calljava_nocopy:
        /* set pv, like a java method does */
-       /*      add  ra_caller,(asm_vm_call_method - calljava_nocopy + 8),pv_callee */
        setx  asm_vm_call_method,%l0,pv_callee
        
-       mov   %i0,itmp1         /* pass method info pointer via itmp1 */
+       stx   %i0,[%l1 + 1*8]              /* store PV on stack            */
+       mov   %l1,mptr_itmp2               /* set address of PV (-1*8)     */
        
-       setx  asm_call_jit_compiler,%l0,mptr_itmp2  /* fake virtual function call (2 instr) */
-       stx   mptr_itmp2,[%sp + 2047 + 17*8]        /* store function address               */
-       add   %sp,2047 + 16*8,mptr_itmp2            /* set method pointer                   */
-       
-       ldx  [1*8 + mptr_itmp2], pv_caller          /* method call as in Java               */
-       jmpl pv_caller,ra_caller                      /* call JIT compiler          */
+       ldx  [1*8 + mptr_itmp2], pv_caller /* load PV from stack           */
+       jmpl pv_caller,ra_caller           /* method call as in Java       */
        nop
+
 calljava_jit2:
        /* pretend to restore pv */
        add  ra_caller,(asm_vm_call_method - calljava_jit2 + 8),zero
@@ -181,7 +151,8 @@ asm_vm_call_method_exception_handler:
        call    builtin_throw_exception
        nop
        return  %i7 + 8                          /* implicit window restore */
-       nop
+asm_vm_call_method_end:
+       mov    zero,%o0                  /* delay: return NULL      */
        
 
 
@@ -208,7 +179,8 @@ asm_vm_call_method_exception_handler:
 asm_call_jit_compiler:
        
        /* stacksave for regsave(16) + argslots(6) + float args  */
-       save    %sp,-((16+6+FLT_ARG_CNT)*8),%sp
+       /* Note: +1 to keep stack 16-byte aligned                */
+       save    %sp,-((16+6+FLT_ARG_CNT+1)*8),%sp
 
        SAVE_FLOAT_ARGUMENT_REGISTERS(22)
 
@@ -239,19 +211,14 @@ asm_call_jit_compiler:
 L_asm_call_jit_compiler_exception:
        /* window still open, ra_callee valid, pv_callee undefined      */
 
-       /* get pv for further exception handling */
-       mov     ra_callee,%o0   
-       call    md_codegen_get_pv_from_pc   /* get PV from RA                     */
-       nop
-       mov     %o0,pv_callee
-
        call    exceptions_get_and_clear_exception
        nop
 
        mov     %o0,xptr_itmp2        /* get exception                            */
-       mov     ra_callee,xpc_itmp3 /* exception address is ra               */
+       mov     ra_callee,xpc_itmp3  /* exception address is address of call      */
 
-       /* don't restore callers window, behave like java non-leaf */
+       /* restore the window of the calling function */
+       restore
 
        b      L_asm_handle_nat_exception
        nop
@@ -296,7 +263,7 @@ asm_handle_exception:
        mov     pv_callee,%g4
 
        /* save bigger stack frame for float args and temps */
-       save    %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT)*8),%sp
+       save    %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+16+CSTACK_CNT)*8),%sp
 
        SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
        SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
@@ -387,10 +354,11 @@ asm_patcher_wrapper:
        mov     pv_callee,pv_caller
 
        /* create window and stack frame              */
-       save  %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT+4)*8),%sp
+       save  %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+16+CSTACK_CNT+6)*8),%sp
 
-       SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
-       SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
+       SAVE_FLOAT_RETURN_REGISTER(CSTACK_CNT)
+       SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT+1)
+       SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+1+FLT_ARG_CNT)
 
        mov     itmp1,%l0               /* save itmp1                             */
        mov     itmp2,%l1               /* save itmp2                             */
@@ -401,8 +369,9 @@ asm_patcher_wrapper:
        call    patcher_wrapper
        nop
 
-       RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
-       RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
+       RESTORE_FLOAT_RETURN_REGISTER(CSTACK_CNT)
+       RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT+1)
+       RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+1+FLT_ARG_CNT)
 
        mov     %l0,itmp1               /* restore itmp1                          */
        mov     %l1,itmp2               /* restore itmp2                          */
@@ -427,30 +396,55 @@ L_asm_patcher_wrapper_exception:
        nop
 
 
-asm_getclassvalues_atomic:
-_crit_restart:
-_crit_begin:
-/* not doing a window save, using the global temporary registers */
-       ldsw    [offbaseval+%o0],itmp1
-       ldsw    [offdiffval+%o0],itmp2
-       ldsw    [offbaseval+%o1],itmp3
-_crit_end:
-       stw     itmp1,[offcast_super_baseval+%o2]
-       stw     itmp2,[offcast_super_diffval+%o2]
-       stw     itmp3,[offcast_sub_baseval+%o2]
-       jmpl    ra_caller+8,zero  /* caller's ra, b/c no window save */
+    
+/* asm_store_fp_state_reg **************************************************
+ *                                                                         *
+ * This function stores the 64-bit floating point state register to a      *
+ * memory location. (which needs to be 8-byte aligned)                     *
+ *                                                                         *
+ * C-prototype:                                                            *
+ *  void asm_store_fp_state_reg(u8 *mem);                                  *
+ *                                                                            *
+ **************************************************************************/
+asm_store_fp_state_reg:
+       stx %fsr,[%o0]
+       retl  /* return from leaf */
+       nop
+       
+/* asm_load_fp_state_reg ***************************************************
+ *                                                                         *
+ * This function loades the 64-bit floating point state register from a    *
+ * memory location. (which needs to be 8-byte aligned)                     *
+ *                                                                         *
+ * C-prototype:                                                            *
+ *  void asm_load_fp_state_reg(u8 *mem);                                   *
+ *                                                                            *
+ **************************************************************************/
+asm_load_fp_state_reg:
+       ldx [%o0],%fsr
+       retl  /* return from leaf */
        nop
 
 
-    .data
+/* disable exec-stacks ********************************************************/
 
-asm_criticalsections:
-#if defined(ENABLE_THREADS)
-    .xword   _crit_begin
-    .xword   _crit_end
-    .xword   _crit_restart
+#if defined(__linux__) && defined(__ELF__)
+       .section .note.GNU-stack,"",%progbits
 #endif
-    .xword   0
-
 
 
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: asm
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */