* Merged with 60f051a3c5ae.
[cacao.git] / src / vm / jit / alpha / emit.c
index 84c3bf3ea9cd981e9f760aed213589814054caa3..63f1fbab4c6dc194525b4f96f80bedfd04456bc0 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: emit.c 8318 2007-08-16 10:05:34Z michi $
-
 */
 
 
@@ -41,7 +39,6 @@
 
 #include "threads/lock-common.h"
 
-#include "vm/builtin.h"
 #include "vm/exceptions.h"
 
 #include "vm/jit/abi.h"
@@ -52,6 +49,7 @@
 #include "vm/jit/jit.h"
 #include "vm/jit/patcher-common.h"
 #include "vm/jit/replace.h"
+#include "vm/jit/trace.h"
 
 #include "vmcore/options.h"
 
@@ -351,6 +349,23 @@ void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1,
 }
 
 
+/* emit_arraystore_check *******************************************************
+
+   Emit an ArrayStoreException check.
+
+*******************************************************************************/
+
+void emit_arraystore_check(codegendata *cd, instruction *iptr)
+{
+       if (INSTRUCTION_MUST_CHECK(iptr)) {
+               M_BNEZ(REG_RESULT, 1);
+               /* Destination register must not be REG_ZERO, because then no
+                  SIGSEGV is thrown. */
+               M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_ARRAYSTORE);
+       }
+}
+
+
 /* emit_classcast_check ********************************************************
 
    Emit a ClassCastException check.
@@ -409,6 +424,18 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 }
 
 
+/* emit_trap_compiler **********************************************************
+
+   Emit a trap instruction which calls the JIT compiler.
+
+*******************************************************************************/
+
+void emit_trap_compiler(codegendata *cd)
+{
+       M_ALD_INTERN(REG_METHODPTR, REG_ZERO, EXCEPTION_HARDWARE_COMPILER);
+}
+
+
 /* emit_trap *******************************************************************
 
    Emit a trap instruction and return the original machine code.
@@ -442,17 +469,20 @@ uint32_t emit_trap(codegendata *cd)
 void emit_verbosecall_enter(jitdata *jd)
 {
        methodinfo   *m;
+       codeinfo     *code;
        codegendata  *cd;
        registerdata *rd;
        methoddesc   *md;
+       int32_t       stackframesize;
        s4            disp;
-       s4            i, t;
+       s4            i, j, s;
 
        /* get required compiler data */
 
-       m  = jd->m;
-       cd = jd->cd;
-       rd = jd->rd;
+       m    = jd->m;
+       code = jd->code;
+       cd   = jd->cd;
+       rd   = jd->rd;
 
        md = m->parseddesc;
 
@@ -460,73 +490,100 @@ void emit_verbosecall_enter(jitdata *jd)
 
        M_NOP;
 
-       M_LDA(REG_SP, REG_SP, -((ARG_CNT + TMP_CNT + 2) * 8));
-       M_AST(REG_RA, REG_SP, 1 * 8);
+       stackframesize = ARG_CNT + TMP_CNT + md->paramcount + 1;
 
-       /* save argument registers */
+       M_LDA(REG_SP, REG_SP, -(stackframesize * 8));
+       M_AST(REG_RA, REG_SP, 0 * 8);
 
-       for (i = 0; i < INT_ARG_CNT; i++)
-               M_LST(abi_registers_integer_argument[i], REG_SP, (2 + i) * 8);
+       /* save all argument and temporary registers for leaf methods */
 
