* Merged in twisti-branch.
[cacao.git] / src / vm / jit / powerpc / linux / md-os.c
index c3f5ad36a9a6453c954804e48af2c0b6db5072a4..89ccfe8f96aee87cbd81a29394ef3d27581517ba 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/powerpc/linux/md-os.c - machine dependent PowerPC Linux functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   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
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   $Id: md-os.c 5939 2006-11-09 09:54:00Z twisti $
+   $Id: md-os.c 7592 2007-03-28 20:12:33Z twisti $
 
 */
 
@@ -38,6 +34,7 @@
 
 #include "vm/types.h"
 
+#include "vm/jit/powerpc/codegen.h"
 #include "vm/jit/powerpc/linux/md-abi.h"
 
 #if defined(ENABLE_THREADS)
 
 /* md_signal_handler_sigsegv ***************************************************
 
-   NullPointerException signal handler for hardware null pointer
-   check.
+   Signal handler for hardware-exceptions.
 
 *******************************************************************************/
 
 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t  *_uc;
-       mcontext_t  *_mc;
-       u4           instr;
-       s4           reg;
-       ptrint       addr;
-       u1          *pv;
-       u1          *sp;
-       u1          *ra;
-       u1          *xpc;
+       ucontext_t        *_uc;
+       mcontext_t        *_mc;
+       u1                *pv;
+       u1                *sp;
+       u1                *ra;
+       u1                *xpc;
+       u4                 mcode;
+       s4                 s1;
+       s4                 disp;
+       s4                 d;
+       ptrint             addr;
+       ptrint             val;
+       s4                 type;
+       java_objectheader *o;
 
        _uc = (ucontext_t *) _p;
        _mc = _uc->uc_mcontext.uc_regs;
 
-       instr = *((u4 *) _mc->gregs[PT_NIP]);
-       reg = (instr >> 16) & 0x1f;
-       addr = _mc->gregs[reg];
-
        pv  = (u1 *) _mc->gregs[REG_PV];
        sp  = (u1 *) _mc->gregs[REG_SP];
        ra  = (u1 *) _mc->gregs[PT_LNK];         /* this is correct for leafs */
        xpc = (u1 *) _mc->gregs[PT_NIP];
 
-       if (addr == 0) {
-               _mc->gregs[REG_ITMP1_XPTR] =
-                       (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
+       /* get exception-throwing instruction */
+
+       mcode = *((u4 *) xpc);
+
+       s1   = M_INSTR_OP2_IMM_A(mcode);
+       disp = M_INSTR_OP2_IMM_I(mcode);
+       d    = M_INSTR_OP2_IMM_D(mcode);
 
-               _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
-               _mc->gregs[PT_NIP] = (ptrint) asm_handle_exception;
+       val  = _mc->gregs[d];
+
+       /* check for special-load */
+
+       if (s1 == REG_ZERO) {
+               /* we use the exception type as load displacement */
+
+               type = disp;
        }
        else {
-               codegen_get_pv_from_pc(xpc);
+               /* This is a normal NPE: addr must be NULL and the NPE-type
+                  define is 0. */
+
+               addr = _mc->gregs[s1];
+               type = (s4) addr;
+       }
+
+       /* generate appropriate exception */
+
+       o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
+
+       /* set registers */
+
+       _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
+       _mc->gregs[REG_ITMP2_XPC]  = (ptrint) xpc;
+       _mc->gregs[PT_NIP]         = (ptrint) asm_handle_exception;
+}
+
+
+/* md_signal_handler_sigtrap ***************************************************
+
+   Signal handler for hardware-traps.
+
+*******************************************************************************/
+
+void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
+{
+       ucontext_t        *_uc;
+       mcontext_t        *_mc;
+       u1                *pv;
+       u1                *sp;
+       u1                *ra;
+       u1                *xpc;
+       u4                 mcode;
+       s4                 s1;
+       ptrint             val;
+       s4                 type;
+       java_objectheader *o;
+
+       _uc = (ucontext_t *) _p;
+       _mc = _uc->uc_mcontext.uc_regs;
+
+       pv  = (u1 *) _mc->gregs[REG_PV];
+       sp  = (u1 *) _mc->gregs[REG_SP];
+       ra  = (u1 *) _mc->gregs[PT_LNK];         /* this is correct for leafs */
+       xpc = (u1 *) _mc->gregs[PT_NIP];
+
+       /* get exception-throwing instruction */
+
+       mcode = *((u4 *) xpc);
+
+       s1 = M_OP3_GET_A(mcode);
+
+       /* for now we only handle ArrayIndexOutOfBoundsException */
+
+       type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
+       val  = _mc->gregs[s1];
+
+       /* generate appropriate exception */
+
+       o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
 
-               /* this should not happen */
+       /* set registers */
 
-               assert(0);
-       }               
+       _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
+       _mc->gregs[REG_ITMP2_XPC]  = (ptrint) xpc;
+       _mc->gregs[PT_NIP]         = (ptrint) asm_handle_exception;
 }