#include "vm/jit/mips/md.h"
#include "vm/jit/mips/md-abi.h"
-#include "mm/gc-common.h"
-#include "mm/memory.h"
+#include "mm/gc.hpp"
+#include "mm/memory.hpp"
-#include "vm/exceptions.h"
-#include "vm/signallocal.h"
+#include "vm/signallocal.hpp"
+#include "vm/os.hpp"
#include "vm/jit/asmpart.h"
#include "vm/jit/executionstate.h"
-#include "vm/jit/stacktrace.h"
-#include "vm/jit/trap.h"
+#include "vm/jit/trap.hpp"
/* md_init *********************************************************************
intptr_t val;
intptr_t addr;
int type;
- void *p;
_uc = (struct ucontext *) _p;
_mc = &_uc->uc_mcontext;
/* Handle the trap. */
- p = trap_handle(type, val, pv, sp, ra, xpc, _p);
+ trap_handle(type, val, pv, sp, ra, xpc, _p);
+}
+
- /* Set registers. */
+/**
+ * Signal handler for patcher calls.
+ */
+void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
+{
+ ucontext_t* _uc = (struct ucontext *) _p;
+ mcontext_t* _mc = &_uc->uc_mcontext;
+ greg_t* _gregs;
- switch (type) {
- case TRAP_COMPILER:
- if (p != NULL) {
- _gregs[REG_PV] = (uintptr_t) p;
#if defined(__UCLIBC__)
- _gregs[CTX_EPC] = (uintptr_t) p;
-#else
- _mc->pc = (uintptr_t) p;
+ _gregs = _mc->gpregs;
+#else
+ _gregs = _mc->gregs;
#endif
- break;
- }
-
- /* Get and set the PV from the parent Java method. */
- pv = md_codegen_get_pv_from_pc(ra);
-
- _gregs[REG_PV] = (uintptr_t) pv;
-
- /* Get the exception object. */
-
- p = builtin_retrieve_exception();
-
- assert(p != NULL);
-
- /* fall-through */
-
- case TRAP_PATCHER:
- if (p == NULL) {
- /* We set the PC again because the cause may have changed
- the XPC. */
+ // In glibc's ucontext.h the registers are defined as long long
+ // int, even for MIPS32, so we cast them. This is not the case
+ // for uClibc.
+ void* pv = (void*) (uintptr_t) _gregs[REG_PV];
+ void* sp = (void*) (uintptr_t) _gregs[REG_SP];
+ void* ra = (void*) (uintptr_t) _gregs[REG_RA]; // The RA is correct for leaf methods.
#if defined(__UCLIBC__)
- _gregs[CTX_EPC] = (uintptr_t) xpc;
+ void* xpc = (void*) (uintptr_t) _gregs[CTX_EPC];
#else
- _mc->pc = (uintptr_t) xpc;
+ void* xpc = (void*) (uintptr_t) _mc->pc;
#endif
- break;
- }
- /* fall-through */
-
- default:
- _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
- _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
+ // This signal is always a patcher.
+ int type = TRAP_PATCHER;
+ intptr_t val = 0;
+
+ // Handle the trap.
+ void* p = trap_handle(type, val, pv, sp, ra, xpc, _p);
+
+ // Set registers
+ if (p == NULL) {
+ // We set the PC again because the cause may have changed the
+ // XPC.
#if defined(__UCLIBC__)
- _gregs[CTX_EPC] = (uintptr_t) asm_handle_exception;
+ _gregs[CTX_EPC] = (uintptr_t) xpc;
#else
- _mc->pc = (uintptr_t) asm_handle_exception;
+ _mc->pc = (uintptr_t) xpc;
#endif
}
}
_mc->fpregs[i] can cause invalid conversions. */
assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
- system_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
+ os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
}
_mc->fpregs[i] can cause invalid conversions. */
assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
- system_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
+ os_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
/* Write special registers. */
}
-/* 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;
-
-#if defined(__UCLIBC__)
- pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
-#else
- pc = (u1 *) (ptrint) _mc->pc;
-#endif
-
- npc = critical_find_restart_point(pc);
-
- if (npc != NULL) {
-#if defined(__UCLIBC__)
- _mc->gpregs[CTX_EPC] = (ptrint) npc;
-#else
- _mc->pc = (ptrint) npc;
-#endif
- }
-}
-#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