-       for (i = 0; i < FLT_ARG_CNT; i++)
-               M_DST(abi_registers_float_argument[i], REG_SP, (2 + INT_ARG_CNT + i) * 8);
+       if (code_is_leafmethod(code)) {
+               j = 1 + md->paramcount;
 
-       /* save temporary registers for leaf methods */
+               for (i = 0; i < INT_ARG_CNT; i++, j++)
+                       M_LST(abi_registers_integer_argument[i], REG_SP, j * 8);
 
-       if (jd->isleafmethod) {
-               for (i = 0; i < INT_TMP_CNT; i++)
-                       M_LST(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
+               for (i = 0; i < FLT_ARG_CNT; i++, j++)
+                       M_DST(abi_registers_float_argument[i], REG_SP, j * 8);
 
-               for (i = 0; i < FLT_TMP_CNT; i++)
-                       M_DST(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
+               for (i = 0; i < INT_TMP_CNT; i++, j++)
+                       M_LST(rd->tmpintregs[i], REG_SP, j * 8);
+
+               for (i = 0; i < FLT_TMP_CNT; i++, j++)
+                       M_DST(rd->tmpfltregs[i], REG_SP, j * 8);
        }
 
-       /* load float arguments into integer registers */
+       /* save argument registers */
 
-       for (i = 0; i < md->paramcount && i < INT_ARG_CNT; i++) {
-               t = md->paramtypes[i].type;
+       for (i = 0; i < md->paramcount; i++) {
+               if (!md->params[i].inmemory) {
+                       s = md->params[i].regoff;
 
-               if (IS_FLT_DBL_TYPE(t)) {
-                       if (IS_2_WORD_TYPE(t)) {
-                               M_DST(abi_registers_float_argument[i], REG_SP, 0 * 8);
-                               M_LLD(abi_registers_integer_argument[i], REG_SP, 0 * 8);
-                       }
-                       else {
-                               M_FST(abi_registers_float_argument[i], REG_SP, 0 * 8);
-                               M_ILD(abi_registers_integer_argument[i], REG_SP, 0 * 8);
+                       switch (md->paramtypes[i].type) {
+                       case TYPE_ADR:
+                       case TYPE_INT:
+                       case TYPE_LNG:
+                               M_LST(s, REG_SP, (1 + i) * 8);
+                               break;
+                       case TYPE_FLT:
+                       case TYPE_DBL:
+                               M_DST(s, REG_SP, (1 + i) * 8);
+                               break;
                        }
                }
        }
 
        disp = dseg_add_address(cd, m);
-       M_ALD(REG_ITMP1, REG_PV, disp);
-       M_AST(REG_ITMP1, REG_SP, 0 * 8);
-       disp = dseg_add_functionptr(cd, builtin_verbosecall_enter);
+       M_ALD(REG_A0, REG_PV, disp);
+       M_AADD_IMM(REG_SP, 1 * 8, REG_A1);
+       M_LDA(REG_A2, REG_SP, stackframesize * 8 + cd->stackframesize * 8);
+
+       disp = dseg_add_functionptr(cd, trace_java_call_enter);
        M_ALD(REG_PV, REG_PV, disp);
        M_JSR(REG_RA, REG_PV);
        disp = (s4) (cd->mcodeptr - cd->mcodebase);
        M_LDA(REG_PV, REG_RA, -disp);
-       M_ALD(REG_RA, REG_SP, 1 * 8);
+       M_ALD(REG_RA, REG_SP, 0 * 8);
 
        /* restore argument registers */
 
-       for (i = 0; i < INT_ARG_CNT; i++)
-               M_LLD(abi_registers_integer_argument[i], REG_SP, (2 + i) * 8);
+       for (i = 0; i < md->paramcount; i++) {
+               if (!md->params[i].inmemory) {
+                       s = md->params[i].regoff;
 
-       for (i = 0; i < FLT_ARG_CNT; i++)
-               M_DLD(abi_registers_float_argument[i], REG_SP, (2 + INT_ARG_CNT + i) * 8);
+                       switch (md->paramtypes[i].type) {
+                       case TYPE_ADR:
+                       case TYPE_INT:
+                       case TYPE_LNG:
+                               M_LLD(s, REG_SP, (1 + i) * 8);
+                               break;
+                       case TYPE_FLT:
+                       case TYPE_DBL:
+                               M_DLD(s, REG_SP, (1 + i) * 8);
+                               break;
+                       }
+               }
+       }
+
+       /* restore all argument and temporary registers for leaf methods */
+
+       if (code_is_leafmethod(code)) {
+               j = 1 + md->paramcount;
+
+               for (i = 0; i < INT_ARG_CNT; i++, j++)
+                       M_LLD(abi_registers_integer_argument[i], REG_SP, j * 8);
 
-       /* restore temporary registers for leaf methods */
+               for (i = 0; i < FLT_ARG_CNT; i++, j++)
+                       M_DLD(abi_registers_float_argument[i], REG_SP, j * 8);
 
-       if (jd->isleafmethod) {
-               for (i = 0; i < INT_TMP_CNT; i++)
-                       M_LLD(rd->tmpintregs[i], REG_SP, (2 + ARG_CNT + i) * 8);
+               for (i = 0; i < INT_TMP_CNT; i++, j++)
+                       M_LLD(rd->tmpintregs[i], REG_SP, j * 8);
 
-               for (i = 0; i < FLT_TMP_CNT; i++)
-                       M_DLD(rd->tmpfltregs[i], REG_SP, (2 + ARG_CNT + INT_TMP_CNT + i) * 8);
+               for (i = 0; i < FLT_TMP_CNT; i++, j++)
+                       M_DLD(rd->tmpfltregs[i], REG_SP, j * 8);
        }
 
-       M_LDA(REG_SP, REG_SP, (ARG_CNT + TMP_CNT + 2) * 8);
+       M_LDA(REG_SP, REG_SP, stackframesize * 8);
 
        /* mark trace code */
 
@@ -539,8 +596,6 @@ void emit_verbosecall_enter(jitdata *jd)
 
    Generates the code for the call trace.
 
-   void builtin_verbosecall_exit(s8 l, double d, float f, methodinfo *m);
-
 *******************************************************************************/
 
 #if !defined(NDEBUG)
@@ -549,6 +604,7 @@ void emit_verbosecall_exit(jitdata *jd)
        methodinfo   *m;
        codegendata  *cd;
        registerdata *rd;
+       methoddesc   *md;
        s4            disp;
 
        /* get required compiler data */
@@ -557,34 +613,55 @@ void emit_verbosecall_exit(jitdata *jd)
        cd = jd->cd;
        rd = jd->rd;
 
+       md = m->parseddesc;
+
        /* mark trace code */
 
        M_NOP;
 
-       M_ASUB_IMM(REG_SP, 4 * 8, REG_SP);
+       M_ASUB_IMM(REG_SP, 2 * 8, REG_SP);
        M_AST(REG_RA, REG_SP, 0 * 8);
 
-       M_LST(REG_RESULT, REG_SP, 1 * 8);
-       M_DST(REG_FRESULT, REG_SP, 2 * 8);
-
-       M_MOV(REG_RESULT, REG_A0);
-       M_FMOV(REG_FRESULT, REG_FA1);
-       M_FMOV(REG_FRESULT, REG_FA2);
+       /* save return value */
+
+       switch (md->returntype.type) {
+       case TYPE_ADR:
+       case TYPE_INT:
+       case TYPE_LNG:
+               M_LST(REG_RESULT, REG_SP, 1 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DST(REG_FRESULT, REG_SP, 1 * 8);
+               break;
+       }
 
        disp = dseg_add_address(cd, m);
-       M_ALD(REG_A3, REG_PV, disp);
+       M_ALD(REG_A0, REG_PV, disp);
+       M_AADD_IMM(REG_SP, 1 * 8, REG_A1);
 
-       disp = dseg_add_functionptr(cd, builtin_verbosecall_exit);
+       disp = dseg_add_functionptr(cd, trace_java_call_exit);
        M_ALD(REG_PV, REG_PV, disp);
        M_JSR(REG_RA, REG_PV);
        disp = (cd->mcodeptr - cd->mcodebase);
        M_LDA(REG_PV, REG_RA, -disp);
 
-       M_DLD(REG_FRESULT, REG_SP, 2 * 8);
-       M_LLD(REG_RESULT, REG_SP, 1 * 8);
+       /* restore return value */
+
+       switch (md->returntype.type) {
+       case TYPE_ADR:
+       case TYPE_INT:
+       case TYPE_LNG:
+               M_LLD(REG_RESULT, REG_SP, 1 * 8);
+               break;
+       case TYPE_FLT:
+       case TYPE_DBL:
+               M_DLD(REG_FRESULT, REG_SP, 1 * 8);
+               break;
+       }
 
        M_ALD(REG_RA, REG_SP, 0 * 8);
-       M_AADD_IMM(REG_SP, 4 * 8, REG_SP);
+       M_AADD_IMM(REG_SP, 2 * 8, REG_SP);
 
        /* mark trace code */