1 /* src/vm/jit/powerpc/md.c - machine dependent PowerPC functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34 #include "vm/jit/powerpc/codegen.h"
35 #include "vm/jit/powerpc/md.h"
37 #include "vm/global.h"
40 #include "vm/jit/jit.hpp"
43 /* md_init *********************************************************************
45 Do some machine dependent initialization.
47 *******************************************************************************/
55 /* md_jit_method_patch_address *************************************************
57 Gets the patch address of the currently compiled method. The offset
58 is extracted from the load instruction(s) before the jump and added
59 to the right base address (PV or REG_METHODPTR).
63 81adffd4 lwz r13,-44(r13)
69 81830000 lwz r12,0(r3)
70 81ac0000 lwz r13,0(r12)
76 81830000 lwz r12,0(r3)
77 818c0000 lwz r12,0(r12)
78 81ac0000 lwz r13,0(r12)
82 *******************************************************************************/
84 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
91 /* go back to the actual load instruction (3 instructions) */
93 pc = ((uint32_t *) ra) - 3;
95 /* get first instruction word (lwz) */
99 /* check if we have 2 instructions (addis, addi) */
101 if ((mcode >> 16) == 0x3c19) {
102 /* XXX write a regression for this */
106 /* get displacement of first instruction (addis) */
108 offset = (int32_t) (mcode << 16);
110 /* get displacement of second instruction (addi) */
114 assert((mcode >> 16) != 0x6739);
116 offset += (int16_t) (mcode & 0x0000ffff);
119 /* get the offset from the instruction */
121 offset = (int16_t) (mcode & 0x0000ffff);
123 /* check for load from PV */
125 if ((mcode >> 16) == 0x81ad) {
126 /* get the final data segment address */
128 pa = ((uint8_t *) pv) + offset;
130 else if ((mcode >> 16) == 0x81ac) {
131 /* in this case we use the passed method pointer */
133 /* return NULL if no mptr was specified (used for replacement) */
138 pa = ((uint8_t *) mptr) + offset;
141 /* catch any problems */
143 vm_abort("md_jit_method_patch_address: unknown instruction %x",
146 /* keep compiler happy */
156 /* md_patch_replacement_point **************************************************
158 Patch the given replacement point.
160 *******************************************************************************/
162 #if defined(ENABLE_REPLACEMENT)
163 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
168 /* restore the patched-over instruction */
169 *(u4*)(pc) = *(u4*)(savedmcode);
172 /* save the current machine code */
173 *(u4*)(savedmcode) = *(u4*)(pc);
175 /* build the machine code for the patch */
176 assert(0); /* XXX build trap instruction below */
179 /* write the new machine code */
180 *(u4*)(pc) = (u4) mcode;
183 /* flush instruction cache */
184 md_icacheflush(pc,4);
186 #endif /* defined(ENABLE_REPLACEMENT) */
190 * These are local overrides for various environment variables in Emacs.
191 * Please do not remove this and leave it at the end of the file, where
192 * Emacs will automagically detect them.
193 * ---------------------------------------------------------------------
196 * indent-tabs-mode: t
200 * vim:noexpandtab:sw=4:ts=4: