-/* src/vm/jit/alpha/linux/md.c - machine dependent Alpha Linux functions
+/* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux functions
- Copyright (C) 1996-2005, 2006 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.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
-
- Changes:
-
- $Id: md-os.c 4908 2006-05-12 16:49:50Z edwin $
-
*/
#include "config.h"
#include <assert.h>
+#include <stdint.h>
#include <ucontext.h>
#include "vm/types.h"
+#include "vm/jit/alpha/codegen.h"
+#include "vm/jit/alpha/md.h"
#include "vm/jit/alpha/md-abi.h"
-#include "vm/exceptions.h"
-#include "vm/signallocal.h"
-#include "vm/stringlocal.h"
-#include "vm/jit/asmpart.h"
-#include "vm/jit/stacktrace.h"
+#include "threads/thread.hpp"
+
+#include "vm/signallocal.hpp"
+
+#include "vm/jit/executionstate.h"
+#include "vm/jit/trap.hpp"
+
+
+/**
+ * NullPointerException signal handler for hardware null pointer check.
+ */
+void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
+{
+ ucontext_t* _uc = (ucontext_t *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
+
+ void* xpc = (void*) _mc->sc_pc;
+
+ // Handle the trap.
+ trap_handle(TRAP_SIGSEGV, xpc, _p);
+}
+
+
+/**
+ * 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;
+
+ void* xpc = (void*) _mc->sc_pc;
+
+ // The PC points to the instruction after the illegal instruction.
+ xpc = (void*) (((uintptr_t) xpc) - 4);
+
+ // Handle the trap.
+ trap_handle(TRAP_SIGILL, xpc, _p);
+}
-/* md_signal_handler_sigsegv ***************************************************
+/* md_signal_handler_sigusr2 ***************************************************
- NullPointerException signal handler for hardware null pointer
- check.
+ Signal handler for profiling sampling.
*******************************************************************************/
-void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
+#if defined(ENABLE_THREADS)
+void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
{
- ucontext_t *_uc;
- mcontext_t *_mc;
- u4 instr;
- ptrint addr;
- u1 *pv;
- u1 *sp;
- u1 *ra;
- u1 *xpc;
+ threadobject *tobj;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ u1 *pc;
+
+ tobj = THREADOBJECT;
_uc = (ucontext_t *) _p;
_mc = &_uc->uc_mcontext;
- instr = *((s4 *) (_mc->sc_pc));
- addr = _mc->sc_regs[(instr >> 16) & 0x1f];
+ pc = (u1 *) _mc->sc_pc;
+
+ tobj->pc = pc;
+}
+#endif
- if (addr == 0) {
- 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;
- _mc->sc_regs[REG_ITMP1_XPTR] =
- (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
+/* md_executionstate_read ******************************************************
- _mc->sc_regs[REG_ITMP2_XPC] = (ptrint) xpc;
- _mc->sc_pc = (ptrint) asm_handle_exception;
+ Read the given context into an executionstate.
- } else {
- addr += (long) ((instr << 16) >> 16);
+*******************************************************************************/
+
+void md_executionstate_read(executionstate_t *es, void *context)
+{
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ int i;
+
+ _uc = (ucontext_t *) context;
+ _mc = &_uc->uc_mcontext;
- throw_cacao_exception_exit(string_java_lang_InternalError,
- "Segmentation fault: 0x%016lx at 0x%016lx\n",
- addr, _mc->sc_pc);
- }
+ /* read special registers */
+ 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 */
+ /* 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));
}
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void thread_restartcriticalsection(ucontext_t *_uc)
+/* md_executionstate_write *****************************************************
+
+ Write the given executionstate back to the context.
+
+*******************************************************************************/
+
+void md_executionstate_write(executionstate_t *es, void *context)
{
+ ucontext_t *_uc;
mcontext_t *_mc;
- void *critical;
+ int i;
+ _uc = (ucontext_t *) context;
_mc = &_uc->uc_mcontext;
- critical = critical_find_restart_point((void *) _mc->sc_pc);
+ /* write integer registers */
+ for (i = 0; i < INT_REG_CNT; i++)
+ _mc->sc_regs[i] = es->intregs[i];
+
+ /* write float registers */
+ /* Do not use the assignment operator '=', as the type of
+ * the _mc->sc_fpregs[i] can cause invalid conversions. */
- if (critical)
- _mc->sc_pc = (ptrint) critical;
+ 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 = (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
/*