/* src/vm/jit/powerpc/md.c - machine dependent PowerPC 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) 2009 Theobroma Systems Ltd.
This file is part of CACAO.
#include "vm/jit/powerpc/md.h"
#include "vm/global.h"
-#include "vm/vm.h"
+#include "vm/vm.hpp"
-#include "vm/jit/jit.h"
+#include "vm/jit/jit.hpp"
+#include "vm/jit/trap.hpp"
/* md_init *********************************************************************
}
+/**
+ * Decode the trap instruction at the given PC.
+ *
+ * @param trp information about trap to be filled
+ * @param sig signal number
+ * @param xpc exception PC
+ * @param es execution state of the machine
+ * @return true if trap was decoded successfully, false otherwise.
+ */
+bool md_trap_decode(trapinfo_t* trp, int sig, void* xpc, executionstate_t* es)
+{
+ // Get the exception-throwing instruction.
+ uint32_t mcode = *((uint32_t*) xpc);
+
+ switch (sig) {
+ case TRAP_SIGILL:
+ // Check for valid trap instruction.
+ if (patcher_is_valid_trap_instruction_at(xpc)) {
+ trp->type = TRAP_PATCHER;
+ trp->value = 0;
+ return true;
+ }
+ return false;
+
+ case TRAP_SIGTRAP:
+ {
+ int s1 = M_OP3_GET_A(mcode);
+
+ // For now we only handle ArrayIndexOutOfBoundsException.
+ trp->type = TRAP_ArrayIndexOutOfBoundsException;
+ trp->value = es->intregs[s1];
+ return true;
+ }
+
+ case TRAP_SIGSEGV:
+ {
+ int s1 = M_INSTR_OP2_IMM_A(mcode);
+ uintptr_t addr = es->intregs[s1];
+
+ // Check for special-load.
+ if (s1 == REG_ZERO) {
+ int16_t disp = M_INSTR_OP2_IMM_I(mcode);
+ int d = M_INSTR_OP2_IMM_D(mcode);
+
+ // We use the exception type as load displacement.
+ trp->type = disp;
+ trp->value = es->intregs[d];
+ return true;
+ }
+
+ // Check for implicit NullPointerException.
+ if (addr == 0) {
+ trp->type = TRAP_NullPointerException;
+ trp->value = 0;
+ return true;
+ }
+
+ return false;
+ }
+
+ default:
+ return false;
+ }
+}
+
+
/* md_patch_replacement_point **************************************************
Patch the given replacement point.
/* save the current machine code */
*(u4*)(savedmcode) = *(u4*)(pc);
- /* build the machine code for the patch */
- assert(0); /* XXX build trap instruction below */
+ // Build the machine code for the patch. On PowerPC we use
+ // an illegal instruction which really is just 0, believe me!
mcode = 0;
/* write the new machine code */