* Merged with default branch at rev 16f3633aaa5a.
[cacao.git] / src / vm / jit / m68k / emit.c
index 94d1926b3f4ce1f2be1b5a2e11af3b34d524c0e8..f53e321908243d02abd547655ee457b1d68ca351 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: arch.h 5330 2006-09-05 18:43:12Z edwin $
-
 */
 
 
@@ -166,23 +164,23 @@ inline void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
                        case TYPE_DBL:
 #endif
                        case TYPE_LNG:
-                               M_LST(d, REG_SP, dst->vv.regoff * 4);
+                               M_LST(d, REG_SP, dst->vv.regoff);
                                break;
 #if defined(ENABLE_SOFTFLOAT)
                        case TYPE_FLT:
 #endif
                        case TYPE_INT:
-                               M_IST(d, REG_SP, dst->vv.regoff * 4);
+                               M_IST(d, REG_SP, dst->vv.regoff);
                                break;
                        case TYPE_ADR:
-                               M_AST(d, REG_SP, dst->vv.regoff * 4);
+                               M_AST(d, REG_SP, dst->vv.regoff);
                                break;
 #if !defined(ENABLE_SOFTFLOAT)
                        case TYPE_DBL:
-                               M_DST(d, REG_SP, dst->vv.regoff * 4);
+                               M_DST(d, REG_SP, dst->vv.regoff);
                                break;
                        case TYPE_FLT:
-                               M_FST(d, REG_SP, dst->vv.regoff * 4);
+                               M_FST(d, REG_SP, dst->vv.regoff);
                                break;
 #endif
                        default:
@@ -211,7 +209,7 @@ s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
        if (IS_INMEMORY(src->flags)) {
                COUNT_SPILLS;
 
-               disp = src->vv.regoff * 4;
+               disp = src->vv.regoff;
        
                switch (src->type)      {
 #if defined(ENABLE_SOFTFLOAT)
@@ -354,7 +352,7 @@ s4 emit_load_low(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
        if (IS_INMEMORY(src->flags)) {
                COUNT_SPILLS;
 
-               disp = src->vv.regoff * 4;
+               disp = src->vv.regoff;
                M_ILD(tempreg, REG_SP, disp + 4);
                reg = tempreg;
        } else {
@@ -378,7 +376,7 @@ s4 emit_load_high(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
 
        if (IS_INMEMORY(src->flags)) {
                COUNT_SPILLS;
-               disp = src->vv.regoff * 4;
+               disp = src->vv.regoff;
                M_ILD(tempreg, REG_SP, disp);
                reg = tempreg;
        } else {
@@ -481,6 +479,74 @@ void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
        }
 }
 
+/* emit_replacement_stubs ******************************************************
+
+   Generates the code for the replacement stubs.
+
+*******************************************************************************/
+
+#if defined(ENABLE_REPLACEMENT)
+void emit_replacement_stubs(jitdata *jd)
+{
+       codegendata *cd;
+       codeinfo    *code;
+       rplpoint    *rplp;
+       s4           i;
+       s4           branchmpc;
+       s4           outcode;
+
+       /* get required compiler data */
+
+       cd   = jd->cd;
+       code = jd->code;
+
+       rplp = code->rplpoints;
+
+       /* store beginning of replacement stubs */
+
+       code->replacementstubs = (u1*) (cd->mcodeptr - cd->mcodebase);
+
+       for (i = 0; i < code->rplpointcount; ++i, ++rplp) {
+               /* do not generate stubs for non-trappable points */
+
+               if (rplp->flags & RPLPOINT_FLAG_NOTRAP)
+                       continue;
+
+               M_JSR_IMM(0);
+#if 0
+               /* check code segment size */
+
+               MCODECHECK(512);
+
+               /* note start of stub code */
+
+               outcode = (s4) (cd->mcodeptr - cd->mcodebase);
+
+               /* push address of `rplpoint` struct */
+                       
+               M_PUSH_IMM(rplp);
+
+               /* jump to replacement function */
+
+               M_PUSH_IMM(asm_replacement_out);
+               M_RET;
+
+               /* add jump reference for COUNTDOWN points */
+
+               if (rplp->flags & RPLPOINT_FLAG_COUNTDOWN) {
+
+                       branchmpc = (s4)rplp->pc + (7 + 6);
+
+                       md_codegen_patch_branch(cd, branchmpc, (s4) outcode);
+               }
+
+               assert(((cd->mcodeptr - cd->mcodebase) - outcode) == REPLACEMENT_STUB_SIZE);
+#endif
+       }
+}
+#endif /* defined(ENABLE_REPLACEMENT) */
+       
+
 
 #if !defined(NDEBUG)
 /*
@@ -529,10 +595,7 @@ void emit_verbosecall_enter(jitdata* jd)
 
        /* travel up stack to the first argument of the function which needs to be copied */
        for (i=0; (i < md->paramcount) && (i < TRACE_ARGS_NUM); i++)    {
-               disp += 4;
-               if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {   
-                       disp += 4;
-               }
+               disp += 8;
        }
 
        /* disp now points to the first arg which gets copied to the trace stack, relative to REG_SP! */
@@ -541,19 +604,11 @@ void emit_verbosecall_enter(jitdata* jd)
                        /* traced function has such an argument */
                        t = md->paramtypes[i].type;
                        
-                       if (IS_2_WORD_TYPE(t))  {
-                               /* copy from original argument stack */
-                               M_ILD(REG_ITMP1, REG_SP, disp);
-                               M_IPUSH(REG_ITMP1);
-                               M_ILD(REG_ITMP1, REG_SP, disp);
-                               M_IPUSH(REG_ITMP1);
-                       } else  {
-                               /* displacment is increased as 4 byte on original stack but 8 byte on trace stack */
-                               M_ILD(REG_ITMP1, REG_SP, disp);
-                               M_IPUSH(REG_ITMP1);
-                               M_IPUSH_IMM(0);
-                               disp += 4;
-                       }
+                       /* copy from original argument stack */
+                       M_ILD(REG_ITMP1, REG_SP, disp);
+                       M_ILD(REG_ITMP2, REG_SP, disp-4);
+                       M_IPUSH(REG_ITMP2);
+                       M_IPUSH(REG_ITMP1);
                } else  {
                        /* function has no arg here, push nothing and adapt displacement */
                        M_IPUSH_IMM(0);
@@ -602,7 +657,7 @@ void emit_verbosecall_exit(jitdata* jd)
 
 #if !defined(ENABLE_SOFTFLOAT)
        M_AADD_IMM(-8, REG_SP);
-       M_FSTORE(REG_F1, REG_SP, 0);
+       M_FSTORE(REG_D1, REG_SP, 0);
 #endif
 
        M_IPUSH_IMM(m);                                 /* push methodinfo */
@@ -634,7 +689,7 @@ void emit_verbosecall_exit(jitdata* jd)
        M_AADD_IMM(3*4 + 4, REG_SP);
 
 #if !defined(ENABLE_SOFTFLOAT)
-       M_FLOAD(REG_F1, REG_SP, 0)
+       M_FLOAD(REG_D1, REG_SP, 0)
        M_AADD_IMM(8, REG_SP);
 #endif
 
@@ -680,7 +735,7 @@ void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 r
 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_ICMP(s2, REG_ITMP3);
                M_BHI(4);
                M_TRAP_SETREGISTER(s2);