Merged with tip.
[cacao.git] / src / vm / jit / x86_64 / linux / md-os.c
index a814540e73701878e9283f7235a21d92652ae512..fa5d6755b0f21cc78c42b06abf231ea12a2ff439 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/jit/x86_64/linux/md-os.c - machine dependent x86_64 Linux functions
 
-   Copyright (C) 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) 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #include "vm/types.h"
 
 #include "vm/jit/x86_64/codegen.h"
+#include "vm/jit/x86_64/md.h"
 
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
+#include "threads/thread.h"
 
-#include "vm/exceptions.h"
+#include "vm/builtin.h"
 #include "vm/signallocal.h"
 
 #include "vm/jit/asmpart.h"
+#include "vm/jit/executionstate.h"
+#include "vm/jit/trap.h"
 #include "vm/jit/stacktrace.h"
 
 
@@ -59,6 +58,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 {
        ucontext_t     *_uc;
        mcontext_t     *_mc;
+       void           *pv;
        u1             *sp;
        u1             *ra;
        u1             *xpc;
@@ -70,7 +70,7 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        int             type;
        intptr_t        val;
        void           *p;
-       java_handle_t  *o;
+       java_object_t  *o;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
@@ -78,9 +78,10 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
           different to the ones in <ucontext.h>. */
 
+       pv  = NULL;                 /* is resolved during stackframeinfo creation */
        sp  = (u1 *) _mc->gregs[REG_RSP];
        xpc = (u1 *) _mc->gregs[REG_RIP];
-       ra  = xpc;                          /* return address is equal to xpc     */
+       ra  = xpc;                              /* return address is equal to XPC */
 
 #if 0
        /* check for StackOverflowException */
@@ -151,40 +152,47 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
                val = _mc->gregs[d];
 
-               if (type == EXCEPTION_HARDWARE_COMPILER) {
+               if (type == TRAP_COMPILER) {
+                       /* The PV from the compiler stub is equal to the XPC. */
+
+                       pv = xpc;
+
                        /* We use a framesize of zero here because the call pushed
                           the return addres onto the stack. */
 
                        ra = md_stacktrace_get_returnaddress(sp, 0);
 
-                       /* And remove the RA from the stack. */
+                       /* Skip the RA on the stack. */
 
                        sp = sp + 1 * SIZEOF_VOID_P;
+
+                       /* The XPC is the RA minus 1, because the RA points to the
+                          instruction after the call. */
+
+                       xpc = ra - 3;
                }
        }
        else {
                /* this was a normal NPE */
 
-               type = EXCEPTION_HARDWARE_NULLPOINTER;
+               type = TRAP_NullPointerException;
                val  = 0;
        }
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, NULL, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* Set registers. */
 
-       if (type == EXCEPTION_HARDWARE_COMPILER) {
+       if (type == TRAP_COMPILER) {
                if (p == NULL) {
-                       o = exceptions_get_and_clear_exception();
-
-                       ra = ra - 3;                     /* XPC is before the actual call */
+                       o = builtin_retrieve_exception();
 
                        _mc->gregs[REG_RSP] = (uintptr_t) sp;    /* Remove RA from stack. */
 
                        _mc->gregs[REG_RAX] = (uintptr_t) o;
-                       _mc->gregs[REG_R10] = (uintptr_t) ra;            /* REG_ITMP2_XPC */
+                       _mc->gregs[REG_R10] = (uintptr_t) xpc;           /* REG_ITMP2_XPC */
                        _mc->gregs[REG_RIP] = (uintptr_t) asm_handle_exception;
                }
                else {
@@ -229,14 +237,14 @@ void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
        xpc = (u1 *) _mc->gregs[REG_RIP];
        ra  = xpc;                          /* return address is equal to xpc     */
 
-       /* this is an ArithmeticException */
+       /* This is an ArithmeticException. */
 
-       type = EXCEPTION_HARDWARE_ARITHMETIC;
+       type = TRAP_ArithmeticException;
        val  = 0;
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* set registers */
 
@@ -277,12 +285,12 @@ void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
 
        /* This is a patcher. */
 
-       type = EXCEPTION_HARDWARE_PATCHER;
+       type = TRAP_PATCHER;
        val  = 0;
 
-       /* Handle the type. */
+       /* Handle the trap. */
 
-       p = signal_handle(type, val, pv, sp, ra, xpc, _p);
+       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
 
        /* set registers */
 
@@ -353,14 +361,13 @@ 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;
@@ -371,7 +378,7 @@ void md_replace_executionstate_read(executionstate_t *es, void *context)
        _mc = &_uc->uc_mcontext;
 
        /* read special registers */
-       es->pc = (u1 *) _mc->gregs[REG_RSP];
+       es->pc = (u1 *) _mc->gregs[REG_RIP];
        es->sp = (u1 *) _mc->gregs[REG_RSP];
        es->pv = NULL;
 
@@ -423,17 +430,15 @@ void md_replace_executionstate_read(executionstate_t *es, void *context)
        for (i = 0; i < FLT_REG_CNT; i++)
                es->fltregs[i] = 0xdeadbeefdeadbeefL;
 }
-#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;
@@ -491,36 +496,6 @@ void md_replace_executionstate_write(executionstate_t *es, void *context)
        _mc->gregs[REG_RIP] = (ptrint) es->pc;
        _mc->gregs[REG_RSP] = (ptrint) es->sp;
 }
-#endif
-
-
-/* md_critical_section_restart *************************************************
-
-   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;
-       u1         *pc;
-       u1         *npc;
-
-       _mc = &_uc->uc_mcontext;
-
-       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
-          different to the ones in <ucontext.h>. */
-
-       pc = (u1 *) _mc->gregs[REG_RIP];
-
-       npc = critical_find_restart_point(pc);
-
-       if (npc != NULL)
-               _mc->gregs[REG_RIP] = (ptrint) npc;
-}
-#endif
 
 
 /*