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 5248 2006-08-17 17:51:40Z 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 e9ceffb8 ld r14,-72(r14)
97 FIXME 81830000 lwz r12,0(r3)
98 e9cc0000 ld r14,0(r12)
105 FIXME 81830000 lwz r12,0(r3)
106 FIXME 818c0000 lwz r12,0(r12)
107 FIXME 81ac0000 lwz r13,0(r12)
111 *******************************************************************************/
113 u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
119 /* go back to the actual load instruction (3 instructions) */
123 /* get first instruction word (lwz) */
125 mcode = *((u4 *) ra);
127 /* check if we have 2 instructions (addis, addi) */
129 if ((mcode >> 16) == 0x3c19) {
130 /* XXX write a regression for this */
133 /* get displacement of first instruction (addis) */
135 offset = (s4) (mcode << 16);
137 /* get displacement of second instruction (addi) */
139 mcode = *((u4 *) (ra + 1 * 4));
141 assert((mcode >> 16) != 0x6739);
143 offset += (s2) (mcode & 0x0000ffff);
146 /* get the offset from the instruction */
148 offset = (s2) (mcode & 0x0000ffff);
150 /* check for load from PV */
152 if ((mcode >> 16) == 0xe9ce) {
153 /* get the final data segment address */
155 pa = sfi->pv + offset;
157 } else if ((mcode >> 16) == 0xe9cc) {
158 /* in this case we use the passed method pointer */
163 /* catch any problems */
173 /* md_codegen_get_pv_from_pc ***************************************************
178 39cbffe0 addi r14r11,-32
183 3dcbffff addis r14r11,-1
184 39ce68b0 addi r14,r13,26800
186 *******************************************************************************/
188 u1 *md_codegen_get_pv_from_pc(u1 *ra)
194 /* get first instruction word after jump */
196 mcode = *((u4 *) (ra + 1 * 4));
198 /* check if we have 2 instructions (addis, addi) */
200 if ((mcode >> 16) == 0x3dcb) {
201 /* get displacement of first instruction (addis) */
203 offset = (s4) (mcode << 16);
205 /* get displacement of second instruction (addi) */
207 mcode = *((u4 *) (ra + 2 * 4));
209 /* check for addi instruction */
211 assert((mcode >> 16) == 0x39ce);
213 offset += (s2) (mcode & 0x0000ffff);
216 /* check for addi instruction */
218 assert((mcode >> 16) == 0x39cb);
220 /* get offset of first instruction (addi) */
222 offset = (s2) (mcode & 0x0000ffff);
225 /* calculate PV via RA + offset */
233 /* md_cacheflush ***************************************************************
235 Calls the system's function to flush the instruction and data
238 *******************************************************************************/
240 void md_cacheflush(u1 *addr, s4 nbytes)
242 asm_cacheflush(addr, nbytes);
246 /* md_icacheflush **************************************************************
248 Calls the system's function to flush the instruction cache.
250 *******************************************************************************/
252 void md_icacheflush(u1 *addr, s4 nbytes)
254 asm_cacheflush(addr, nbytes);
258 /* md_dcacheflush **************************************************************
260 Calls the system's function to flush the data cache.
262 *******************************************************************************/
264 void md_dcacheflush(u1 *addr, s4 nbytes)
266 asm_cacheflush(addr, nbytes);
270 /* md_patch_replacement_point **************************************************
272 Patch the given replacement point.
274 *******************************************************************************/
276 void md_patch_replacement_point(rplpoint *rp)
280 /* save the current machine code */
281 mcode = *(u4*)rp->pc;
283 /* write the new machine code */
284 *(u4*)(rp->pc) = (u4) rp->mcode;
286 /* store saved mcode */
289 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
297 /* flush instruction cache */
298 md_icacheflush(rp->pc,4);
302 * These are local overrides for various environment variables in Emacs.
303 * Please do not remove this and leave it at the end of the file, where
304 * Emacs will automagically detect them.
305 * ---------------------------------------------------------------------
308 * indent-tabs-mode: t
312 * vim:noexpandtab:sw=4:ts=4: