* Removed all Id tags.
[cacao.git] / src / vm / jit / powerpc64 / emit.c
index eca64506c727a887998807e768f53942842d9ec5..041f8da4d347b4e8be6c909fe4161385d0c2cbf6 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: emitfuncs.c 4398 2006-01-31 23:43:08Z twisti $
-
 */
 
 
@@ -71,7 +69,7 @@ s4 emit_load(jitdata *jd, instruction *iptr, varinfo *src, s4 tempreg)
        if (src->flags & INMEMORY) {
                COUNT_SPILLS;
 
-               disp = src->vv.regoff * 8;
+               disp = src->vv.regoff;
 
                if (IS_FLT_DBL_TYPE(src->type)) {
                        M_DLD(tempreg, REG_SP, disp);
@@ -107,10 +105,10 @@ void emit_store(jitdata *jd, instruction *iptr, varinfo *dst, s4 d)
                COUNT_SPILLS;
 
                if (IS_FLT_DBL_TYPE(dst->type)) {
-                       M_DST(d, REG_SP, dst->vv.regoff * 8);
+                       M_DST(d, REG_SP, dst->vv.regoff);
                }
                else {
-                       M_LST(d, REG_SP, dst->vv.regoff * 8);
+                       M_LST(d, REG_SP, dst->vv.regoff);
                }
        }
 }
@@ -255,7 +253,7 @@ void emit_verbosecall_enter(jitdata *jd)
                        if (!md->params[p].inmemory) { /* Param in Arg Reg */
                                M_LST(md->params[p].regoff, REG_SP, LA_SIZE + PA_SIZE + 8 + p * 8);
                        } else { /* Param on Stack */
-                               s1 = (md->params[p].regoff + cd->stackframesize) * 8 + stack_size;
+                               s1 = md->params[p].regoff + cd->stackframesize * 8 + stack_size;
                                M_LLD(REG_ITMP2, REG_SP, s1);
                                M_LST(REG_ITMP2, REG_SP, LA_SIZE + PA_SIZE + 8 + p * 8);
                        }
@@ -431,7 +429,6 @@ void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
                        /* if the long-branches flag isn't set yet, do it */
 
                        if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
-                               log_println("setting error");
                                cd->flags |= (CODEGENDATA_FLAG_ERROR |
                                                          CODEGENDATA_FLAG_LONGBRANCHES);
                        }
@@ -449,11 +446,9 @@ void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
                        /* if the long-branches flag isn't set yet, do it */
 
                        if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
-                               log_println("setting error");
                                cd->flags |= (CODEGENDATA_FLAG_ERROR |
                                                          CODEGENDATA_FLAG_LONGBRANCHES);
                        }
-                       log_println("generating long-branch");
 
                        branchdisp --;          /* we jump from the second instruction */
                        switch (condition) {
@@ -530,12 +525,12 @@ void emit_arrayindexoutofbounds_check(codegendata *cd, instruction *iptr, s4 s1,
        if (checkbounds) {
 #define SOFTEX 0
 #if SOFTEX
-               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
+               M_ILD(REG_ITMP3, s1, OFFSET(java_array_t, size));
                M_CMPU(s2, REG_ITMP3);
                codegen_add_arrayindexoutofboundsexception_ref(cd, s2);
                BRANCH_NOPS;
 #else
-               M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));
+               M_ILD(REG_ITMP3, s1, OFFSET(java_array_t, size));
                M_CMPU(s2, REG_ITMP3);
                M_BLT(1);
                /* ALD is 4 byte aligned, ILD 2, onyl LWZ is byte aligned */
@@ -760,110 +755,37 @@ void emit_patcher_stubs(jitdata *jd)
 }
 
 
-/* emit_replacement_stubs ******************************************************
+/* emit_trap *******************************************************************
 
-   Generates the code for the replacement stubs.
+   Emit a trap instruction and return the original machine code.
 
 *******************************************************************************/
 
-#if defined(ENABLE_REPLACEMENT)
-void emit_replacement_stubs(jitdata *jd)
+uint32_t emit_trap(codegendata *cd)
 {
-       codegendata *cd;
-       codeinfo    *code;
-       rplpoint    *replacementpoint;
-       s4           disp;
-       s4           i;
-#if !defined(NDEBUG)
-       u1          *savedmcodeptr;
-#endif
-
-       /* get required compiler data */
-
-       cd   = jd->cd;
-       code = jd->code;
-
-       replacementpoint = jd->code->rplpoints;
-
-       for (i = 0; i < code->rplpointcount; ++i, ++replacementpoint) {
-               /* do not generate stubs for non-trappable points */
-
-               if (replacementpoint->flags & RPLPOINT_FLAG_NOTRAP)
-                       continue;
-
-
-               /* check code segment size */
-
-               MCODECHECK(200);
-
-#if !defined(NDEBUG)
-               savedmcodeptr = cd->mcodeptr;
-#endif
-               /* create stack frame - keep 16-byte aligned */
-
-               M_AADD_IMM(REG_SP, -4 * 8, REG_SP);
-
-               /* push address of `rplpoint` struct */
-
-               disp = dseg_add_address(cd, replacementpoint);
-               M_ALD(REG_ITMP3, REG_PV, disp);
-               M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 8);
-
-               /* jump to replacement function */
-
-               disp = dseg_add_functionptr(cd, asm_replacement_out);
-               M_ALD(REG_ITMP3, REG_PV, disp);
-               M_MTCTR(REG_ITMP3);
-               M_RTS;
-
-               assert((cd->mcodeptr - savedmcodeptr) == 4*REPLACEMENT_STUB_SIZE);
-
-#if 0
-               /* note start of stub code */
-
-               replacementpoint->outcode = (u1 *) (cd->mcodeptr - cd->mcodebase);
-
-               /* make machine code for patching */
-
-               savedmcodeptr  = cd->mcodeptr;
-               cd->mcodeptr = (u1 *) &(replacementpoint->mcode) + 1 /* big-endian */;
+       uint32_t mcode;
 
-               disp = (ptrint)((s4*)replacementpoint->outcode - (s4*)replacementpoint->pc) - 1;
-               M_BR(disp);
-
-               cd->mcodeptr = savedmcodeptr;
-
-               /* create stack frame - keep 16-byte aligned */
+       /* Get machine code which is patched back in later. The
+          trap is 1 instruction word long. */
 
-               M_AADD_IMM(REG_SP, -4 * 4, REG_SP);
-
-               /* push address of `rplpoint` struct */
-
-               disp = dseg_add_unique_address(cd, replacementpoint);
-               M_ALD(REG_ITMP3, REG_PV, disp);
-               M_AST_INTERN(REG_ITMP3, REG_SP, 0 * 4);
+       mcode = *((uint32_t *) cd->mcodeptr);
 
-               /* jump to replacement function */
+       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
 
-               disp = dseg_add_functionptr(cd, asm_replacement_out);
-               M_ALD(REG_ITMP3, REG_PV, disp);
-               M_MTCTR(REG_ITMP3);
-               M_RTS;
-#endif
-       }
+       return mcode;
 }
-#endif /* define(ENABLE_REPLACEMENT) */
+
 
 /*
-* 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: c
-* indent-tabs-mode: t
-* c-basic-offset: 4
-* tab-width: 4
-* End:
-* vim:noexpandtab:sw=4:ts=4:
-*/
+ * 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: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ * vim:noexpandtab:sw=4:ts=4:
+ */