1 /* src/vm/jit/powerpc64/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 5232 2006-08-11 13:11:44Z tbfg $
43 #include "vm/global.h"
44 #include "vm/jit/asmpart.h"
46 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
47 #include "vm/options.h" /* XXX debug */
48 #include "vm/jit/disass.h" /* XXX debug */
52 /* md_init *********************************************************************
54 Do some machine dependent initialization.
56 *******************************************************************************/
64 /* md_stacktrace_get_returnaddress *********************************************
66 Returns the return address of the current stackframe, specified by
67 the passed stack pointer and the stack frame size.
69 *******************************************************************************/
71 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
75 /* on PowerPC the return address is located in the linkage area */
77 ra = *((u1 **) (sp + framesize + LA_LR_OFFSET));
83 /* md_get_method_patch_address *************************************************
85 Gets the patch address of the currently compiled method. The offset
86 is extracted from the load instruction(s) before the jump and added
87 to the right base address (PV or REG_METHODPTR).
91 81adffd4 lwz r13,-44(r13)
97 81830000 lwz r12,0(r3)
98 81ac0000 lwz r13,0(r12)
104 81830000 lwz r12,0(r3)
105 818c0000 lwz r12,0(r12)
106 81ac0000 lwz r13,0(r12)
110 *******************************************************************************/
112 u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
118 /* go back to the actual load instruction (3 instructions) */
122 /* get first instruction word (lwz) */
124 mcode = *((u4 *) ra);
126 /* check if we have 2 instructions (addis, addi) */
128 if ((mcode >> 16) == 0x3c19) {
129 /* XXX write a regression for this */
132 /* get displacement of first instruction (addis) */
134 offset = (s4) (mcode << 16);
136 /* get displacement of second instruction (addi) */
138 mcode = *((u4 *) (ra + 1 * 4));
140 assert((mcode >> 16) != 0x6739);
142 offset += (s2) (mcode & 0x0000ffff);
145 /* get the offset from the instruction */
147 offset = (s2) (mcode & 0x0000ffff);
149 /* check for load from PV */
151 if ((mcode >> 16) == 0x81ad) {
152 /* get the final data segment address */
154 pa = sfi->pv + offset;
156 } else if ((mcode >> 16) == 0x81ac) {
157 /* in this case we use the passed method pointer */
162 /* catch any problems */
172 /* md_codegen_findmethod *******************************************************
177 39cbffe0 addi r14r11,-32
182 3dcbffff addis r14r11,-1
183 39ce68b0 addi r14,r13,26800
185 *******************************************************************************/
187 u1 *md_codegen_findmethod(u1 *ra)
193 /* get first instruction word after jump */
195 mcode = *((u4 *) (ra + 1 * 4));
197 /* check if we have 2 instructions (addis, addi) */
199 if ((mcode >> 16) == 0x3dcb) {
200 /* get displacement of first instruction (addis) */
202 offset = (s4) (mcode << 16);
204 /* get displacement of second instruction (addi) */
206 mcode = *((u4 *) (ra + 2 * 4));
208 /* check for addi instruction */
210 assert((mcode >> 16) == 0x39ce);
212 offset += (s2) (mcode & 0x0000ffff);
215 /* check for addi instruction */
217 assert((mcode >> 16) == 0x39cb);
219 /* get offset of first instruction (addi) */
221 offset = (s2) (mcode & 0x0000ffff);
224 /* calculate PV via RA + offset */
232 /* md_cacheflush ***************************************************************
234 Calls the system's function to flush the instruction and data
237 *******************************************************************************/
239 void md_cacheflush(u1 *addr, s4 nbytes)
241 asm_cacheflush(addr, nbytes);
245 /* md_icacheflush **************************************************************
247 Calls the system's function to flush the instruction cache.
249 *******************************************************************************/
251 void md_icacheflush(u1 *addr, s4 nbytes)
253 asm_cacheflush(addr, nbytes);
257 /* md_dcacheflush **************************************************************
259 Calls the system's function to flush the data cache.
261 *******************************************************************************/
263 void md_dcacheflush(u1 *addr, s4 nbytes)
265 asm_cacheflush(addr, nbytes);
269 /* md_patch_replacement_point **************************************************
271 Patch the given replacement point.
273 *******************************************************************************/
275 void md_patch_replacement_point(rplpoint *rp)
279 /* save the current machine code */
280 mcode = *(u4*)rp->pc;
282 /* write the new machine code */
283 *(u4*)(rp->pc) = (u4) rp->mcode;
285 /* store saved mcode */
288 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
296 /* flush instruction cache */
297 md_icacheflush(rp->pc,4);
301 * These are local overrides for various environment variables in Emacs.
302 * Please do not remove this and leave it at the end of the file, where
303 * Emacs will automagically detect them.
304 * ---------------------------------------------------------------------
307 * indent-tabs-mode: t
311 * vim:noexpandtab:sw=4:ts=4: