Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: md-os.c 7311 2007-02-09 13:20:27Z twisti $
+ $Id: md-os.c 8283 2007-08-09 15:10:05Z twisti $
*/
#include "config.h"
#include <assert.h>
+#include <stdint.h>
#include <ucontext.h>
#include "vm/types.h"
+#include "vm/jit/powerpc64/codegen.h"
#include "vm/jit/powerpc64/linux/md-abi.h"
#if defined(ENABLE_THREADS)
/* md_signal_handler_sigsegv ***************************************************
-
- NullPointerException signal handler for hardware null pointer
- check.
+
+ Signal handler for hardware-exceptions.
*******************************************************************************/
void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
{
- ucontext_t *_uc;
- mcontext_t *_mc;
- u4 instr;
- s4 reg;
- ptrint addr;
- u1 *pv;
- u1 *sp;
- u1 *ra;
- u1 *xpc;
+ stackframeinfo sfi;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ u1 *pv;
+ u1 *sp;
+ u1 *ra;
+ u1 *xpc;
+ u4 mcode;
+ int s1;
+ int16_t disp;
+ int d;
+ int type;
+ intptr_t addr;
+ intptr_t val;
+ void *p;
_uc = (ucontext_t *) _p;
_mc = &(_uc->uc_mcontext);
-
- pv = (u1 *) _mc->gp_regs[REG_PV];
- sp = (u1 *) _mc->gp_regs[REG_SP];
- ra = (u1 *) _mc->gp_regs[PT_LNK]; /* this is correct for leafs */
- xpc = (u1 *) _mc->gp_regs[PT_NIP];
-
- instr = *((u4 *) xpc);
- reg = (instr >> 16) & 0x1f;
- addr = _mc->gp_regs[reg];
-
- if (addr == 0) {
- _mc->gp_regs[REG_ITMP1_XPTR] =
- (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
-
- _mc->gp_regs[REG_ITMP2_XPC] = (ptrint) xpc;
- _mc->gp_regs[PT_NIP] = (ptrint) asm_handle_exception;
+
+ /* get register values */
+
+ pv = (u1*) _mc->gp_regs[REG_PV];
+ sp = (u1*) _mc->gp_regs[REG_SP];
+ ra = (u1*) _mc->gp_regs[PT_LNK]; /* correct for leafs */
+ xpc =(u1*) _mc->gp_regs[PT_NIP];
+
+ /* get the throwing instruction */
+
+ mcode = *((u4*)xpc);
+
+ s1 = M_INSTR_OP2_IMM_A(mcode);
+ disp = M_INSTR_OP2_IMM_I(mcode);
+ d = M_INSTR_OP2_IMM_D(mcode);
+
+ val = _mc->gp_regs[d];
+
+ if (s1 == REG_ZERO) {
+ /* we use the exception type as load displacement */
+ type = disp;
}
else {
- codegen_get_pv_from_pc(xpc);
+ /* normal NPE */
+ addr = _mc->gp_regs[s1];
+ type = (s4) addr;
+ }
+
+ /* create stackframeinfo */
- /* this should not happen */
+ stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
- assert(0);
- }
+ /* Handle the type. */
+
+ p = signal_handle(xpc, type, val);
+
+ /* remove stackframeinfo */
+
+ stacktrace_remove_stackframeinfo(&sfi);
+
+ _mc->gp_regs[REG_ITMP1] = (intptr_t) p;
+ _mc->gp_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
+ _mc->gp_regs[PT_NIP] = (intptr_t) asm_handle_exception;
}
tobj->pc = pc;
}
+#endif
-void thread_restartcriticalsection(ucontext_t *_uc)
+/* 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;
- void *critical;
+ u1 *npc;
_mc = &(_uc->uc_mcontext);
pc = (u1 *) _mc->gp_regs[PT_NIP];
- critical = critical_find_restart_point(pc);
+ npc = critical_find_restart_point(pc);
- if (critical != NULL)
- _mc->gp_regs[PT_NIP] = (ptrint) critical;
+ if (npc != NULL)
+ _mc->gp_regs[PT_NIP] = (ptrint) npc;
}
#endif