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
25 $Id: md.c 8247 2007-07-31 12:06:44Z michi $
36 #include "vm/global.h"
38 #include "vm/jit/asmpart.h"
39 #include "vm/jit/codegen-common.h"
40 #include "vm/jit/md.h"
42 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
43 #include "vmcore/options.h" /* XXX debug */
44 #include "vm/jit/disass.h" /* XXX debug */
48 /* md_init *********************************************************************
50 Do some machine dependent initialization.
52 *******************************************************************************/
60 /* md_stacktrace_get_returnaddress *********************************************
62 Returns the return address of the current stackframe, specified by
63 the passed stack pointer and the stack frame size.
65 *******************************************************************************/
67 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
71 /* on i386 the return address is above the current stack frame */
73 ra = *((u1 **) (sp + framesize));
79 /* md_get_method_patch_address *************************************************
81 Gets the patch address of the currently compiled method. The offset
82 is extracted from the load instruction(s) before the jump and added
83 to the right base address (PV or REG_METHODPTR).
87 b9 30 00 49 b7 mov $0xb7490030,%ecx
93 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
99 8b 89 00 00 00 00 mov 0x0(%ecx),%ecx
100 8b 91 00 00 00 00 mov 0x0(%ecx),%edx
103 *******************************************************************************/
105 u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
109 u1 *pa; /* patch address */
111 /* go back to the actual call instruction (2-bytes) */
115 /* get the last byte of the call */
119 /* check for the different calls */
122 /* INVOKESTATIC/SPECIAL */
124 /* patch address is 4-bytes before the call instruction */
128 else if (mcode == 0xd2) {
129 /* INVOKEVIRTUAL/INTERFACE */
131 /* return NULL if no mptr was specified (used for replacement) */
136 /* Get the offset from the instruction (the offset address is
137 4-bytes before the call instruction). */
139 offset = *((s4 *) (ra - 4));
141 /* add the offset to the method pointer */
146 /* catch any problems */
148 pa = NULL; /* avoid warnings */
150 vm_abort("couldn't find a proper call instruction sequence");
157 /* md_codegen_get_pv_from_pc ***************************************************
159 On this architecture just a wrapper function to
160 codegen_get_pv_from_pc.
162 *******************************************************************************/
164 u1 *md_codegen_get_pv_from_pc(u1 *ra)
168 /* Get the start address of the function which contains this
169 address from the method table. */
171 pv = codegen_get_pv_from_pc(ra);
177 /* md_cacheflush ***************************************************************
179 Calls the system's function to flush the instruction and data
182 *******************************************************************************/
184 void md_cacheflush(u1 *addr, s4 nbytes)
190 /* md_icacheflush **************************************************************
192 Calls the system's function to flush the instruction cache.
194 *******************************************************************************/
196 void md_icacheflush(u1 *addr, s4 nbytes)
202 /* md_dcacheflush **************************************************************
204 Calls the system's function to flush the data cache.
206 *******************************************************************************/
208 void md_dcacheflush(u1 *addr, s4 nbytes)
214 /* md_patch_replacement_point **************************************************
216 Patch the given replacement point.
218 *******************************************************************************/
220 #if defined(ENABLE_REPLACEMENT)
221 void md_patch_replacement_point(codeinfo *code, s4 index, rplpoint *rp, u1 *savedmcode)
225 /* XXX this is probably unsafe! */
228 /* write spinning instruction */
229 *(u2*)(rp->pc) = 0xebfe;
232 rp->pc[4] = savedmcode[4];
234 /* write first word */
235 *(u4*)(rp->pc) = *(u4*)(savedmcode);
238 /* save the current machine code */
239 *(u4*)(savedmcode) = *(u4*)(rp->pc);
240 savedmcode[4] = rp->pc[4];
242 /* build the machine code for the patch */
243 assert(0); /* XXX build trap instruction below */
246 /* write spinning instruction */
247 *(u2*)(rp->pc) = 0xebfe;
250 rp->pc[4] = (mcode >> 32);
252 /* write first word */
253 *(u4*)(rp->pc) = (u4) mcode;
256 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER) && 0
264 /* XXX if required asm_cacheflush(rp->pc,8); */
266 #endif /* defined(ENABLE_REPLACEMENT) */
269 * These are local overrides for various environment variables in Emacs.
270 * Please do not remove this and leave it at the end of the file, where
271 * Emacs will automagically detect them.
272 * ---------------------------------------------------------------------
275 * indent-tabs-mode: t
279 * vim:noexpandtab:sw=4:ts=4: