1 /* src/vm/jit/powerpc/md.c - machine dependent PowerPC 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
36 #include "vm/jit/powerpc/codegen.h"
37 #include "vm/jit/powerpc/md.h"
39 #include "vm/global.h"
42 #include "vm/jit/jit.h"
45 /* md_init *********************************************************************
47 Do some machine dependent initialization.
49 *******************************************************************************/
57 /* md_jit_method_patch_address *************************************************
59 Gets the patch address of the currently compiled method. The offset
60 is extracted from the load instruction(s) before the jump and added
61 to the right base address (PV or REG_METHODPTR).
65 81adffd4 lwz r13,-44(r13)
71 81830000 lwz r12,0(r3)
72 81ac0000 lwz r13,0(r12)
78 81830000 lwz r12,0(r3)
79 818c0000 lwz r12,0(r12)
80 81ac0000 lwz r13,0(r12)
84 *******************************************************************************/
86 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
93 /* go back to the actual load instruction (3 instructions) */
95 pc = ((uint32_t *) ra) - 3;
97 /* get first instruction word (lwz) */
101 /* check if we have 2 instructions (addis, addi) */
103 if ((mcode >> 16) == 0x3c19) {
104 /* XXX write a regression for this */
108 /* get displacement of first instruction (addis) */
110 offset = (int32_t) (mcode << 16);
112 /* get displacement of second instruction (addi) */
116 assert((mcode >> 16) != 0x6739);
118 offset += (int16_t) (mcode & 0x0000ffff);
121 /* get the offset from the instruction */
123 offset = (int16_t) (mcode & 0x0000ffff);
125 /* check for load from PV */
127 if ((mcode >> 16) == 0x81ad) {
128 /* get the final data segment address */
130 pa = ((uint8_t *) pv) + offset;
132 else if ((mcode >> 16) == 0x81ac) {
133 /* in this case we use the passed method pointer */
135 /* return NULL if no mptr was specified (used for replacement) */
140 pa = ((uint8_t *) mptr) + offset;
143 /* catch any problems */
145 vm_abort("md_jit_method_patch_address: unknown instruction %x",
148 /* keep compiler happy */
158 /* md_patch_replacement_point **************************************************
160 Patch the given replacement point.
162 *******************************************************************************/
164 #if defined(ENABLE_REPLACEMENT)
165 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
170 /* restore the patched-over instruction */
171 *(u4*)(pc) = *(u4*)(savedmcode);
174 /* save the current machine code */
175 *(u4*)(savedmcode) = *(u4*)(pc);
177 /* build the machine code for the patch */
178 assert(0); /* XXX build trap instruction below */
181 /* write the new machine code */
182 *(u4*)(pc) = (u4) mcode;
185 /* flush instruction cache */
186 md_icacheflush(pc,4);
188 #endif /* defined(ENABLE_REPLACEMENT) */
192 * These are local overrides for various environment variables in Emacs.
193 * Please do not remove this and leave it at the end of the file, where
194 * Emacs will automagically detect them.
195 * ---------------------------------------------------------------------
198 * indent-tabs-mode: t
202 * vim:noexpandtab:sw=4:ts=4: