1 /* src/vm/jit/powerpc64/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
37 #include "vm/jit/powerpc64/codegen.h"
38 #include "vm/jit/powerpc64/md.h"
40 #include "vm/exceptions.h"
41 #include "vm/global.h"
43 #include "vm/jit/jit.h"
46 /* md_init *********************************************************************
48 Do some machine dependent initialization.
50 *******************************************************************************/
58 /* md_jit_method_patch_address *************************************************
60 Gets the patch address of the currently compiled method. The offset
61 is extracted from the load instruction(s) before the jump and added
62 to the right base address (PV or REG_METHODPTR).
66 e9ceffb8 ld r14,-72(r14)
72 FIXME 81830000 lwz r12,0(r3)
73 e9cc0000 ld r14,0(r12)
80 FIXME 81830000 lwz r12,0(r3)
81 FIXME 818c0000 lwz r12,0(r12)
82 FIXME 81ac0000 lwz r13,0(r12)
86 *******************************************************************************/
88 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
95 /* Go back to the actual load instruction (3 instructions). */
97 pc = ((uint32_t *) ra) - 3;
99 /* get first instruction word (lwz) */
103 /* check if we have 2 instructions (addis, addi) */
105 if ((mcode >> 16) == 0x3c19) {
106 /* XXX write a regression for this */
110 /* get displacement of first instruction (addis) */
112 offset = (int32_t) (mcode << 16);
114 /* get displacement of second instruction (addi) */
118 assert((mcode >> 16) != 0x6739);
120 offset += (int16_t) (mcode & 0x0000ffff);
123 /* get the offset from the instruction */
125 offset = (int16_t) (mcode & 0x0000ffff);
127 /* check for load from PV */
129 if ((mcode >> 16) == 0xe9ce) {
130 /* get the final data segment address */
132 pa = ((uint8_t *) pv) + offset;
134 else if ((mcode >> 16) == 0xe9cc) {
135 /* in this case we use the passed method pointer */
137 /* return NULL if no mptr was specified (used for replacement) */
142 pa = ((uint8_t *) mptr) + offset;
145 /* catch any problems */
147 vm_abort("md_jit_method_patch_address: unknown instruction %x",
150 /* keep compiler happy */
160 /* md_patch_replacement_point **************************************************
162 Patch the given replacement point.
164 *******************************************************************************/
166 #if defined(ENABLE_REPLACEMENT)
167 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
172 /* restore the patched-over instruction */
173 *(u4*)(pc) = *(u4*)(savedmcode);
176 /* save the current machine code */
177 *(u4*)(savedmcode) = *(u4*)(pc);
179 /* build the machine code for the patch */
180 mcode = (0x80000000 | (EXCEPTION_HARDWARE_PATCHER));
182 /* write the new machine code */
183 *(u4*)(pc) = (u4) mcode;
186 /* flush instruction cache */
187 md_icacheflush(pc,4);
189 #endif /* defined(ENABLE_REPLACEMENT) */
193 * These are local overrides for various environment variables in Emacs.
194 * Please do not remove this and leave it at the end of the file, where
195 * Emacs will automagically detect them.
196 * ---------------------------------------------------------------------
199 * indent-tabs-mode: t
203 * vim:noexpandtab:sw=4:ts=4: