/* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux functions
- 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
+ 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/types.h"
#include "vm/jit/alpha/codegen.h"
+#include "vm/jit/alpha/md.h"
#include "vm/jit/alpha/md-abi.h"
-#if defined(ENABLE_THREADS)
-# include "threads/native/threads.h"
-#endif
-
-#include "vm/signallocal.h"
+#include "threads/thread.hpp"
-#include "vm/jit/asmpart.h"
-#include "vm/jit/stacktrace.h"
+#include "vm/signallocal.hpp"
+#include "vm/jit/executionstate.h"
+#include "vm/jit/trap.hpp"
-/* 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)
{
- stackframeinfo sfi;
- 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;
+ ucontext_t* _uc = (ucontext_t *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
- /* get exception-throwing instruction */
+ void* xpc = (void*) _mc->sc_pc;
- mcode = *((u4 *) xpc);
-
- d = M_MEM_GET_A(mcode);
- s1 = M_MEM_GET_B(mcode);
- disp = M_MEM_GET_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;
- }
- 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;
- }
-
- /* create stackframeinfo */
-
- stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
-
- /* Handle the type. */
+ // Handle the trap.
+ trap_handle(TRAP_SIGSEGV, xpc, _p);
+}
- p = signal_handle(xpc, type, val);
- /* remove stackframeinfo */
+/**
+ * Illegal Instruction signal handler for hardware exception checks.
+ */
+void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
+{
+ ucontext_t* _uc = (ucontext_t*) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
- stacktrace_remove_stackframeinfo(&sfi);
+ void* xpc = (void*) _mc->sc_pc;
- /* set registers */
+ // The PC points to the instruction after the illegal instruction.
+ xpc = (void*) (((uintptr_t) xpc) - 4);
- if (p != NULL) {
- _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
- _mc->sc_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
- _mc->sc_pc = (intptr_t) asm_handle_exception;
- }
+ // Handle the trap.
+ trap_handle(TRAP_SIGILL, xpc, _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;
- s4 i;
+ int i;
_uc = (ucontext_t *) context;
_mc = &_uc->uc_mcontext;
es->pc = (u1 *) _mc->sc_pc;
es->sp = (u1 *) _mc->sc_regs[REG_SP];
es->pv = (u1 *) _mc->sc_regs[REG_PV];
+ es->ra = (u1 *) _mc->sc_regs[REG_RA];
/* read integer registers */
for (i = 0; i < INT_REG_CNT; i++)
es->intregs[i] = _mc->sc_regs[i];
/* read float registers */
- for (i = 0; i < FLT_REG_CNT; i++)
- es->fltregs[i] = _mc->sc_fpregs[i];
+ /* Do not use the assignment operator '=', as the type of
+ * the _mc->sc_fpregs[i] can cause invalid conversions. */
+
+ assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
+ os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
}
-#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;
- s4 i;
+ int i;
_uc = (ucontext_t *) context;
_mc = &_uc->uc_mcontext;
_mc->sc_regs[i] = es->intregs[i];
/* write float registers */
- for (i = 0; i < FLT_REG_CNT; i++)
- _mc->sc_fpregs[i] = es->fltregs[i];
+ /* Do not use the assignment operator '=', as the type of
+ * the _mc->sc_fpregs[i] can cause invalid conversions. */
+
+ assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
+ os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
/* write special registers */
- _mc->sc_pc = es->pc;
+ _mc->sc_pc = (ptrint) es->pc;
_mc->sc_regs[REG_SP] = (ptrint) es->sp;
_mc->sc_regs[REG_PV] = (ptrint) es->pv;
+ _mc->sc_regs[REG_RA] = (ptrint) es->ra;
}
-#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;
-
- pc = (u1 *) _mc->sc_pc;
-
- npc = critical_find_restart_point(pc);
-
- if (npc != NULL)
- _mc->sc_pc = (ptrint) npc;
-}
-#endif
/*