* Removed all Id tags.
[cacao.git] / src / vm / jit / sparc64 / emit.c
index 49ab597428a524fcab28dae587173a205c90c12e..dc89473eab6eb8d8837f1a5836ac5bfc1d075de1 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: emit.c 4398 2006-01-31 23:43:08Z twisti $
-
 */
 
 
@@ -41,6 +39,7 @@
 
 #include "vm/exceptions.h"
 #include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
+#include "vm/jit/abi.h"
 #include "vm/jit/abi-asm.h"
 #include "vm/jit/asmpart.h"
 #include "vm/builtin.h"
@@ -51,6 +50,8 @@
 
 #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 +73,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 +118,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 +157,6 @@ void emit_copy(jitdata *jd, instruction *iptr)
        /* get required compiler data */
 
        cd = jd->cd;
-       rd = jd->rd;
 
        /* get source and destination variables */
 
@@ -475,7 +475,7 @@ 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;
@@ -550,6 +550,27 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 }
 
 
+/* 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 = *((u4 *) cd->mcodeptr);
+
+       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
+
+       return mcode;
+}
+
+
 /* emit_patcher_stubs **********************************************************
 
    Generates the code for the patcher stubs.
@@ -680,18 +701,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 +716,7 @@ void emit_verbosecall_enter(jitdata *jd)
        methoddesc   *md;
        s4            disp;
        s4            i, t;
+       s4            stackslots;
 
        /* get required compiler data */
 
@@ -721,12 +731,15 @@ 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
@@ -743,11 +756,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 +769,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,7 +810,7 @@ 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
@@ -792,7 +822,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 +855,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 +874,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 */