* src/vm/jit/trap.c: Moved to C++
[cacao.git] / src / vm / jit / powerpc / emit.c
index 238c4d8112245de01a6bfd00e3580a3940bd8869..6065246b943c8de4a401b28c7f928537b8adee51 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/powerpc/emit.c - PowerPC 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.
 
 
 #include "vm/jit/powerpc/codegen.h"
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
 
-#include "vm/exceptions.h"
+#include "vm/options.h"
 
 #include "vm/jit/abi.h"
 #include "vm/jit/asmpart.h"
-#include "vm/jit/codegen-common.h"
+#include "vm/jit/codegen-common.hpp"
 #include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
-#include "vm/jit/replace.h"
-#include "vm/jit/trace.h"
-
-#include "vmcore/options.h"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/trace.hpp"
+#include "vm/jit/trap.hpp"
 
 
 /* emit_load *******************************************************************
@@ -347,36 +344,46 @@ void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
                                                          CODEGENDATA_FLAG_LONGBRANCHES);
                        }
 
-                       switch (condition) {
-                       case BRANCH_EQ:
-                               M_BNE(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_NE:
-                               M_BEQ(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_LT:
-                               M_BGE(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_GE:
-                               M_BLT(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_GT:
-                               M_BLE(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_LE:
-                               M_BGT(1);
-                               M_BR(branchdisp);
-                               break;
-                       case BRANCH_NAN:
-                               vm_abort("emit_branch: long BRANCH_NAN");
-                               break;
-                       default:
-                               vm_abort("emit_branch: unknown condition %d", condition);
+                       // Subtract 1 instruction from the displacement as the
+                       // actual branch is the second instruction.
+                       checkdisp  = checkdisp - 4;
+                       branchdisp = branchdisp - 1;
+
+                       if ((checkdisp < (int32_t) 0xfe000000) || (checkdisp > (int32_t) 0x01fffffc)) {
+                               vm_abort("emit_branch: emit conditional long-branch code");
+                       }
+                       else {
+                               switch (condition) {
+                               case BRANCH_EQ:
+                                       M_BNE(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_NE:
+                                       M_BEQ(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_LT:
+                                       M_BGE(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_GE:
+                                       M_BLT(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_GT:
+                                       M_BLE(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_LE:
+                                       M_BGT(1);
+                                       M_BR(branchdisp);
+                                       break;
+                               case BRANCH_NAN:
+                                       vm_abort("emit_branch: long BRANCH_NAN");
+                                       break;
+                               default:
+                                       vm_abort("emit_branch: unknown condition %d", condition);
+                               }
                        }
                }
                else {
@@ -421,7 +428,7 @@ void emit_arithmetic_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TST(reg);
                M_BNE(1);
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_ARITHMETIC);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_ArithmeticException);
        }
 }
 
@@ -452,7 +459,7 @@ void emit_arraystore_check(codegendata *cd, instruction *iptr)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TST(REG_RESULT);
                M_BNE(1);
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_ARRAYSTORE);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_ArrayStoreException);
        }
 }
 
@@ -479,7 +486,7 @@ void emit_classcast_check(codegendata *cd, instruction *iptr, s4 condition, s4 r
                default:
                        vm_abort("emit_classcast_check: unknown condition %d", condition);
                }
-               M_ALD_INTERN(s1, REG_ZERO, EXCEPTION_HARDWARE_CLASSCAST);
+               M_ALD_INTERN(s1, REG_ZERO, TRAP_ClassCastException);
        }
 }
 
@@ -495,7 +502,7 @@ void emit_nullpointer_check(codegendata *cd, instruction *iptr, s4 reg)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TST(reg);
                M_BNE(1);
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
        }
 }
 
@@ -511,7 +518,7 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
        if (INSTRUCTION_MUST_CHECK(iptr)) {
                M_TST(REG_RESULT);
                M_BNE(1);
-               M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);
+               M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_CHECK_EXCEPTION);
        }
 }
 
@@ -524,7 +531,7 @@ void emit_exception_check(codegendata *cd, instruction *iptr)
 
 void emit_trap_compiler(codegendata *cd)
 {
-       M_ALD_INTERN(REG_METHODPTR, REG_ZERO, EXCEPTION_HARDWARE_COMPILER);
+       M_ALD_INTERN(REG_METHODPTR, REG_ZERO, TRAP_COMPILER);
 }
 
 
@@ -536,14 +543,11 @@ void emit_trap_compiler(codegendata *cd)
 
 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);
+       // Get machine code which is patched back in later. The rap is 1
+       // instruction word long.
+       uint32_t mcode = *((uint32_t*) cd->mcodeptr);
 
-       M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
+       M_ILLEGAL;
 
        return mcode;
 }