/* src/vm/jit/powerpc64/md.c - machine dependent PowerPC functions
- Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ 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
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- Contact: cacao@cacaojvm.org
-
- Authors: Christian Thalinger
-
- Changes: Edwin Steiner
-
- $Id: md.c 5934 2006-11-08 13:33:08Z tbfg $
+ $Id: md.c 7596 2007-03-28 21:05:53Z twisti $
*/
+
#include "config.h"
#include <assert.h>
#include "md-abi.h"
+#include "vm/jit/powerpc64/codegen.h"
+
#include "vm/global.h"
+
#include "vm/jit/asmpart.h"
+#include "vm/jit/stacktrace.h"
#if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
-#include "vm/options.h" /* XXX debug */
+#include "vmcore/options.h" /* XXX debug */
#include "vm/jit/disass.h" /* XXX debug */
#endif
vm_abort("jump displacement is out of range: %d > +/-%d", disp, 0x00007fff);
mcode &= 0xffff0000;
- mcode |= (((disp)&0xfffc));
+ mcode |= (((disp)& M_BCMASK));
} else if ((mcode & 0xfc000000) == 0x48000000) {
/* unconditional jump bx */
if ((disp < (s4) 0xfc000000) || (disp > (s4) 0x03ffffff))
vm_abort("jump displacement is out of range: %d > +/-%d", disp, 0x0cffffff);
mcode &= 0xfc000000;
- mcode |= (((disp)&0x03fffffc));
+ mcode |= (((disp)& M_BMASK));
} else {
vm_abort("md_codegen_patch_branch, patching unsupported branch: %xd", mcode);
}
} else if ((mcode >> 16) == 0xe9cc) {
/* in this case we use the passed method pointer */
+ /* return NULL if no mptr was specified (used for replacement) */
+
+ if (mptr == NULL)
+ return NULL;
+
pa = mptr + offset;
} else {
*******************************************************************************/
-void md_patch_replacement_point(rplpoint *rp)
+#if defined(ENABLE_REPLACEMENT)
+void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp, u1 *savedmcode)
{
- u8 mcode;
+ s4 disp;
+ u4 mcode;
- /* save the current machine code */
- mcode = *(u4*)rp->pc;
+ if (index < 0) {
+ /* restore the patched-over instruction */
+ *(u4*)(rp->pc) = *(u4*)(savedmcode);
+ }
+ else {
+ /* save the current machine code */
+ *(u4*)(savedmcode) = *(u4*)(rp->pc);
- /* write the new machine code */
- *(u4*)(rp->pc) = (u4) rp->mcode;
+ /* build the machine code for the patch */
+ disp = ((u4*)code->replacementstubs - (u4*)rp->pc)
+ + index * REPLACEMENT_STUB_SIZE
+ - 1;
- /* store saved mcode */
- rp->mcode = mcode;
+ mcode = (18 << 26) | ((((disp) * 4) + 4) & M_BMASK);
+
+ /* write the new machine code */
+ *(u4*)(rp->pc) = (u4) mcode;
+ }
#if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
{
/* flush instruction cache */
md_icacheflush(rp->pc,4);
}
+#endif /* defined(ENABLE_REPLACEMENT) */
/*
* These are local overrides for various environment variables in Emacs.