* src/vm/jit/trap.c (trap_handle): Update executionstates PC register in case
[cacao.git] / src / vm / jit / alpha / linux / md-os.c
index afe391d11b2b86b0abc946d0a0ff509ff7ff80e1..8e127a9fab4e3bae10487216f640ecdda617c28a 100644 (file)
@@ -2,6 +2,7 @@
 
    Copyright (C) 1996-2005, 2006, 2007, 2008
    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+   Copyright (C) 2008 Theobroma Systems Ltd.
 
    This file is part of CACAO.
 
 #include "vm/jit/alpha/md.h"
 #include "vm/jit/alpha/md-abi.h"
 
-#include "threads/thread.h"
+#include "threads/thread.hpp"
 
-#include "vm/builtin.h"
+#include "vm/jit/builtin.hpp"
 #include "vm/signallocal.h"
+#include "vm/os.hpp"
 
 #include "vm/jit/asmpart.h"
+#include "vm/jit/disass.h"
 #include "vm/jit/executionstate.h"
-#include "vm/jit/stacktrace.h"
 #include "vm/jit/trap.h"
 
-#include "vmcore/system.h"
-
 
 /* md_signal_handler_sigsegv ***************************************************
 
@@ -70,7 +70,6 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
        intptr_t        val;
        intptr_t        addr;
        int             type;
-       void           *p;
 
        _uc = (ucontext_t *) _p;
        _mc = &_uc->uc_mcontext;
@@ -114,43 +113,50 @@ void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
 
        /* Handle the trap. */
 
-       p = trap_handle(type, val, pv, sp, ra, xpc, _p);
-
-       /* Set registers. */
+       trap_handle(type, val, pv, sp, ra, xpc, _p);
+}
 
-       switch (type) {
-       case TRAP_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. */
+/* md_signal_handler_sigill ****************************************************
 
-               pv = md_codegen_get_pv_from_pc(ra);
+   Illegal Instruction signal handler for hardware exception checks.
 
-               _mc->sc_regs[REG_PV] = (uintptr_t) pv;
+*******************************************************************************/
 
-               /* Get the exception object. */
+void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
+{
+       ucontext_t* _uc = (ucontext_t*) _p;
+       mcontext_t* _mc = &_uc->uc_mcontext;
 
-               p = builtin_retrieve_exception();
+       void* pv  = (u1 *) _mc->sc_regs[REG_PV];
+       void* sp  = (u1 *) _mc->sc_regs[REG_SP];
+       void* ra  = (u1 *) _mc->sc_regs[REG_RA]; // RA is correct for leaf methods.
+       void* xpc = (u1 *) _mc->sc_pc;
 
-               assert(p != NULL);
+       // The PC points to the instruction after the illegal instruction.
+       xpc = (void*) (((uintptr_t) xpc) - 4);
 
-               /* fall-through */
+       // Get the exception-throwing instruction.
+       uint32_t mcode = *((uint32_t*) xpc);
 
-       case TRAP_PATCHER:
-               if (p == NULL)
-                       break;
+       int opcode = M_OP3_GET_Opcode(mcode);
 
-               /* 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;
+       // Check for undefined instruction we use.
+       // TODO Check the whole instruction.
+       if (opcode != 0x4) {
+               log_println("md_signal_handler_sigill: Unknown illegal instruction %x at %p", mcode, xpc);
+#if defined(ENABLE_DISASSEMBLER)
+               (void) disassinstr(xpc);
+#endif
+               vm_abort("Aborting...");
        }
+
+       // This signal is always a patcher.
+       int      type = TRAP_PATCHER;
+       intptr_t val  = 0;
+
+       // Handle the trap.
+       trap_handle(type, val, pv, sp, ra, xpc, _p);
 }
 
 
@@ -237,7 +243,7 @@ void md_executionstate_read(executionstate_t *es, void *context)
         * 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));
+       os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
 }
 
 
@@ -265,7 +271,7 @@ void md_executionstate_write(executionstate_t *es, void *context)
         * 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));
+       os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
 
        /* write special registers */
        _mc->sc_pc           = (ptrint) es->pc;
@@ -275,32 +281,6 @@ void md_executionstate_write(executionstate_t *es, void *context)
 }
 
 
-/* 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;
-
-       pc = (u1 *) _mc->sc_pc;
-
-       npc = critical_find_restart_point(pc);
-
-       if (npc != NULL)
-               _mc->sc_pc = (ptrint) npc;
-}
-#endif
-
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where