Merged revisions 7940-8026 via svnmerge from
[cacao.git] / src / vm / jit / sparc64 / asmpart.S
index 3d008a5ac9563319207f70284ce235ae87f02170..b135b6559702ba31b65dba3cbcb80cfb5d583360 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 $
 
 */
@@ -53,6 +45,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_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);
@@ -100,63 +98,105 @@ asm_vm_call_method_long:
 asm_vm_call_method_float: 
 asm_vm_call_method_double:
        
-       save %sp, -144, %sp             /* 16 reg-save + 2 */
+       save %sp,-((JITSTACK_CNT+2)*8),%sp
+       add %sp,JITSTACK,%l1               /* right above window save area */
 
 
-       /* todo: copy fp registers */
+       /* %i1 not needed after _nocopy -> calculate in branch delay */
 
-       brlez %i1, calljava_argsloaded
-       dec %i1
-       ldx [%i2 + offvmargdata], %o0
-       brlez %i1, calljava_argsloaded
-
-       dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*1)], %o1
-       brlez %i1, calljava_argsloaded
+       brlez %i1, calljava_nocopy
+       
+       dec %i1   /* branch delay */
+       ldx [%i2 + offvmargdata],%o0
+       ldx [%i2 + offvmargtype],%l2
+       cmp %l2,2
+       be,a %xcc,calljava_arg0isfloat
+       ld  [%i2 + offvmargdata],fa0f   /* delay: annulled if branch not taken */
+       ldd [%i2 + offvmargdata],fa0
+calljava_arg0isfloat:
+       brlez %i1,calljava_nocopy
+
+       dec %i1   /* branch delay */
+       ldx [%i2 + (offvmargdata+sizevmarg*1)],%o1
+       ldx [%i2 + (offvmargtype+sizevmarg*1)],%l2
+       cmp %l2,2
+       be,a %xcc,calljava_arg1isfloat
+       ld  [%i2 + (offvmargdata+sizevmarg*1)],fa1f
+       ldd [%i2 + (offvmargdata+sizevmarg*1)],fa1
+calljava_arg1isfloat:
+       brlez %i1,calljava_nocopy
 
        dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*2)], %o2
-       brlez %i1, calljava_argsloaded
+       ldx [%i2 + (offvmargdata+sizevmarg*2)],%o2
+       ldx [%i2 + (offvmargtype+sizevmarg*2)],%l2
+       cmp %l2,2
+       be,a %xcc,calljava_arg2isfloat
+       ld  [%i2 + (offvmargdata+sizevmarg*2)],fa2f
+       ldd [%i2 + (offvmargdata+sizevmarg*2)],fa2
+calljava_arg2isfloat:
+       brlez %i1,calljava_nocopy
 
        dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*3)], %o3
-       brlez %i1, calljava_argsloaded
+       ldx [%i2 + (offvmargdata+sizevmarg*3)],%o3
+       ldx [%i2 + (offvmargtype+sizevmarg*3)],%l2
+       cmp %l2,2
+       be,a %xcc,calljava_arg3isfloat
+       ld  [%i2 + (offvmargdata+sizevmarg*3)],fa3f
+       ldd [%i2 + (offvmargdata+sizevmarg*3)],fa3
+calljava_arg3isfloat:
+       brlez %i1,calljava_nocopy
 
        dec %i1
-       ldx [%i2 + (offvmargdata+sizevmarg*4)], %o4
-
-       /* todo: use more out registers ? */
-
-calljava_argsloaded:
-       /* todo: stack frame layout!! */
-       
+       ldx [%i2 + (offvmargdata+sizevmarg*4)],%o4
+       ldx [%i2 + (offvmargtype+sizevmarg*4)],%l2
+       cmp %l2,2
+       be,a %xcc,calljava_arg4isfloat
+       ld  [%i2 + (offvmargdata+sizevmarg*4)],fa4f
+       ldd [%i2 + (offvmargdata+sizevmarg*4)],fa4
+calljava_arg4isfloat:
+
+calljava_argsloaded:   
        brlez %i1, calljava_nocopy
