* Removed all Id tags.
[cacao.git] / src / vm / jit / x86_64 / md.c
index 958bd78a964d176b4686a77a589fb58f9661c378..02a369cff7e7ee065738884fba23de94a4c0ac16 100644 (file)
@@ -1,6 +1,6 @@
-/* src/vm/jit/x86_64/md.c - machine dependent x86_64 Linux functions
+/* src/vm/jit/x86_64/md.c - machine dependent x86_64 functions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   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
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Christian Thalinger
-
-   Changes: Edwin Steiner
-
-   $Id: md.c 6265 2007-01-02 20:40:57Z edwin $
-
 */
 
 
-#define _GNU_SOURCE
-
 #include "config.h"
 
 #include <assert.h>
 #include <stdlib.h>
-#include <ucontext.h>
 
 #include "vm/jit/x86_64/md-abi.h"
 
 # include "threads/native/threads.h"
 #endif
 
-#include "vm/exceptions.h"
-#include "vm/signallocal.h"
 #include "vm/jit/asmpart.h"
+#include "vm/jit/codegen-common.h"
 #include "vm/jit/stacktrace.h"
 
+#if defined(ENABLE_REPLACEMENT)
+# include "vm/exceptions.h"
+#endif
+
 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
-#include "vm/options.h" /* XXX debug */
+#include "vmcore/options.h" /* XXX debug */
 #include "vm/jit/disass.h" /* XXX debug */
 #endif
 
@@ -70,151 +62,6 @@ void md_init(void)
 }
 
 
-/* md_signal_handler_sigsegv ***************************************************
-
-   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;
-       u1         *sp;
-       u1         *ra;
-       u1         *xpc;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
-          different to the ones in <ucontext.h>. */
-
-       sp  = (u1 *) _mc->gregs[REG_RSP];
-       xpc = (u1 *) _mc->gregs[REG_RIP];
-       ra  = xpc;                          /* return address is equal to xpc     */
-
-#if 0
-       /* check for StackOverflowException */
-
-       threads_check_stackoverflow(sp);
-#endif
-
-       _mc->gregs[REG_RAX] =
-               (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
-
-       _mc->gregs[REG_R10] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
-       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
-}
-
-
-/* md_signal_handler_sigfpe ****************************************************
-
-   ArithmeticException signal handler for hardware divide by zero
-   check.
-
-*******************************************************************************/
-
-void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
-{
-       ucontext_t  *_uc;
-       mcontext_t  *_mc;
-       u1          *sp;
-       u1          *ra;
-       u1          *xpc;
-
-       _uc = (ucontext_t *) _p;
-       _mc = &_uc->uc_mcontext;
-
-       /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
-          different to the ones in <ucontext.h>. */
-
-       sp  = (u1 *) _mc->gregs[REG_RSP];
-       xpc = (u1 *) _mc->gregs[REG_RIP];
-       ra  = xpc;                          /* return address is equal to xpc     */
-
-       _mc->gregs[REG_RAX] =
-               (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
-
-       _mc->gregs[REG_R10] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
-       _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
-}
-
-
-/* md_signal_handler_sigusr2 ***************************************************
-
-   Signal handler for profiling sampling.
-
-*******************************************************************************/
-
-#if defined(ENABLE_THREADS)
-void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
-{
-       threadobject *t;
-       ucontext_t   *_uc;
-       mcontext_t   *_mc;
-       u1           *pc;
-
-       t = THREADOBJECT;
-
-       _uc = (ucontext_t *) _p;
-       _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];
-
-       t->pc = pc;
-}
-#endif
-
-
-#if defined(ENABLE_THREADS)
-void thread_restartcriticalsection(ucontext_t *_uc)
-{
-       mcontext_t *_mc;
-       void       *pc;
-
-       _mc = &_uc->uc_mcontext;
-
-       pc = critical_find_restart_point((void *) _mc->gregs[REG_RIP]);
-
-       if (pc != NULL)
-               _mc->gregs[REG_RIP] = (ptrint) pc;
-}
-#endif
-
-
-/* md_codegen_patch_branch *****************************************************
-
-   Back-patches a branch instruction.
-
-*******************************************************************************/
-
-void md_codegen_patch_branch(codegendata *cd, s4 branchmpc, s4 targetmpc)
-{
-       s4 *mcodeptr;
-       s4  disp;                           /* branch displacement                */
-
-       /* calculate the patch position */
-
-       mcodeptr = (s4 *) (cd->mcodebase + branchmpc);
-
-       /* Calculate the branch displacement. */
-
-       disp = targetmpc - branchmpc;
-
-       /* I don't think we have to check for branch-displacement
-          overflow.  +/-2GB should be enough. */
-
-       /* patch the branch instruction before the mcodeptr */
-
-       mcodeptr[-1] = disp;
-}
-
-
 /* md_stacktrace_get_returnaddress *********************************************
 
    Returns the return address of the current stackframe, specified by
@@ -308,7 +155,11 @@ u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
        else {
                /* catch any problems */
 
-               assert(0);
+               vm_abort("md_get_method_patch_address: unknown instruction %x", mcode);
+
+               /* keep compiler happy */
+
+               pa = NULL;
        }
 
        return pa;
@@ -381,7 +232,6 @@ void md_dcacheflush(u1 *addr, s4 nbytes)
 #if defined(ENABLE_REPLACEMENT)
 void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp, u1 *savedmcode)
 {
-       s4 disp;
        u8 mcode;
 
        /* XXX this is probably unsafe! */
@@ -402,11 +252,8 @@ void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp, u1 *save
                savedmcode[4] = rp->pc[4];
 
                /* build the machine code for the patch */
-               disp = (code->replacementstubs - rp->pc)
-                          + index * REPLACEMENT_STUB_SIZE
-                          - 5;
-
-               mcode = 0xe9 | ((u8) disp << 8);
+               assert(0); /* XXX build trap instruction below */
+               mcode = 0;
 
                /* write spinning instruction */
                *(u2*)(rp->pc) = 0xebfe;