* src/vm/jit/trap.c: Moved to C++
[cacao.git] / src / vm / jit / powerpc / emit.c
index 724ff58f1b7b5c817b5c49e9f997aaa304277e43..6065246b943c8de4a401b28c7f928537b8adee51 100644 (file)
@@ -34,9 +34,9 @@
 
 #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/options.h"
 
@@ -48,7 +48,7 @@
 #include "vm/jit/jit.hpp"
 #include "vm/jit/replace.hpp"
 #include "vm/jit/trace.hpp"
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
 
 
 /* emit_load *******************************************************************
@@ -344,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 {
@@ -533,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 = *((uint32_t *) 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, TRAP_PATCHER);
+       M_ILLEGAL;
 
        return mcode;
 }