1 /* src/vm/jit/mips/md.c - machine dependent MIPS functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 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
33 #include "vm/jit/mips/md.h"
35 #include "vm/global.h"
38 #include "vm/jit/jit.hpp"
41 /* md_jit_method_patch_address *************************************************
43 Gets the patch address of the currently compiled method. The offset
44 is extracted from the load instruction(s) before the jump and added
45 to the right base address (PV or REG_METHODPTR).
49 dfdeffb8 ld s8,-72(s8)
63 df39ff90 ld t9,-112(t9)
68 *******************************************************************************/
70 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
77 /* go back to the actual load instruction (3 instructions on MIPS) */
79 pc = ((uint32_t *) ra) - 3;
81 /* get first instruction word on current PC */
85 /* check if we have 2 instructions (lui) */
87 if ((mcode >> 16) == 0x3c19) {
88 /* XXX write a regression for this */
91 /* get displacement of first instruction (lui) */
93 offset = (int32_t) (mcode << 16);
95 /* get displacement of second instruction (daddiu) */
99 assert((mcode >> 16) != 0x6739);
101 offset += (int16_t) (mcode & 0x0000ffff);
106 /* get the offset from the instruction */
108 offset = (int16_t) (mcode & 0x0000ffff);
110 /* check for call with REG_METHODPTR: ld s8,x(t9) */
112 #if SIZEOF_VOID_P == 8
113 if ((mcode >> 16) == 0xdf3e) {
115 if ((mcode >> 16) == 0x8f3e) {
117 /* in this case we use the passed method pointer */
119 /* return NULL if no mptr was specified (used for replacement) */
124 pa = ((uint8_t *) mptr) + offset;
127 /* in the normal case we check for a `ld s8,x(s8)' instruction */
129 #if SIZEOF_VOID_P == 8
130 assert((mcode >> 16) == 0xdfde);
132 assert((mcode >> 16) == 0x8fde);
135 /* and get the final data segment address */
137 pa = ((uint8_t *) pv) + offset;
146 * Decode the trap instruction at the given PC.
148 * @param trp information about trap to be filled
149 * @param sig signal number
150 * @param xpc exception PC
151 * @param es execution state of the machine
152 * @return true if trap was decoded successfully, false otherwise.
154 bool md_trap_decode(trapinfo_t* trp, int sig, void* xpc, executionstate_t* es)
156 // Get the exception-throwing instruction.
157 uint32_t mcode = *((uint32_t*) xpc);
161 // Check for valid trap instruction.
162 // TODO Check the whole instruction.
163 if (mcode == 0xec000000) {
164 trp->type = TRAP_PATCHER;
172 // Retrieve base address of instruction.
173 int32_t s1 = M_ITYPE_GET_RS(mcode);
174 uintptr_t addr = es->intregs[s1];
176 // Check for special-load.
177 if (s1 == REG_ZERO) {
178 int32_t d = M_ITYPE_GET_RT(mcode);
179 int32_t disp = M_ITYPE_GET_IMM(mcode);
181 // We use the exception type as load displacement.
183 trp->value = es->intregs[d];
187 // Check for implicit NullPointerException.
189 trp->type = TRAP_NullPointerException;
203 /* md_patch_replacement_point **************************************************
205 Patch the given replacement point.
207 *******************************************************************************/
209 #if defined(ENABLE_REPLACEMENT)
210 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
218 /* restore the patched-over instruction */
219 *(u8*)(pc) = *(u8*)(savedmcode);
222 /* save the current machine code */
223 *(u8*)(savedmcode) = *(u8*)(pc);
225 /* build the machine code for the patch */
226 assert(0); /* XXX build trap instruction below */
229 /* write the new machine code */
230 *(u8*)(pc) = mcode.both;
233 /* flush instruction cache */
234 md_icacheflush(pc,2*4);
236 #endif /* defined(ENABLE_REPLACEMENT) */
240 * These are local overrides for various environment variables in Emacs.
241 * Please do not remove this and leave it at the end of the file, where
242 * Emacs will automagically detect them.
243 * ---------------------------------------------------------------------
246 * indent-tabs-mode: t
250 * vim:noexpandtab:sw=4:ts=4: