1 /* src/vm/jit/i386/md.c - machine dependent i386 functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "vm/global.h"
36 #include "vm/jit/asmpart.h"
37 #include "vm/jit/codegen-common.h"
38 #include "vm/jit/md.h"
40 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
41 #include "vmcore/options.h" /* XXX debug */
42 #include "vm/jit/disass.h" /* XXX debug */
46 /* md_init *********************************************************************
48 Do some machine dependent initialization.
50 *******************************************************************************/
58 /* md_stacktrace_get_returnaddress *********************************************
60 Returns the return address of the current stackframe, specified by
61 the passed stack pointer and the stack frame size.
63 *******************************************************************************/
65 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
69 /* on i386 the return address is above the current stack frame */
71 ra = *((u1 **) (sp + framesize));
77 /* md_get_method_patch_address *************************************************
79 Gets the patch address of the currently compiled method. The offset
80 is extracted from the load instruction(s) before the jump and added
81 to the right base address (PV or REG_METHODPTR).
85 b9 30 00 49 b7 mov $0xb7490030,%ecx
91 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
97 8b 89 00 00 00 00 mov 0x0(%ecx),%ecx
98 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
101 *******************************************************************************/
103 u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
107 u1 *pa; /* patch address */
109 /* go back to the actual call instruction (2-bytes) */
113 /* get the last byte of the call */
117 /* check for the different calls */
120 /* INVOKESTATIC/SPECIAL */
122 /* patch address is 4-bytes before the call instruction */
126 else if (mcode == 0xd2) {
127 /* INVOKEVIRTUAL/INTERFACE */
129 /* return NULL if no mptr was specified (used for replacement) */
134 /* Get the offset from the instruction (the offset address is
135 4-bytes before the call instruction). */
137 offset = *((s4 *) (ra - 4));
139 /* add the offset to the method pointer */
144 /* catch any problems */
146 pa = NULL; /* avoid warnings */
148 vm_abort("couldn't find a proper call instruction sequence");
155 /* md_codegen_get_pv_from_pc ***************************************************
157 On this architecture just a wrapper function to
158 codegen_get_pv_from_pc.
160 *******************************************************************************/
162 u1 *md_codegen_get_pv_from_pc(u1 *ra)
166 /* Get the start address of the function which contains this
167 address from the method table. */
169 pv = codegen_get_pv_from_pc(ra);
175 /* md_cacheflush ***************************************************************
177 Calls the system's function to flush the instruction and data
180 *******************************************************************************/
182 void md_cacheflush(u1 *addr, s4 nbytes)
188 /* md_icacheflush **************************************************************
190 Calls the system's function to flush the instruction cache.
192 *******************************************************************************/
194 void md_icacheflush(u1 *addr, s4 nbytes)
200 /* md_dcacheflush **************************************************************
202 Calls the system's function to flush the data cache.
204 *******************************************************************************/
206 void md_dcacheflush(u1 *addr, s4 nbytes)
212 /* md_patch_replacement_point **************************************************
214 Patch the given replacement point.
216 *******************************************************************************/
218 #if defined(ENABLE_REPLACEMENT)
219 void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp, u1 *savedmcode)
223 /* XXX this is probably unsafe! */
226 /* write spinning instruction */
227 *(u2*)(rp->pc) = 0xebfe;
230 rp->pc[4] = savedmcode[4];
232 /* write first word */
233 *(u4*)(rp->pc) = *(u4*)(savedmcode);
236 /* save the current machine code */
237 *(u4*)(savedmcode) = *(u4*)(rp->pc);
238 savedmcode[4] = rp->pc[4];
240 /* build the machine code for the patch */
241 assert(0); /* XXX build trap instruction below */
244 /* write spinning instruction */
245 *(u2*)(rp->pc) = 0xebfe;
248 rp->pc[4] = (mcode >> 32);
250 /* write first word */
251 *(u4*)(rp->pc) = (u4) mcode;
254 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) && 0
262 /* XXX if required asm_cacheflush(rp->pc,8); */
264 #endif /* defined(ENABLE_REPLACEMENT) */
267 * These are local overrides for various environment variables in Emacs.
268 * Please do not remove this and leave it at the end of the file, where
269 * Emacs will automagically detect them.
270 * ---------------------------------------------------------------------
273 * indent-tabs-mode: t
277 * vim:noexpandtab:sw=4:ts=4: