Merged revisions 8245-8298 via svnmerge from
[cacao.git] / src / vm / jit / powerpc / linux / md-os.c
index 139a5e9c9ba3f099899ecd08b33ca8cad0d128e2..ce41acbcf04a684ef2e14aebbc5c2f2e202033b9 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: md-os.c 7616 2007-03-29 23:21:50Z michi $
+   $Id: md-os.c 8283 2007-08-09 15:10:05Z twisti $
 
 */
 
@@ -30,6 +30,7 @@
 #include "config.h"
 
 #include <assert.h>
+#include <stdint.h>
 #include <ucontext.h>
 
 #include "vm/types.h"
 
 void md_signal_handler_sigsegv(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;
-       s4                 disp;
-       s4                 d;
-       ptrint             addr;
-       ptrint             val;
-       s4                 type;
-       java_objectheader *o;
+       stackframeinfo  sfi;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       unsigned long  *_gregs;
+       u1             *pv;
+       u1             *sp;
+       u1             *ra;
+       u1             *xpc;
+       u4              mcode;
+       int             s1;
+       int16_t         disp;
+       int             d;
+       intptr_t        addr;
+       intptr_t        val;
+       int             type;
+       void           *p;
 
        _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];
+#if defined(__UCLIBC__)
+       _mc    = &(_uc->uc_mcontext);
+       _gregs = _mc->regs->gpr;
+#else
+       _mc    = _uc->uc_mcontext.uc_regs;
+       _gregs = _mc->gregs;
+#endif
+
+       pv  = (u1 *) _gregs[REG_PV];
+       sp  = (u1 *) _gregs[REG_SP];
+       ra  = (u1 *) _gregs[PT_LNK];                 /* this is correct for leafs */
+       xpc = (u1 *) _gregs[PT_NIP];
 
        /* get exception-throwing instruction */
 
@@ -92,7 +102,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        disp = M_INSTR_OP2_IMM_I(mcode);
        d    = M_INSTR_OP2_IMM_D(mcode);
 
-       val  = _mc->gregs[d];
+       val  = _gregs[d];
 
        /* check for special-load */
 
@@ -105,23 +115,32 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                /* This is a normal NPE: addr must be NULL and the NPE-type
                   define is 0. */
 
-               addr = _mc->gregs[s1];
+               addr = _gregs[s1];
+               type = EXCEPTION_HARDWARE_NULLPOINTER;
 
-               if (addr == 0)
+               if (addr != 0)
                        vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
-
-               type = (s4) addr;
        }
 
-       /* generate appropriate exception */
+       /* create stackframeinfo */
 
-       o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
 
-       /* set registers */
+       /* Handle the type. */
+
+       p = signal_handle(xpc, type, val);
+
+       /* remove stackframeinfo */
+
+       stacktrace_remove_stackframeinfo(&sfi);
 
-       _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
-       _mc->gregs[REG_ITMP2_XPC]  = (ptrint) xpc;
-       _mc->gregs[PT_NIP]         = (ptrint) asm_handle_exception;
+       /* set registers (only if exception object ready) */
+
+       if (p != NULL) {
+               _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
+               _gregs[REG_ITMP2_XPC]  = (intptr_t) xpc;
+               _gregs[PT_NIP]         = (intptr_t) asm_handle_exception;
+       }
 }
 
 
@@ -133,25 +152,34 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
 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;
+       stackframeinfo  sfi;
+       ucontext_t     *_uc;
+       mcontext_t     *_mc;
+       unsigned long  *_gregs;
+       u1             *pv;
+       u1             *sp;
+       u1             *ra;
+       u1             *xpc;
+       u4              mcode;
+       int             s1;
+       intptr_t        val;
+       int             type;
+       void           *p;
 
        _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];
+#if defined(__UCLIBC__)
+       _mc    = &(_uc->uc_mcontext);
+       _gregs = _mc->regs->gpr;
+#else
+       _mc    = _uc->uc_mcontext.uc_regs;
+       _gregs = _mc->gregs;
+#endif
+
+       pv  = (u1 *) _gregs[REG_PV];
+       sp  = (u1 *) _gregs[REG_SP];
+       ra  = (u1 *) _gregs[PT_LNK];                 /* this is correct for leafs */
+       xpc = (u1 *) _gregs[PT_NIP];
 
        /* get exception-throwing instruction */
 
@@ -162,17 +190,25 @@ void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
        /* for now we only handle ArrayIndexOutOfBoundsException */
 
        type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
-       val  = _mc->gregs[s1];
+       val  = _gregs[s1];
+
+       /* create stackframeinfo */
+
+       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
 
-       /* generate appropriate exception */
+       /* Handle the type. */
 
-       o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
+       p = signal_handle(xpc, type, val);
+
+       /* remove stackframeinfo */
+
+       stacktrace_remove_stackframeinfo(&sfi);
 
        /* set registers */
 
-       _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
-       _mc->gregs[REG_ITMP2_XPC]  = (ptrint) xpc;
-       _mc->gregs[PT_NIP]         = (ptrint) asm_handle_exception;
+       _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
+       _gregs[REG_ITMP2_XPC]  = (intptr_t) xpc;
+       _gregs[PT_NIP]         = (intptr_t) asm_handle_exception;
 }
 
 
@@ -185,36 +221,60 @@ void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
 #if defined(ENABLE_THREADS)
 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
 {
-       threadobject *tobj;
-       ucontext_t   *_uc;
-       mcontext_t   *_mc;
-       u1           *pc;
+       threadobject  *tobj;
+       ucontext_t    *_uc;
+       mcontext_t    *_mc;
+       unsigned long *_gregs;
+       u1            *pc;
 
        tobj = THREADOBJECT;
 
        _uc = (ucontext_t *) _p;
-       _mc = _uc->uc_mcontext.uc_regs;
 
-       pc = (u1 *) _mc->gregs[PT_NIP];
+#if defined(__UCLIBC__)
+       _mc    = &(_uc->uc_mcontext);
+       _gregs = _mc->regs->gpr;
+#else
+       _mc    = _uc->uc_mcontext.uc_regs;
+       _gregs = _mc->gregs;
+#endif
+
+       pc = (u1 *) _gregs[PT_NIP];
 
        tobj->pc = pc;
 }
+#endif
 
 
-void thread_restartcriticalsection(ucontext_t *_uc)
-{
-       mcontext_t *_mc;
-       u1         *pc;
-       void       *critical;
+/* md_critical_section_restart *************************************************
 
-       _mc = _uc->uc_mcontext.uc_regs;
+   Search the critical sections tree for a matching section and set
+   the PC to the restart point, if necessary.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS)
+void md_critical_section_restart(ucontext_t *_uc)
+{
+       mcontext_t    *_mc;
+       unsigned long *_gregs;
+       u1            *pc;
+       u1            *npc;
+
+#if defined(__UCLIBC__)
+       _mc    = &(_uc->uc_mcontext);
+       _gregs = _mc->regs->gpr;
+#else
+       _mc    = _uc->uc_mcontext.uc_regs;
+       _gregs = _mc->gregs;
+#endif
 
-       pc = (u1 *) _mc->gregs[PT_NIP];
+       pc = (u1 *) _gregs[PT_NIP];
 
-       critical = critical_find_restart_point(pc);
+       npc = critical_find_restart_point(pc);
 
-       if (critical)
-               _mc->gregs[PT_NIP] = (ptrint) critical;
+       if (npc != NULL)
+               _gregs[PT_NIP] = (ptrint) npc;
 }
 #endif