1 /* src/vm/jit/powerpc64/md.c - machine dependent PowerPC functions
3 Copyright (C) 1996-2005, 2006, 2007, 2009
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
35 #include "vm/jit/powerpc64/codegen.h"
36 #include "vm/jit/powerpc64/md.h"
38 #include "vm/global.h"
40 #include "vm/jit/jit.hpp"
41 #include "vm/jit/trap.hpp"
44 /* md_init *********************************************************************
46 Do some machine dependent initialization.
48 *******************************************************************************/
56 /* md_jit_method_patch_address *************************************************
58 Gets the patch address of the currently compiled method. The offset
59 is extracted from the load instruction(s) before the jump and added
60 to the right base address (PV or REG_METHODPTR).
64 e9ceffb8 ld r14,-72(r14)
70 FIXME 81830000 lwz r12,0(r3)
71 e9cc0000 ld r14,0(r12)
78 FIXME 81830000 lwz r12,0(r3)
79 FIXME 818c0000 lwz r12,0(r12)
80 FIXME 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) == 0xe9ce) {
128 /* get the final data segment address */
130 pa = ((uint8_t *) pv) + offset;
132 else if ((mcode >> 16) == 0xe9cc) {
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 */
159 * Decode the trap instruction at the given PC.
161 * @param trp information about trap to be filled
162 * @param sig signal number
163 * @param xpc exception PC
164 * @param es execution state of the machine
165 * @return true if trap was decoded successfully, false otherwise.
167 bool md_trap_decode(trapinfo_t* trp, int sig, void* xpc, executionstate_t* es)
169 // Get the throwing instruction.
170 uint32_t mcode = *((uint32_t*) xpc);
174 // Check for valid trap instruction.
175 if (mcode == 0x00000000) {
176 trp->type = TRAP_PATCHER;
184 // Decode the throwing instruction.
185 int s1 = M_INSTR_OP2_IMM_A(mcode);
186 int16_t disp = M_INSTR_OP2_IMM_I(mcode);
187 int d = M_INSTR_OP2_IMM_D(mcode);
189 // We use the exception type as load displacement.
190 if (s1 == REG_ZERO) {
192 trp->value = es->intregs[d];
196 // Default case is a normal NullPointerException.
197 if (es->intregs[s1] == 0) {
198 trp->type = TRAP_NullPointerException;
212 /* md_patch_replacement_point **************************************************
214 Patch the given replacement point.
216 *******************************************************************************/
218 #if defined(ENABLE_REPLACEMENT)
219 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
224 /* restore the patched-over instruction */
225 *(u4*)(pc) = *(u4*)(savedmcode);
228 /* save the current machine code */
229 *(u4*)(savedmcode) = *(u4*)(pc);
231 /* build the machine code for the patch */
232 mcode = (0x80000000 | TRAP_PATCHER);
234 /* write the new machine code */
235 *(u4*)(pc) = (u4) mcode;
238 /* flush instruction cache */
239 md_icacheflush(pc,4);
241 #endif /* defined(ENABLE_REPLACEMENT) */
245 * These are local overrides for various environment variables in Emacs.
246 * Please do not remove this and leave it at the end of the file, where
247 * Emacs will automagically detect them.
248 * ---------------------------------------------------------------------
251 * indent-tabs-mode: t
255 * vim:noexpandtab:sw=4:ts=4: