* Moved all files from vmcore/ to vm/.
[cacao.git] / src / vm / jit / sparc64 / emit.c
index 49ab597428a524fcab28dae587173a205c90c12e..db4b4ba05f5bb99796fb2ca354f4896f8b909a3d 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/sparc64/emit.c - SPARC code emitter functions
 
-   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
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -22,8 +20,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: emit.c 4398 2006-01-31 23:43:08Z twisti $
-
 */
 
 
 
 #include "mm/memory.h"
 
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
+#include "vm/builtin.h"
+#include "vm/options.h"
+
+#include "vm/jit/abi.h"
 #include "vm/jit/abi-asm.h"
 #include "vm/jit/asmpart.h"
-#include "vm/builtin.h"
 #include "vm/jit/dseg.h"
 #include "vm/jit/emit-common.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/replace.h"
 
-#include "vmcore/options.h"
+#include "vm/jit/sparc64/solaris/macro_rename.h"
 
 /* how to leaf optimization in the emitted stubs?? */
 #define REG_PV REG_PV_CALLEE
@@ -72,9 +69,9 @@ s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
        cd = jd->cd;
 
        if (src->flags & INMEMORY) {
-               COUNT_SPILLS;
+               COUNT_READ_SPILLS(src)
 
-               disp = JITSTACK + src->vv.regoff * 8;
+               disp = JITSTACK + src->vv.regoff;
 
                switch(src->type)
                {
@@ -117,10 +114,10 @@ void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
        cd = jd->cd;
 
        if (dst->flags & INMEMORY) {
-               COUNT_SPILLS;
+               COUNT_WRITE_SPILLS(dst)
 
-               disp = JITSTACK + dst->vv.regoff * 8;                   
-                       
+               disp = JITSTACK + dst->vv.regoff;
+       
                switch(dst->type)
                {
                case TYPE_INT:
@@ -156,7 +153,6 @@ void emit_copy(jitdata *jd, instruction *iptr)
        /* get required compiler data */
 
        cd = jd->cd;
-       rd = jd->rd;
 
        /* get source and destination variables */
 
@@ -461,7 +457,7 @@ void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_BNEZ(reg, 3);
                M_NOP;
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_ARITHMETIC);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_ArithmeticException);
        }
 }
 
@@ -475,11 +471,27 @@ void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
 void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1, s4 s2)
 {
        if (INSTRUCTION_MUST_CHECK(iptr)) {
-               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
+               M_ILD(REG_ITMP3, s1, OFFSET(java_array_t, size));
                M_CMP(s2, REG_ITMP3);
                M_XBULT(3);
                M_NOP;
-               M_ALD_INTERN(s2, REG_ZERO, EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
+               M_ALD_INTERN(s2, REG_ZERO, TRAP_ArrayIndexOutOfBoundsException);
+       }
+}
+
+
+/* emit_arraystore_check *******************************************************
+
+   Emit an ArrayStoreException check.
+
+*******************************************************************************/
+
+void emit_arraystore_check(codegendata *cd, instruction *iptr)
+{
+       if (INSTRUCTION_MUST_CHECK(iptr)) {
+               M_BNEZ(REG_RESULT_CALLER, 3);
+               M_NOP;
+               M_ALD_INTERN(REG_RESULT_CALLER, REG_ZERO, TRAP_ArrayStoreException);
        }
 }
 
@@ -513,7 +525,7 @@ void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 r
                }
 
                M_NOP;
-               M_ALD_INTERN(s1, REG_ZERO, EXCEPTION_HARDWARE_CLASSCAST);
+               M_ALD_INTERN(s1, REG_ZERO, TRAP_ClassCastException);
        }
 }
 
@@ -529,7 +541,7 @@ void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_BNEZ(reg, 3);
                M_NOP;
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
        }
 }
 
@@ -545,11 +557,32 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_BNEZ(REG_RESULT_CALLER, 3);
                M_NOP;
-               M_ALD_INTERN(REG_RESULT_CALLER, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);
+               M_ALD_INTERN(REG_RESULT_CALLER, REG_ZERO, TRAP_CHECK_EXCEPTION);
        }
 }
 
 
+/* emit_trap *******************************************************************
+
+   Emit a trap instruction and return the original machine code.
+
+*******************************************************************************/
+
+uint32_t emit_trap(codegendata *cd)
+{
+       uint32_t mcode;
+
+       /* Get machine code which is patched back in later. The
+          trap is 1 instruction word long. */
+
+       mcode = *((uint32_t *) cd->mcodeptr);
+
+       M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_PATCHER);
+
+       return mcode;
+}
+
+
 /* emit_patcher_stubs **********************************************************
 
    Generates the code for the patcher stubs.
@@ -680,18 +713,6 @@ void emit_patcher_stubs(jitdata *jd)
 }
 
 
-/* emit_replacement_stubs ******************************************************
-
-   Generates the code for the replacement stubs.
-
-*******************************************************************************/
-
-#if defined(ENABLE_REPLACEMENT)
-void emit_replacement_stubs(jitdata *jd)
-{
-}
-#endif /* defined(ENABLE_REPLACEMENT) */
-
 /* emit_verbosecall_enter ******************************************************
 
    Generates the code for the call trace.
@@ -707,6 +728,7 @@ void emit_verbosecall_enter(jitdata *jd)
        methoddesc   *md;
        s4            disp;
        s4            i, t;
+       s4            stackslots;
 
        /* get required compiler data */
 
@@ -721,16 +743,19 @@ void emit_verbosecall_enter(jitdata *jd)
        M_NOP;
 
        /* XXX jit-c-call */
-       M_LDA(REG_SP, REG_SP, -(1 + FLT_ARG_CNT) * 8);
+       stackslots = 1 + FLT_ARG_CNT;
+       ALIGN_STACK_SLOTS(stackslots);
+
+       M_LDA(REG_SP, REG_SP, -(stackslots * 8));
 
        /* save float argument registers */
 
        for (i = 0; i < FLT_ARG_CNT; i++)
-               M_DST(rd->argfltregs[i], REG_SP, JITSTACK + (1 + i) * 8);
+               M_DST(abi_registers_float_argument[i], REG_SP, JITSTACK + (1 + i) * 8);
 
        /* save temporary registers for leaf methods */
 /* XXX no leaf optimization yet
-       if (jd->isleafmethod) {
+       if (code_is_leafmethod(code)) {
                for (i = 0; i < INT_TMP_CNT; i++)
                        M_LST(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
 
@@ -743,11 +768,12 @@ void emit_verbosecall_enter(jitdata *jd)
        for (i = 0; i < md->paramcount && i < INT_NATARG_CNT; i++) {
                t = md->paramtypes[i].type;
 
-               /* using all available argument registers, this adds complexity */
+               /* all available argument registers used, which adds a little complexity */
                
                if (IS_INT_LNG_TYPE(t)) {
                        if (i < INT_ARG_CNT) {
-                               M_INTMOVE(REG_WINDOW_TRANSPOSE(rd->argintregs[i]), rd->argintregs[i]);
+                               M_INTMOVE(REG_WINDOW_TRANSPOSE(abi_registers_integer_argument[i]), 
+                                       abi_registers_integer_argument[i]);
                        }
                        else {
                                assert(i == 5);
@@ -755,20 +781,36 @@ void emit_verbosecall_enter(jitdata *jd)
                        }
                }
                else {
-                       assert(i < 4); /* XXX only 4 float reg args right now! */
-                       if (IS_2_WORD_TYPE(t)) {
-                               M_DST(rd->argfltregs[i], REG_SP, JITSTACK);
-                               M_LDX(rd->argintregs[i], REG_SP, JITSTACK);
+                       if (i < FLT_ARG_CNT) {
+                               
+                               /* reg -> mem -> reg */
+                               
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_DST(abi_registers_float_argument[i], REG_SP, JITSTACK);
+                                       M_LDX(abi_registers_integer_argument[i], REG_SP, JITSTACK);
+                               }
+                               else {
+                                       M_FST(abi_registers_float_argument[i], REG_SP, JITSTACK);
+                                       M_ILD(abi_registers_integer_argument[i], REG_SP, JITSTACK);
+                               }
                        }
                        else {
-                               M_FST(rd->argfltregs[i], REG_SP, JITSTACK);
-                               M_ILD(rd->argintregs[i], REG_SP, JITSTACK);
+                               
+                               /* mem -> reg */
+                               
+                               assert(i == 5);
+                               if (IS_2_WORD_TYPE(t)) {
+                                       M_LDX(REG_OUT5, REG_FP, JITSTACK);
+                               }
+                               else {
+                                       M_ILD(REG_OUT5, REG_FP, JITSTACK);
+                               }
                        }
                }
        }
        
        
-       /* method info pointer is passed in argument register 5 */
+       /* method info pointer is passed via stack */
        disp = dseg_add_address(cd, m);
        M_ALD(REG_ITMP1, REG_PV_CALLEE, disp);
        M_AST(REG_ITMP1, REG_SP, CSTACK);
@@ -780,11 +822,11 @@ void emit_verbosecall_enter(jitdata *jd)
        /* restore float argument registers */
 
        for (i = 0; i < FLT_ARG_CNT; i++)
-               M_DLD(rd->argfltregs[i], REG_SP, JITSTACK + (1 + i) * 8);
+               M_DLD(abi_registers_float_argument[i], REG_SP, JITSTACK + (1 + i) * 8);
 
        /* restore temporary registers for leaf methods */
 /* XXX no leaf optimization yet
-       if (jd->isleafmethod) {
+       if (code_is_leafmethod(code)) {
                for (i = 0; i < INT_TMP_CNT; i++)
                        M_LLD(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
 
@@ -792,7 +834,7 @@ void emit_verbosecall_enter(jitdata *jd)
                        M_DLD(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
        }
 */
-       M_LDA(REG_SP, REG_SP, (1 + FLT_ARG_CNT) * 8);
+       M_LDA(REG_SP, REG_SP, stackslots * 8);
 
        /* mark trace code */
 
@@ -825,17 +867,17 @@ void emit_verbosecall_exit(jitdata *jd)
 
        M_NOP;
        
-       /* XXX jit-c-call */
-       M_LDA(REG_SP, REG_SP, -(1 * 8));
+       /* XXX jit-c-call (keep stack aligned)*/
+       M_LDA(REG_SP, REG_SP, -(2 * 8));
 
        M_DST(REG_FRESULT, REG_SP, JITSTACK);
 
-       M_MOV(REG_RESULT_CALLEE, rd->argintregs[0]);
+       M_MOV(REG_RESULT_CALLEE, REG_OUT0);
        M_DMOV(REG_FRESULT, 1); /* logical dreg 1 => f2 */
        M_FMOV(REG_FRESULT, 2); /* logical freg 2 => f5 */
 
        disp = dseg_add_functionptr(cd, m);
-       M_ALD(rd->argintregs[3], REG_PV_CALLEE, disp);
+       M_ALD(REG_OUT3, REG_PV_CALLEE, disp);
 
        disp = dseg_add_functionptr(cd, builtin_verbosecall_exit);
        M_ALD(REG_ITMP3, REG_PV_CALLEE, disp);
@@ -844,7 +886,7 @@ void emit_verbosecall_exit(jitdata *jd)
 
        M_DLD(REG_FRESULT, REG_SP, JITSTACK);
 
-       M_LDA(REG_SP, REG_SP, 1 * 8);
+       M_LDA(REG_SP, REG_SP, 2 * 8);
 
        /* mark trace code */