1 /* src/vm/jit/i386/md.c - machine dependent i386 functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33 #include "vm/global.h"
36 #include "vm/jit/asmpart.h"
37 #include "vm/jit/jit.hpp"
40 /* md_init *********************************************************************
42 Do some machine dependent initialization.
44 *******************************************************************************/
52 /* md_jit_method_patch_address *************************************************
54 Gets the patch address of the currently compiled method. The offset
55 is extracted from the load instruction(s) before the jump and added
56 to the right base address (PV or REG_METHODPTR).
60 b9 30 00 49 b7 mov $0xb7490030,%ecx
66 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
72 8b 89 00 00 00 00 mov 0x0(%ecx),%ecx
73 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
76 *******************************************************************************/
78 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
83 void *pa; /* patch address */
85 /* go back to the actual call instruction (2-bytes) */
87 pc = ((uint8_t *) ra) - 2;
89 /* Get the opcode of the call. */
91 opcode = *((uint16_t *) pc);
93 /* check for the different calls */
97 /* INVOKESTATIC/SPECIAL */
99 /* Patch address is 4-bytes before the call instruction. */
105 /* INVOKEVIRTUAL/INTERFACE */
107 /* Return NULL if no mptr was specified (used for
113 /* Get the displacement from the instruction (the displacement
114 address is 4-bytes before the call instruction). */
116 disp = *((int32_t *) (pc - 4));
118 /* Add the displacement to the method pointer. */
120 pa = ((uint8_t *) mptr) + disp;
124 vm_abort_disassemble(pc, 1, "md_jit_method_patch_address: unknown instruction %x", opcode);
132 /* md_patch_replacement_point **************************************************
134 Patch the given replacement point.
136 *******************************************************************************/
138 #if defined(ENABLE_REPLACEMENT)
139 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
144 /* write saved machine code */
145 *(u2*)(pc) = *(u2*)(savedmcode);
148 /* save the current machine code */
149 *(u2*)(savedmcode) = *(u2*)(pc);
151 /* build the machine code for the patch */
154 /* write new machine code */
158 /* XXX if required asm_cacheflush(pc,8); */
160 #endif /* defined(ENABLE_REPLACEMENT) */
163 * These are local overrides for various environment variables in Emacs.
164 * Please do not remove this and leave it at the end of the file, where
165 * Emacs will automagically detect them.
166 * ---------------------------------------------------------------------
169 * indent-tabs-mode: t
173 * vim:noexpandtab:sw=4:ts=4: