Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: emit.c 8186 2007-07-05 23:48:16Z michi $
+ $Id: emit.c 8260 2007-08-06 12:19:01Z michi $
*/
#include "vm/types.h"
#include <assert.h>
+#include <stdint.h>
#include "md-abi.h"
}
-/* emit_patcher_traps **********************************************************
+/* emit_trap *******************************************************************
- Generates the code for the patcher traps.
+ Emit a trap instruction and return the original machine code.
*******************************************************************************/
-void emit_patcher_traps(jitdata *jd)
+uint32_t emit_trap(codegendata *cd)
{
- codegendata *cd;
- codeinfo *code;
- patchref_t *pr;
- u1 *savedmcodeptr;
- u1 *tmpmcodeptr;
-
- /* get required compiler data */
-
- cd = jd->cd;
- code = jd->code;
-
- /* generate patcher traps code */
-
- for (pr = list_first_unsynced(code->patchers); pr != NULL; pr = list_next_unsynced(code->patchers, pr)) {
-
- /* Get machine code which is patched back in later. The
- trap is 1 instruction word long. */
-
- tmpmcodeptr = (u1 *) (cd->mcodebase + pr->mpc);
- pr->mcode = *((u4 *) tmpmcodeptr);
-
- /* Patch in the trap to call the signal handler (done at
- compile time). */
-
- savedmcodeptr = cd->mcodeptr; /* save current mcodeptr */
- cd->mcodeptr = tmpmcodeptr; /* set mcodeptr to patch position */
+ uint32_t mcode;
- M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
+ /* Get machine code which is patched back in later. The
+ trap is 1 instruction word long. */
- cd->mcodeptr = savedmcodeptr; /* restore the current mcodeptr */
- }
-}
-
-
-/* emit_replacement_stubs ******************************************************
-
- Generates the code for the replacement stubs.
+ mcode = *((u4 *) cd->mcodeptr);
-*******************************************************************************/
-
-#if defined(ENABLE_REPLACEMENT)
-void emit_replacement_stubs(jitdata *jd)
-{
- codegendata *cd;
- codeinfo *code;
- rplpoint *rplp;
- s4 disp;
- s4 i;
-#if !defined(NDEBUG)
- u1 *savedmcodeptr;
-#endif
+ /* Destination register must not be REG_ZERO, because then no
+ SIGSEGV is thrown. */
+ M_ALD_INTERN(REG_RESULT, REG_ZERO, EXCEPTION_HARDWARE_PATCHER);
- /* get required compiler data */
-
- cd = jd->cd;
- code = jd->code;
-
- rplp = code->rplpoints;
-
- /* store beginning of replacement stubs */
-
- code->replacementstubs = (u1*) (cd->mcodeptr - cd->mcodebase);
-
- for (i = 0; i < code->rplpointcount; ++i, ++rplp) {
- /* do not generate stubs for non-trappable points */
-
- if (rplp->flags & RPLPOINT_FLAG_NOTRAP)
- continue;
-
- /* check code segment size */
-
- MCODECHECK(100);
-
-#if !defined(NDEBUG)
- savedmcodeptr = cd->mcodeptr;
-#endif
-
- /* create stack frame - 16-byte aligned */
-
- M_LSUB_IMM(REG_SP, 2 * 8, REG_SP);
-
- /* push address of `rplpoint` struct */
-
- disp = dseg_add_address(cd, rplp);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_AST(REG_ITMP3, REG_SP, 0 * 8);
-
- /* jump to replacement function */
-
- disp = dseg_add_functionptr(cd, asm_replacement_out);
- M_ALD(REG_ITMP3, REG_PV, disp);
- M_JMP(REG_ZERO, REG_ITMP3);
-
- assert((cd->mcodeptr - savedmcodeptr) == 4*REPLACEMENT_STUB_SIZE);
- }
+ return mcode;
}
-#endif /* defined(ENABLE_REPLACEMENT) */
/* emit_verbosecall_enter ******************************************************