merged volatile memory barriers
[cacao.git] / src / vm / jit / mips / linux / md-os.c
index ff49c55deb62d5b26d2d7794a3fbce83e60d1144..f48ca785803a4468b54bd94fa0db3976747b3174 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
 
-   Copyright (C) 1996-2005, 2006, 2007, 2008
+   Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 #include "vm/jit/mips/md.h"
 #include "vm/jit/mips/md-abi.h"
 
-#include "mm/gc-common.h"
-#include "mm/memory.h"
+#include "mm/gc.hpp"
+#include "mm/memory.hpp"
 
-#include "vm/exceptions.h"
-#include "vm/signallocal.h"
+#include "vm/signallocal.hpp"
 
-#include "vm/jit/asmpart.h"
 #include "vm/jit/executionstate.h"
-#include "vm/jit/stacktrace.h"
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
 
 
 /* md_init *********************************************************************
@@ -78,55 +75,21 @@ void md_init(void)
 }
 
 
-/* md_signal_handler_sigsegv ***************************************************
-
-   NullPointerException signal handler for hardware null pointer
-   check.
-
-*******************************************************************************/
-
+/**
+ * NullPointerException signal handler for hardware null pointer check.
+ */
 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
-       ucontext_t     *_uc;
-       mcontext_t     *_mc;
-       greg_t         *_gregs;
-       u1             *pv;
-       u1             *sp;
-       u1             *ra;
-       u1             *xpc;
-       unsigned int    cause;
-       u4              mcode;
-       int             d;
-       int             s1;
-       int16_t         disp;
-       intptr_t        val;
-       intptr_t        addr;
-       int             type;
-       void           *p;
-
-       _uc    = (struct ucontext *) _p;
-       _mc    = &_uc->uc_mcontext;
-
-#if defined(__UCLIBC__)
-       _gregs = _mc->gpregs;
-#else  
-       _gregs = _mc->gregs;
-#endif
-
-       /* In glibc's ucontext.h the registers are defined as long long,
-          even for MIPS32, so we cast them.  This is not the case for
-          uClibc. */
-
-       pv  = (u1 *) (ptrint) _gregs[REG_PV];
-       sp  = (u1 *) (ptrint) _gregs[REG_SP];
-       ra  = (u1 *) (ptrint) _gregs[REG_RA];        /* this is correct for leafs */
+       int disp = 0;
+       int cause;
+       ucontext_t* _uc = (struct ucontext *) _p;
+       mcontext_t* _mc = &_uc->uc_mcontext;
+       void *xpc;
 
 #if !defined(__UCLIBC__)
 # if ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
        /* NOTE: We only need this for pre glibc-2.5. */
 
-       xpc = (u1 *) (ptrint) _mc->pc;
-
        /* get the cause of this exception */
 
        cause = _mc->cause;
@@ -142,104 +105,38 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
        case 0x00000010:
                /* AdEL: XPC is of the following instruction */
-               xpc = xpc - 4;
+               disp -= 4;
                break;
        }
+       xpc = (void*) (_mc->pc + disp);
 # else
-       xpc = (u1 *) (ptrint) _mc->pc;
+       xpc = (void*) _mc->pc;
 # endif
 #else
-       xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
+       xpc = (void*) _gregs[CTX_EPC];
 #endif
 
-       /* get exception-throwing instruction */
-
-       mcode = *((u4 *) xpc);
-
-       d    = M_ITYPE_GET_RT(mcode);
-       s1   = M_ITYPE_GET_RS(mcode);
-       disp = M_ITYPE_GET_IMM(mcode);
-
-       /* check for special-load */
-
-       if (s1 == REG_ZERO) {
-               /* we use the exception type as load displacement */
-
-               type = disp;
-               val  = _gregs[d];
-
-               if (type == TRAP_COMPILER) {
-                       /* The XPC is the RA minus 4, because the RA points to the
-                          instruction after the call. */
-
-                       xpc = ra - 4;
-               }
-       }
-       else {
-               /* This is a normal NPE: addr must be NULL and the NPE-type
-                  define is 0. */
-
-               addr = _gregs[s1];
-               type = (int) addr;
-               val  = 0;
-       }
-
-       /* Handle the trap. */
+       // Handle the trap.
+       trap_handle(TRAP_SIGSEGV, xpc, _p);
+}
 
-       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* Set registers. */
+/**
+ * Illegal Instruction signal handler for hardware exception checks.
+ */
+void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
+{
+       ucontext_t* _uc = (struct ucontext *) _p;
+       mcontext_t* _mc = &_uc->uc_mcontext;
 
-       switch (type) {
-       case TRAP_COMPILER:
-               if (p != NULL) {
-                       _gregs[REG_PV]  = (uintptr_t) p;
-#if defined(__UCLIBC__)
-                       _gregs[CTX_EPC] = (uintptr_t) p;
+#if !defined(__UCLIBC__)
+       void* xpc = (void*) _mc->pc;
 #else
-                       _mc->pc         = (uintptr_t) p;
+       void* xpc = (void*) _gregs[CTX_EPC];
 #endif
-                       break;
-               }
-
-               /* Get and set the PV from the parent Java method. */
-
-               pv = md_codegen_get_pv_from_pc(ra);
 
-               _gregs[REG_PV] = (uintptr_t) pv;
-
-               /* Get the exception object. */
-
-               p = builtin_retrieve_exception();
-
-               assert(p != NULL);
-
-               /* fall-through */
-
-       case TRAP_PATCHER:
-               if (p == NULL) {
-                       /* We set the PC again because the cause may have changed
-                          the XPC. */
-
-#if defined(__UCLIBC__)
-                       _gregs[CTX_EPC] = (uintptr_t) xpc;
-#else
-                       _mc->pc         = (uintptr_t) xpc;
-#endif
-                       break;
-               }
-
-               /* fall-through */
-               
-       default:
-               _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
-               _gregs[REG_ITMP2_XPC]  = (uintptr_t) xpc;
-#if defined(__UCLIBC__)
-               _gregs[CTX_EPC]        = (uintptr_t) asm_handle_exception;
-#else
-               _mc->pc                = (uintptr_t) asm_handle_exception;
-#endif
-       }
+       // Handle the trap.
+       trap_handle(TRAP_SIGILL, xpc, _p);
 }
 
 
@@ -267,8 +164,6 @@ void md_executionstate_read(executionstate_t* es, void* context)
        greg_t*     _gregs;
        int         i;
 
-       vm_abort("md_executionstate_read: PLEASE REVISE ME!");
-
        _uc = (ucontext_t*) context;
        _mc = &_uc->uc_mcontext;
 
@@ -305,7 +200,7 @@ void md_executionstate_read(executionstate_t* es, void* context)
           _mc->fpregs[i] can cause invalid conversions. */
 
        assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
-       system_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
+       os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
 }
 
 
@@ -322,11 +217,15 @@ void md_executionstate_write(executionstate_t* es, void* context)
        greg_t*     _gregs;
        int         i;
 
-       vm_abort("md_executionstate_write: PLEASE REVISE ME!");
-
        _uc = (ucontext_t *) context;
        _mc = &_uc->uc_mcontext;
 
+#if defined(__UCLIBC__)
+       _gregs = _mc->gpregs;
+#else  
+       _gregs = _mc->gregs;
+#endif
+
        /* Write integer registers. */
 
        for (i = 0; i < INT_REG_CNT; i++)
@@ -338,7 +237,7 @@ void md_executionstate_write(executionstate_t* es, void* context)
           _mc->fpregs[i] can cause invalid conversions. */
 
        assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
-       system_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
+       os_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
 
        /* Write special registers. */