* src/vm/jit/powerpc64/linux/md-os.c: Simplified signal handlers.
[cacao.git] / src / vm / jit / powerpc64 / md.c
index fd10194005ec08b1eda76b8b2dd65b2318f47424..0b61ced6ab70e89be1029ded302f05d6af239afc 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/powerpc64/md.c - machine dependent PowerPC 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, 2009
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -157,6 +155,60 @@ void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
 }
 
 
+/**
+ * Decode the trap instruction at the given PC.
+ *
+ * @param trp information about trap to be filled
+ * @param sig signal number
+ * @param xpc exception PC
+ * @param es execution state of the machine
+ * @return true if trap was decoded successfully, false otherwise.
+ */
+bool md_trap_decode(trapinfo_t* trp, int sig, void* xpc, executionstate_t* es)
+{
+       // Get the throwing instruction.
+       uint32_t mcode = *((uint32_t*) xpc);
+
+       switch (sig) {
+       case TRAP_SIGILL:
+               // Check for valid trap instruction.
+               if (mcode == 0x00000000) {
+                       trp->type  = TRAP_PATCHER;
+                       trp->value = 0;
+                       return true;
+               }
+               return false;
+
+       case TRAP_SIGSEGV:
+       {
+               // Decode the throwing instruction.
+               int     s1   = M_INSTR_OP2_IMM_A(mcode);
+               int16_t disp = M_INSTR_OP2_IMM_I(mcode);
+               int     d    = M_INSTR_OP2_IMM_D(mcode);
+
+               // We use the exception type as load displacement.
+               if (s1 == REG_ZERO) {
+                       trp->type  = disp;
+                       trp->value = es->intregs[d];
+                       return true;
+               }
+
+               // Default case is a normal NullPointerException.
+               if (es->intregs[s1] == 0) {
+                       trp->type  = TRAP_NullPointerException;
+                       trp->value = 0;
+                       return true;
+               }
+
+               return false;
+       }
+
+       default:
+               return false;
+       }
+}
+
+
 /* md_patch_replacement_point **************************************************
 
    Patch the given replacement point.