* Merged executionstate branch.
[cacao.git] / src / vm / jit / alpha / linux / md-os.c
index c356c5957708345fbfc65e2eedcc9a3fafa857a9..08a85f07e6e33425b3983a0792dc28df980f44e0 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux 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, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #include "vm/types.h"
 
 #include "vm/jit/alpha/codegen.h"
+#include "vm/jit/alpha/md.h"
 #include "vm/jit/alpha/md-abi.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
+#include "threads/thread.h"
 
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
 #include "vm/signallocal.h"
 
 #include "vm/jit/asmpart.h"
+#include "vm/jit/executionstate.h"
 #include "vm/jit/stacktrace.h"
 
+#include "vmcore/system.h"
+
 
 /* md_signal_handler_sigsegv ***************************************************
 
@@ -94,6 +96,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 1, 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
@@ -107,12 +116,40 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
        p = signal_handle(type, val, pv, sp, ra, xpc, _p);
 
-       /* set registers */
+       /* Set registers. */
+
+       switch (type) {
+       case EXCEPTION_HARDWARE_COMPILER:
+               if (p != NULL) {
+                       _mc->sc_regs[REG_PV] = (uintptr_t) p;
+                       _mc->sc_pc           = (uintptr_t) p;
+                       break;
+               }
+
+               /* Get and set the PV from the parent Java method. */
+
+               pv = md_codegen_get_pv_from_pc(ra);
+
+               _mc->sc_regs[REG_PV] = (uintptr_t) pv;
 
-       if (p != NULL) {
-               _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
-               _mc->sc_regs[REG_ITMP2_XPC]  = (intptr_t) xpc;
-               _mc->sc_pc                   = (intptr_t) asm_handle_exception;
+               /* Get the exception object. */
+
+               p = builtin_retrieve_exception();
+
+               assert(p != NULL);
+
+               /* fall-through */
+
+       case EXCEPTION_HARDWARE_PATCHER:
+               if (p == NULL)
+                       break;
+
+               /* fall-through */
+               
+       default:
+               _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
+               _mc->sc_regs[REG_ITMP2_XPC]  = (uintptr_t) xpc;
+               _mc->sc_pc                   = (uintptr_t) asm_handle_exception;
        }
 }
 
@@ -170,18 +207,17 @@ void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
 #endif
 
 
-/* md_replace_executionstate_read **********************************************
+/* md_executionstate_read ******************************************************
 
-   Read the given context into an executionstate for Replacement.
+   Read the given context into an executionstate.
 
 *******************************************************************************/
 
-#if defined(ENABLE_REPLACEMENT)
-void md_replace_executionstate_read(executionstate_t *es, void *context)
+void md_executionstate_read(executionstate_t *es, void *context)
 {
        ucontext_t *_uc;
        mcontext_t *_mc;
-       s4          i;
+       int         i;
 
        _uc = (ucontext_t *) context;
        _mc = &_uc->uc_mcontext;
@@ -190,30 +226,32 @@ void md_replace_executionstate_read(executionstate_t *es, void *context)
        es->pc = (u1 *) _mc->sc_pc;
        es->sp = (u1 *) _mc->sc_regs[REG_SP];
        es->pv = (u1 *) _mc->sc_regs[REG_PV];
+       es->ra = (u1 *) _mc->sc_regs[REG_RA];
 
        /* read integer registers */
        for (i = 0; i < INT_REG_CNT; i++)
                es->intregs[i] = _mc->sc_regs[i];
 
        /* read float registers */
-       for (i = 0; i < FLT_REG_CNT; i++)
-               es->fltregs[i] = _mc->sc_fpregs[i];
+       /* Do not use the assignment operator '=', as the type of
+        * the _mc->sc_fpregs[i] can cause invalid conversions. */
+
+       assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
+       system_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
 }
-#endif
 
 
-/* md_replace_executionstate_write *********************************************
+/* md_executionstate_write *****************************************************
 
-   Write the given executionstate back to the context for Replacement.
+   Write the given executionstate back to the context.
 
 *******************************************************************************/
 
-#if defined(ENABLE_REPLACEMENT)
-void md_replace_executionstate_write(executionstate_t *es, void *context)
+void md_executionstate_write(executionstate_t *es, void *context)
 {
        ucontext_t *_uc;
        mcontext_t *_mc;
-       s4          i;
+       int         i;
 
        _uc = (ucontext_t *) context;
        _mc = &_uc->uc_mcontext;
@@ -223,15 +261,18 @@ void md_replace_executionstate_write(executionstate_t *es, void *context)
                _mc->sc_regs[i] = es->intregs[i];
 
        /* write float registers */
-       for (i = 0; i < FLT_REG_CNT; i++)
-               _mc->sc_fpregs[i] = es->fltregs[i];
+       /* Do not use the assignment operator '=', as the type of
+        * the _mc->sc_fpregs[i] can cause invalid conversions. */
+
+       assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
+       system_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
 
        /* write special registers */
        _mc->sc_pc           = (ptrint) es->pc;
        _mc->sc_regs[REG_SP] = (ptrint) es->sp;
        _mc->sc_regs[REG_PV] = (ptrint) es->pv;
+       _mc->sc_regs[REG_RA] = (ptrint) es->ra;
 }
-#endif
 
 
 /* md_critical_section_restart *************************************************