/* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
- Copyright (C) 1996-2005 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, 2009
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Andreas Krall
- Reinhard Grafl
-
- Changes: Christian Thalinger
-
- $Id: md-os.c 3442 2005-10-18 12:38:16Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
+#include "config.h"
+
#include <assert.h>
+#include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
#include <signal.h>
+#include <stdint.h>
#include <ucontext.h>
-#include "config.h"
#include "vm/types.h"
+#include "vm/jit/mips/codegen.h"
+#include "vm/jit/mips/md.h"
#include "vm/jit/mips/md-abi.h"
-#include "mm/boehm.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
-#include "vm/jit/asmpart.h"
-#include "vm/jit/stacktrace.h"
+#include "mm/gc.hpp"
+#include "mm/memory.hpp"
+
+#include "vm/signallocal.hpp"
+
+#include "vm/jit/executionstate.h"
+#include "vm/jit/trap.hpp"
/* md_init *********************************************************************
void md_init(void)
{
- /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
- /* dummy allocation here to ensure that the GC is initialized. */
+ /* The Boehm GC initialization blocks the SIGSEGV signal. So we do
+ a dummy allocation here to ensure that the GC is
+ initialized. */
- heap_allocate(1, 0, NULL);
+#if defined(ENABLE_GC_BOEHM)
+ (void) GCNEW(int);
+#endif
#if 0
/* Turn off flush-to-zero */
}
-/* signal_handler_sigsegv ******************************************************
+/**
+ * NullPointerException signal handler for hardware null pointer check.
+ */
+void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
+{
+ int disp = 0;
+ int cause;
+ ucontext_t* _uc = (struct ucontext *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
+ void *xpc;
+
+#if !defined(__UCLIBC__)
+# if ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
+ /* NOTE: We only need this for pre glibc-2.5. */
+
+ /* get the cause of this exception */
+
+ cause = _mc->cause;
- NullPointerException signal handler for hardware null pointer check.
+ /* check the cause to find the faulting instruction */
+
+ /* TODO: use defines for that stuff */
+
+ switch (cause & 0x0000003c) {
+ case 0x00000008:
+ /* TLBL: XPC is ok */
+ break;
+
+ case 0x00000010:
+ /* AdEL: XPC is of the following instruction */
+ disp -= 4;
+ break;
+ }
+ xpc = (void*) (_mc->pc + disp);
+# else
+ xpc = (void*) _mc->pc;
+# endif
+#else
+ xpc = (void*) _gregs[CTX_EPC];
+#endif
+
+ // 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 = (struct ucontext *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
+
+#if !defined(__UCLIBC__)
+ void* xpc = (void*) _mc->pc;
+#else
+ void* xpc = (void*) _gregs[CTX_EPC];
+#endif
+
+ // Handle the trap.
+ trap_handle(TRAP_SIGILL, xpc, _p);
+}
+
+
+/* md_signal_handler_sigusr2 ***************************************************
+
+ DOCUMENT ME
*******************************************************************************/
-void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
+void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
+{
+}
+
+
+/**
+ * Read the given context into an executionstate.
+ *
+ * @param es execution state
+ * @param context machine context
+ */
+void md_executionstate_read(executionstate_t* es, void* context)
{
- ucontext_t *_uc;
- mcontext_t *_mc;
- u4 instr;
- ptrint addr;
- u1 *pv;
- u1 *sp;
- functionptr ra;
- functionptr xpc;
-
- _uc = (struct ucontext *) _p;
+ ucontext_t* _uc;
+ mcontext_t* _mc;
+ greg_t* _gregs;
+ int i;
+
+ _uc = (ucontext_t*) context;
_mc = &_uc->uc_mcontext;
- /* in ucontext.h the registers are defined as long long, even for
- MIPS32, so we cast them */
-
- instr = *((u4 *) ((ptrint) _mc->pc));
- addr = _mc->gregs[(instr >> 21) & 0x1f];
+#if defined(__UCLIBC__)
+ _gregs = _mc->gpregs;
+#else
+ _gregs = _mc->gregs;
+#endif
- if (addr == 0) {
- pv = (u1 *) (ptrint) _mc->gregs[REG_PV];
- sp = (u1 *) (ptrint) _mc->gregs[REG_SP];
- ra = (functionptr) (ptrint) _mc->gregs[REG_RA]; /* this is correct for leafs*/
- xpc = (functionptr) (ptrint) _mc->pc;
+ /* Read special registers. */
- _mc->gregs[REG_ITMP1_XPTR] =
- (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
+ /* In glibc's ucontext.h the registers are defined as long long,
+ even for MIPS32, so we cast them. This is not the case for
+ uClibc. */
- _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
- _mc->pc = (ptrint) asm_handle_exception;
+#if defined(__UCLIBC__)
+ es->pc = _gregs[CTX_EPC];
+#else
+ es->pc = (void*) (uintptr_t) _mc->pc;
+#endif
- } else {
- addr += (long) ((instr << 16) >> 16);
+ es->sp = (void*) (uintptr_t) _gregs[REG_SP];
+ es->pv = (void*) (uintptr_t) _gregs[REG_PV];
+ es->ra = (void*) (uintptr_t) _gregs[REG_RA];
- throw_cacao_exception_exit(string_java_lang_InternalError,
- "faulting address: 0x%lx at 0x%lx\n",
- addr, _mc->pc);
- }
+ /* Read integer registers. */
+
+ for (i = 0; i < INT_REG_CNT; i++)
+ es->intregs[i] = _gregs[i];
+
+ /* Read float registers. */
+
+ /* Do not use the assignment operator '=', as the type of the
+ _mc->fpregs[i] can cause invalid conversions. */
+
+ assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
+ os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
}
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void thread_restartcriticalsection(ucontext_t *_uc)
+/**
+ * Write the given executionstate back to the context.
+ *
+ * @param es execution state
+ * @param context machine context
+ */
+void md_executionstate_write(executionstate_t* es, void* context)
{
- mcontext_t *_mc;
- void *critical;
+ ucontext_t* _uc;
+ mcontext_t* _mc;
+ greg_t* _gregs;
+ int i;
+ _uc = (ucontext_t *) context;
_mc = &_uc->uc_mcontext;
- critical = thread_checkcritical((void *) (ptrint) _mc->pc);
+#if defined(__UCLIBC__)
+ _gregs = _mc->gpregs;
+#else
+ _gregs = _mc->gregs;
+#endif
- if (critical)
- _mc->pc = (ptrint) critical;
-}
+ /* Write integer registers. */
+
+ for (i = 0; i < INT_REG_CNT; i++)
+ _gregs[i] = es->intregs[i];
+
+ /* Write float registers. */
+
+ /* Do not use the assignment operator '=', as the type of the
+ _mc->fpregs[i] can cause invalid conversions. */
+
+ assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
+ os_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
+
+ /* Write special registers. */
+
+#if defined(__UCLIBC__)
+ _gregs[CTX_EPC] = es->pc;
+#else
+ _mc->pc = (uintptr_t) es->pc;
#endif
+ _gregs[REG_SP] = (uintptr_t) es->sp;
+ _gregs[REG_PV] = (uintptr_t) es->pv;
+ _gregs[REG_RA] = (uintptr_t) es->ra;
+}
+
/*
* These are local overrides for various environment variables in Emacs.
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/