Merged?
[cacao.git] / src / vm / jit / powerpc / linux / md-os.c
index ce41acbcf04a684ef2e14aebbc5c2f2e202033b9..6628953d6290968ab9e55ea16747087a3eda6b60 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: md-os.c 8283 2007-08-09 15:10:05Z twisti $
-
 */
 
 
@@ -62,7 +60,6 @@
 
 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
-       stackframeinfo  sfi;
        ucontext_t     *_uc;
        mcontext_t     *_mc;
        unsigned long  *_gregs;
@@ -110,6 +107,13 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                /* we use the exception type as load displacement */
 
                type = disp;
+
+               if (type == EXCEPTION_HARDWARE_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
@@ -122,24 +126,44 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
                        vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
        }
 
-       /* create stackframeinfo */
+       /* Handle the type. */
 
-       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
+       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* Handle the type. */
+       /* Set registers. */
+
+       switch (type) {
+       case EXCEPTION_HARDWARE_COMPILER:
+               if (p != NULL) {
+                       _gregs[REG_PV] = (uintptr_t) p;
+                       _gregs[PT_NIP] = (uintptr_t) p;
+                       break;
+               }
 
-       p = signal_handle(xpc, type, val);
+               /* Get and set the PV from the parent Java method. */
 
-       /* remove stackframeinfo */
+               pv = md_codegen_get_pv_from_pc(ra);
 
-       stacktrace_remove_stackframeinfo(&sfi);
+               _gregs[REG_PV] = (uintptr_t) pv;
 
-       /* set registers (only if exception object ready) */
+               /* Get the exception object. */
 
-       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;
+               p = exceptions_get_and_clear_exception();
+
+               assert(p != NULL);
+
+               /* fall-through */
+
+       case EXCEPTION_HARDWARE_PATCHER:
+               if (p == NULL)
+                       break;
+
+               /* fall-through */
+               
+       default:
+               _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
+               _gregs[REG_ITMP2_XPC]  = (uintptr_t) xpc;
+               _gregs[PT_NIP]         = (uintptr_t) asm_handle_exception;
        }
 }
 
@@ -152,7 +176,6 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
 {
-       stackframeinfo  sfi;
        ucontext_t     *_uc;
        mcontext_t     *_mc;
        unsigned long  *_gregs;
@@ -192,17 +215,9 @@ void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
        type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
        val  = _gregs[s1];
 
-       /* create stackframeinfo */
-
-       stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
-
        /* Handle the type. */
 
-       p = signal_handle(xpc, type, val);
-
-       /* remove stackframeinfo */
-
-       stacktrace_remove_stackframeinfo(&sfi);
+       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* set registers */
 
@@ -212,6 +227,43 @@ void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
 }
 
 
+/* md_signal_handler_sigusr1 ***************************************************
+
+   Signal handler for suspending threads.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
+void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
+{
+       ucontext_t    *_uc;
+       mcontext_t    *_mc;
+       unsigned long *_gregs;
+       u1            *pc;
+       u1            *sp;
+
+       _uc = (ucontext_t *) _p;
+
+#if defined(__UCLIBC__)
+       _mc    = &(_uc->uc_mcontext);
+       _gregs = _mc->regs->gpr;
+#else
+       _mc    = _uc->uc_mcontext.uc_regs;
+       _gregs = _mc->gregs;
+#endif
+
+       /* get the PC and SP for this thread */
+
+       pc = (u1 *) _gregs[PT_NIP];
+       sp = (u1 *) _gregs[REG_SP];
+
+       /* now suspend the current thread */
+
+       threads_suspend_ack(pc, sp);
+}
+#endif
+
+
 /* md_signal_handler_sigusr2 ***************************************************
 
    Signal handler for profiling sampling.