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 ***************************************************
intptr_t val;
intptr_t addr;
int type;
- void *p;
_uc = (ucontext_t *) _p;
_mc = &_uc->uc_mcontext;
/* 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);
}
* 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