1 /* src/vm/jit/powerpc/md.c - machine dependent PowerPC functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
29 Changes: Edwin Steiner
31 $Id: md.c 4653 2006-03-18 04:14:17Z edwin $
43 #include "vm/global.h"
44 #include "vm/jit/asmpart.h"
45 #include "vm/options.h" /* XXX debug */
46 #include "vm/jit/disass.h" /* XXX debug */
49 /* md_init *********************************************************************
51 Do some machine dependent initialization.
53 *******************************************************************************/
61 /* md_stacktrace_get_returnaddress *********************************************
63 Returns the return address of the current stackframe, specified by
64 the passed stack pointer and the stack frame size.
66 *******************************************************************************/
68 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
72 /* on PowerPC the return address is located in the linkage area */
74 ra = *((u1 **) (sp + framesize + LA_LR_OFFSET));
80 /* md_codegen_findmethod *******************************************************
85 39abffe0 addi r13,r11,-32
90 3dabffff addis r13,r11,-1
91 39ad68b0 addi r13,r13,26800
93 *******************************************************************************/
95 u1 *md_codegen_findmethod(u1 *ra)
101 /* get first instruction word after jump */
103 mcode = *((u4 *) (ra + 1 * 4));
105 /* check if we have 2 instructions (addis, addi) */
107 if ((mcode >> 16) == 0x3dab) {
108 /* get displacement of first instruction (addis) */
110 offset = (s4) (mcode << 16);
112 /* get displacement of second instruction (addi) */
114 mcode = *((u4 *) (ra + 2 * 4));
116 /* check for addi instruction */
118 assert((mcode >> 16) == 0x39ad);
120 offset += (s2) (mcode & 0x0000ffff);
123 /* check for addi instruction */
125 assert((mcode >> 16) == 0x39ab);
127 /* get offset of first instruction (addi) */
129 offset = (s2) (mcode & 0x0000ffff);
132 /* calculate PV via RA + offset */
140 /* md_cacheflush ***************************************************************
142 Calls the system's function to flush the instruction and data
145 *******************************************************************************/
147 void md_cacheflush(u1 *addr, s4 nbytes)
149 asm_cacheflush(addr, nbytes);
153 /* md_icacheflush **************************************************************
155 Calls the system's function to flush the instruction cache.
157 *******************************************************************************/
159 void md_icacheflush(u1 *addr, s4 nbytes)
161 asm_cacheflush(addr, nbytes);
165 /* md_dcacheflush **************************************************************
167 Calls the system's function to flush the data cache.
169 *******************************************************************************/
171 void md_dcacheflush(u1 *addr, s4 nbytes)
173 asm_cacheflush(addr, nbytes);
177 /* md_patch_replacement_point **************************************************
179 Patch the given replacement point.
181 *******************************************************************************/
183 void md_patch_replacement_point(rplpoint *rp)
187 /* save the current machine code */
188 mcode = *(u4*)rp->pc;
190 /* write the new machine code */
191 *(u4*)(rp->pc) = (u4) rp->mcode;
193 /* store saved mcode */
202 /* flush instruction cache */
203 md_icacheflush(rp->pc,4);
207 * These are local overrides for various environment variables in Emacs.
208 * Please do not remove this and leave it at the end of the file, where
209 * Emacs will automagically detect them.
210 * ---------------------------------------------------------------------
213 * indent-tabs-mode: t
217 * vim:noexpandtab:sw=4:ts=4: