/* src/vm/jit/mips/emit.c - MIPS code emitter 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
This file is part of CACAO.
#include "vm/jit/mips/codegen.h"
#include "vm/jit/mips/md-abi.h"
-#include "mm/memory.h"
+#include "mm/memory.hpp"
-#include "threads/lock-common.h"
+#include "threads/lock.hpp"
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h" /* XXX for gen_resolvebranch */
+#include "vm/jit/builtin.hpp"
+#include "vm/options.h"
#include "vm/jit/abi.h"
#include "vm/jit/abi-asm.h"
#include "vm/jit/asmpart.h"
#include "vm/jit/dseg.h"
-#include "vm/jit/emit-common.h"
-#include "vm/jit/jit.h"
-#include "vm/jit/patcher-common.h"
-#include "vm/jit/replace.h"
-
-#include "vmcore/options.h"
+#include "vm/jit/emit-common.hpp"
+#include "vm/jit/jit.hpp"
+#include "vm/jit/patcher-common.hpp"
+#include "vm/jit/replace.hpp"
+#include "vm/jit/trap.hpp"
/* emit_load *******************************************************************
void emit_branch(codegendata *cd, s4 disp, s4 condition, s4 reg, u4 opt)
{
- s4 checkdisp;
- s4 branchdisp;
-
- /* calculate the different displacements */
-
- checkdisp = (disp - 4);
- branchdisp = (disp - 4) >> 2;
+ // Calculate the displacements.
+ int32_t checkdisp = (disp - 4);
+ int32_t branchdisp = (disp - 4) >> 2;
/* check which branch to generate */
if (condition == BRANCH_UNCONDITIONAL) {
- /* check displacement for overflow */
-
- if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
+ // Check displacement for overflow.
+ if (opt_AlwaysEmitLongBranches || ((checkdisp < (int32_t) 0xffff8000) || (checkdisp > (int32_t) 0x00007fff))) {
/* if the long-branches flag isn't set yet, do it */
if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
CODEGENDATA_FLAG_LONGBRANCHES);
}
- vm_abort("emit_branch: emit unconditional long-branch code");
+ // Calculate the offset relative to PV.
+ int32_t currentrpc = cd->mcodeptr - cd->mcodebase;
+ int32_t offset = currentrpc + disp;
+
+ // Sanity check.
+ assert(offset % 4 == 0);
+
+ // Do the long-branch.
+ M_LUI(REG_ITMP3, offset >> 16);
+ M_OR_IMM(REG_ITMP3, offset, REG_ITMP3);
+ M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
+ M_JMP(REG_ITMP3);
+ M_NOP;
+ M_NOP; // This nop is to have 6 instructions (see BRANCH_NOPS).
}
else {
M_BR(branchdisp);
}
}
else {
- /* and displacement for overflow */
-
- if ((checkdisp < (s4) 0xffff8000) || (checkdisp > (s4) 0x00007fff)) {
+ // Check displacement for overflow.
+ if (opt_AlwaysEmitLongBranches || ((checkdisp < (int32_t) 0xffff8000) || (checkdisp > (int32_t) 0x00007fff))) {
/* if the long-branches flag isn't set yet, do it */
if (!CODEGENDATA_HAS_FLAG_LONGBRANCHES(cd)) {
CODEGENDATA_FLAG_LONGBRANCHES);
}
+ // Calculate the offset relative to PV before we generate
+ // new code.
+ int32_t currentrpc = cd->mcodeptr - cd->mcodebase;
+ int32_t offset = currentrpc + disp;
+
+ // Sanity check.
+ assert(offset % 4 == 0);
+
switch (condition) {
case BRANCH_EQ:
M_BNE(GET_HIGH_REG(reg), GET_LOW_REG(reg), 5);
vm_abort("emit_branch: unknown condition %d", condition);
}
- /* The actual branch code which is over-jumped (NOTE: we
- don't use a branch delay slot here). */
+ // The actual branch code which is over-jumped. NOTE: We
+ // don't use a branch delay slot for the conditional
+ // branch.
- M_LUI(REG_ITMP3, branchdisp >> 16);
- M_OR_IMM(REG_ITMP3, branchdisp, REG_ITMP3);
+ // Do the long-branch.
+ M_LUI(REG_ITMP3, offset >> 16);
+ M_OR_IMM(REG_ITMP3, offset, REG_ITMP3);
M_AADD(REG_PV, REG_ITMP3, REG_ITMP3);
M_JMP(REG_ITMP3);
M_NOP;
-
}
else {
switch (condition) {
if (INSTRUCTION_MUST_CHECK(iptr)) {
M_BNEZ(reg, 2);
M_NOP;
- M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_ARITHMETIC);
+ M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_ArithmeticException);
}
}
M_CMPULT(s2, REG_ITMP3, REG_ITMP3);
M_BNEZ(REG_ITMP3, 2);
M_NOP;
- M_ALD_INTERN(s2, REG_ZERO, EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS);
+ M_ALD_INTERN(s2, REG_ZERO, TRAP_ArrayIndexOutOfBoundsException);
+ }
+}
+
+
+/* emit_arraystore_check *******************************************************
+
+ Emit an ArrayStoreException check.
+
+*******************************************************************************/
+
+void emit_arraystore_check(codegendata *cd, instruction *iptr)
+{
+ if (INSTRUCTION_MUST_CHECK(iptr)) {
+ M_BNEZ(REG_RESULT, 2);
+ M_NOP;
+ M_ALD_INTERN(REG_RESULT, REG_ZERO, TRAP_ArrayStoreException);
}
}
}
M_NOP;
- M_ALD_INTERN(s1, REG_ZERO, EXCEPTION_HARDWARE_CLASSCAST);
+ M_ALD_INTERN(s1, REG_ZERO, TRAP_ClassCastException);
}
}
if (INSTRUCTION_MUST_CHECK(iptr)) {
M_BNEZ(reg, 2);
M_NOP;
- M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_NULLPOINTER);
+ M_ALD_INTERN(REG_ZERO, REG_ZERO, TRAP_NullPointerException);
}
}
if (INSTRUCTION_MUST_CHECK(iptr)) {
M_BNEZ(REG_RESULT, 2);
M_NOP;
- M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_EXCEPTION);
+ M_ALD_INTERN(REG_RESULT, REG_ZERO, TRAP_CHECK_EXCEPTION);
}
}
+/* emit_trap_compiler **********************************************************
+
+ Emit a trap instruction which calls the JIT compiler.
+
+*******************************************************************************/
+
+void emit_trap_compiler(codegendata *cd)
+{
+ M_ALD_INTERN(REG_METHODPTR, REG_ZERO, TRAP_COMPILER);
+}
+
+
/* emit_trap *******************************************************************
Emit a trap instruction and return the original machine code.
uint32_t emit_trap(codegendata *cd)
{
- uint32_t mcode;
-
- /* Get machine code which is patched back in later. The
- trap is 1 instruction word long. */
+ // Get machine code which is patched back in later. The trap is 1
+ // instruction word long.
+ uint32_t mcode = *((uint32_t*) cd->mcodeptr);
- mcode = *((u4 *) cd->mcodeptr);
-
- M_ALD_INTERN(REG_ZERO, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
+ M_RESERVED;
return mcode;
}
void emit_verbosecall_enter(jitdata *jd)
{
methodinfo *m;
+ codeinfo *code;
codegendata *cd;
registerdata *rd;
methoddesc *md;
/* get required compiler data */
- m = jd->m;
- cd = jd->cd;
- rd = jd->rd;
+ m = jd->m;
+ code = jd->code;
+ cd = jd->cd;
+ rd = jd->rd;
md = m->parseddesc;
/* save temporary registers for leaf methods */
- if (jd->isleafmethod) {
+ if (code_is_leafmethod(code)) {
for (i = 0; i < INT_TMP_CNT; i++)
M_AST(rd->tmpintregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + i) * 8);
/* restore temporary registers for leaf methods */
- if (jd->isleafmethod) {
+ if (code_is_leafmethod(code)) {
for (i = 0; i < INT_TMP_CNT; i++)
M_ALD(rd->tmpintregs[i], REG_SP, PA_SIZE + (2 + ARG_CNT + i) * 8);