Copyright (C) 1996-2005, 2006, 2007, 2008
CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
+ Copyright (C) 2008, 2009 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/exceptions.h"
-#include "vm/signallocal.h"
+#include "vm/signallocal.hpp"
-#include "vm/jit/asmpart.h"
#include "vm/jit/executionstate.h"
-#include "vm/jit/stacktrace.h"
+#include "vm/jit/trap.hpp"
-#include "vmcore/system.h"
-
-
-/* md_signal_handler_sigsegv ***************************************************
-
- NullPointerException signal handler for hardware null pointer
- check.
-
-*******************************************************************************/
+/**
+ * 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 *pv;
- u1 *sp;
- u1 *ra;
- u1 *xpc;
- u4 mcode;
- s4 d;
- s4 s1;
- s4 disp;
- intptr_t val;
- intptr_t addr;
- int type;
- void *p;
-
- _uc = (ucontext_t *) _p;
- _mc = &_uc->uc_mcontext;
-
- pv = (u1 *) _mc->sc_regs[REG_PV];
- sp = (u1 *) _mc->sc_regs[REG_SP];
- ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
- xpc = (u1 *) _mc->sc_pc;
-
- /* get exception-throwing instruction */
-
- mcode = *((u4 *) xpc);
-
- d = M_MEM_GET_Ra(mcode);
- s1 = M_MEM_GET_Rb(mcode);
- disp = M_MEM_GET_Memory_disp(mcode);
-
- val = _mc->sc_regs[d];
-
- /* check for special-load */
-
- if (s1 == REG_ZERO) {
- /* 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
- define is 0. */
-
- addr = _mc->sc_regs[s1];
- type = (int) addr;
- }
-
- /* Handle the type. */
-
- p = signal_handle(type, val, pv, sp, ra, xpc, _p);
-
- /* 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;
-
- /* Get the exception object. */
-
- p = builtin_retrieve_exception();
-
- assert(p != NULL);
+ ucontext_t* _uc = (ucontext_t *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
- /* fall-through */
+ void* xpc = (void*) _mc->sc_pc;
- 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;
- }
+ // Handle the trap.
+ trap_handle(TRAP_SIGSEGV, xpc, _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)
+/**
+ * Illegal Instruction signal handler for hardware exception checks.
+ */
+void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
{
- ucontext_t *_uc;
- mcontext_t *_mc;
- u1 *pc;
- u1 *sp;
+ ucontext_t* _uc = (ucontext_t*) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
- _uc = (ucontext_t *) _p;
- _mc = &_uc->uc_mcontext;
+ void* xpc = (void*) _mc->sc_pc;
- /* get the PC and SP for this thread */
- pc = (u1 *) _mc->sc_pc;
- sp = (u1 *) _mc->sc_regs[REG_SP];
+ // The PC points to the instruction after the illegal instruction.
+ xpc = (void*) (((uintptr_t) xpc) - 4);
- /* now suspend the current thread */
- threads_suspend_ack(pc, sp);
+ // Handle the trap.
+ trap_handle(TRAP_SIGILL, xpc, _p);
}
-#endif
/* md_signal_handler_sigusr2 ***************************************************
* 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));
}
* 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;
}
-/* 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