-       sllx %i1, 3, %l0        /* remaining args * 8           */
-       mov %sp, %l1            /* right above window save area */
-       sub %sp, %l0, %sp       /* allocate more stack space    */
+       nop
+       sllx %i1,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++                        */
-       inc 8, %l1              /* dst++                        */
-       dec %i1                 /* arg_count--                  */
-       bnz %xcc, calljava_copyloop
+       ldx [%i2 + (offvmargtype+sizevmarg*5)],%l2
+       cmp %l2,2
+       be  %xcc,calljava_copyloop_float
+       nop
+       ldx [%i2 + (offvmargdata+sizevmarg*5)],%l0
+       stx %l0,[%l1]
+       b   calljava_copy_done
+calljava_copyloop_float:
+       ld  [%i2 + (offvmargdata+sizevmarg*5)],%f1      
+       std %f0,[%l1]
+calljava_copy_done:
+       inc sizevmarg,%i2                  /* src++                        */
+       subcc %i1,1,%i1                    /* arg_count--                  */
+       bnz %xcc, calljava_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 */
        
        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                   */
+       stx   mptr_itmp2,[%l1 + 1*8]        /* store function address               */
+       mov   %l1,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          */
        nop
 calljava_jit2:
        /* pretend to restore pv */
-       add  ra_caller,(asm_vm_call_method - calljava_jit2 + 8),pv_callee
+       add  ra_caller,(asm_vm_call_method - calljava_jit2 + 8),zero
        
 calljava_return:
        mov %o0, %i0            /* pass on the return value     */
@@ -166,11 +206,16 @@ calljava_return:
 
 asm_vm_call_method_exception_handler:
        
-       mov             itmp1,%o0
+       /* so far this function did not call any c functions */
+       /* but now we need ABI compliant argslots on the stack */
+       sub   %sp,6*8,%sp
+       
+       mov             xptr_itmp2,%o0
        call    builtin_throw_exception
        nop
        return  %i7 + 8                          /* implicit window restore */
-       nop
+asm_vm_call_method_end:
+       mov    zero,%o0                  /* delay: return NULL      */
        
 
 
@@ -196,7 +241,9 @@ asm_vm_call_method_exception_handler:
 
 asm_call_jit_compiler:
        
-       save    %sp,-208,%sp         /* regsave(16) + argslots(6) + 4 float args  */
+       /* stacksave for regsave(16) + argslots(6) + float args  */
+       /* Note: +1 to keep stack 16-byte aligned                */
+       save    %sp,-((16+6+FLT_ARG_CNT+1)*8),%sp
 
        SAVE_FLOAT_ARGUMENT_REGISTERS(22)
 
@@ -227,19 +274,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
@@ -284,10 +326,10 @@ asm_handle_exception:
        mov     pv_callee,%g4
 
        /* save bigger stack frame for float args and temps */
-       save    %sp,(FLT_ARG_CNT+FLT_TMP_CNT+ABICALL_OFF)*8,%sp
+       save    %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT)*8),%sp
 
-       SAVE_FLOAT_ARGUMENT_REGISTERS(ABICALL_OFF)
-       SAVE_FLOAT_TEMPORARY_REGISTERS(ABICALL_OFF+FLT_ARG_CNT)
+       SAVE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
+       SAVE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
 
        mov     xptr_itmp2,%l0              /* save exception pointer             */
        add     zero,1,%l2                  /* set maybe-leaf flag                */
@@ -310,8 +352,8 @@ L_asm_handle_exception_continue:
        brz     %l2,L_asm_handle_exception_no_leaf
        nop
 
-       RESTORE_FLOAT_ARGUMENT_REGISTERS(ABICALL_OFF)
-       RESTORE_FLOAT_TEMPORARY_REGISTERS(ABICALL_OFF+FLT_ARG_CNT)
+       RESTORE_FLOAT_ARGUMENT_REGISTERS(CSTACK_CNT)
+       RESTORE_FLOAT_TEMPORARY_REGISTERS(CSTACK_CNT+FLT_ARG_CNT)
        
 L_asm_handle_exception_no_leaf:
        /* restore java window and stackframe (ra and pv are in there) */
@@ -326,7 +368,7 @@ L_asm_handle_exception_not_caught:
        
        restore                             /* unwind stack and window            */
        ba      L_asm_handle_exception_stack_loop
-       mov     xpc_itmp3,ra_caller         /* the new xpc is ra (delay)          */
+       mov     ra_caller,xpc_itmp3         /* the new xpc is ra (delay)          */
        
 
 
@@ -375,44 +417,82 @@ asm_patcher_wrapper:
        mov     pv_callee,pv_caller
 
        /* create window and stack frame              */
-       save  %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+ABICALL_OFF+4)*8),%sp
+       save  %sp,-((FLT_ARG_CNT+FLT_TMP_CNT+CSTACK_CNT+6)*8),%sp
 
-       SAVE_FLOAT_ARGUMENT_REGISTERS(ABICALL_OFF)
-       SAVE_FLOAT_TEMPORARY_REGISTERS(ABICALL_OFF+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                             */
 
-       add     %fp,USESTACK,%o0      /* pass pseudo SP                           */
+       add     %fp,JITSTACK,%o0      /* pass pseudo SP                           */
        mov     pv_callee,%o1         /* pass PV                                  */
        mov     ra_callee,%o2         /* pass RA (correct for leafs)              */
        call    patcher_wrapper
        nop
 
-       RESTORE_FLOAT_ARGUMENT_REGISTERS(ABICALL_OFF)
-       RESTORE_FLOAT_TEMPORARY_REGISTERS(ABICALL_OFF+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                          */
 
        brnz    %o0,L_asm_patcher_wrapper_exception
+       nop
 
        /* load RA (patch position from patcher data on the stack */
-       ldx     [%fp+USESTACK+5*8],itmp3
+       ldx     [%fp+JITSTACK+5*8],itmp3
 
        /* remove window and stack frame (and stack space allocated in the stub code */
        restore  %fp,6*8,%sp /* (source regs refer to old window, rd to new window)  */
 
        jmpl     itmp3,zero              /* jump to newly patched code               */
+       nop
 
 L_asm_patcher_wrapper_exception:
-       mov      itmp3,xptr_itmp2      /* get exception                            */
-       ldx      [%fp+USESTACK+5*8],xpc_itmp3 /* xpc is RA                         */
+       mov      %o0,xptr_itmp2        /* get exception                            */
+       ldx      [%fp+JITSTACK+5*8],xpc_itmp3 /* xpc is RA                         */
        restore  %fp,6*8,%sp           /* remove stack frame                       */
        ba       asm_handle_exception
        nop
 
 
+    
+/* 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
+
+
+
+
 asm_getclassvalues_atomic:
 _crit_restart:
 _crit_begin:
@@ -424,9 +504,8 @@ _crit_end:
        stw     itmp1,[offcast_super_baseval+%o2]
        stw     itmp2,[offcast_super_diffval+%o2]
        stw     itmp3,[offcast_sub_baseval+%o2]
-       jmpl    ra_caller,zero  /* caller's ra, b/c no window save */
-
-       .end    asm_getclassvalues_atomic
+       jmpl    ra_caller+8,zero  /* caller's ra, b/c no window save */
+       nop
 
 
     .data
@@ -438,6 +517,25 @@ asm_criticalsections:
     .xword   _crit_restart
 #endif
     .xword   0
+    
 
+/* disable exec-stacks ********************************************************/
+
+#if defined(__linux__) && defined(__ELF__)
+       .section .note.GNU-stack,"",%progbits
+#endif
 
 
+/*
+ * 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:
+ */