1 /* src/vm/jit/sparc64/md.c - machine dependent SPARC64 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
33 #include "vm/jit/sparc64/md-abi.h"
35 #include "vm/jit/asmpart.h"
36 #include "vm/jit/codegen-common.hpp"
37 #include "vm/jit/jit.hpp"
40 /* assembler function prototypes **********************************************/
41 void asm_store_fp_state_reg(u8 *mem);
42 void asm_load_fp_state_reg(u8 *mem);
45 /* NOP is defined as a SETHI instruction with rd and imm. set to zero */
46 /* therefore we check if the 22-bit immediate is zero */
47 #define IS_SETHI(instr) \
48 (((instr & 0xc1c00000) == 0x01000000) \
49 && ((instr & 0x3fffff) != 0x0))
51 #define IS_LDX_IMM(instr) \
52 (((instr >> 13) & 0x60fc1) == 0x602c1)
54 #define IS_SUB(instr) \
55 (((instr >> 13) & 0x60fc0) == 0x40100)
57 inline s2 decode_13bit_imm(u4 instr) {
60 /* mask everything else in the instruction */
61 imm = instr & 0x00001fff;
63 /* sign extend 13-bit to 16-bit */
70 /* md_init *********************************************************************
72 Do some machine dependent initialization.
74 *******************************************************************************/
82 /* md_jit_method_patch_address *************************************************
84 Gets the patch address of the currently compiled method. The offset
85 is extracted from the load instruction(s) before the jump and added
86 to the right base address (PV or REG_METHODPTR).
90 ???????? ldx [i5 - 72],o5
91 ???????? jmp o5 <-- ra
94 w/ sethi (mptr in dseg out of 13-bit simm range)
96 ???????? sethi hi(0x2000),o5
98 ???????? ldx [o5 - 72],o5
99 ???????? jmp o5 <-- ra
104 ???????? ldx [o0 + 0},g2
105 ???????? ldx [g2 + 0],o5
106 ???????? jmp o5 <-- ra
111 ???????? ldx [o0 + 0},g2
112 ???????? ldx [g2 - 112],g2
113 ???????? ldx [g2 + 24],o5
114 ???????? jmp o5 <-- ra
117 *******************************************************************************/
119 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
122 uint32_t mcode, mcode_sethi, mcode_masked;
127 /* Go back to the location of a possible sethi (3 instruction
130 pc = ((uint32_t *) ra) - 3;
132 /* note: ra is the address of the jump instruction on SPARC */
136 /* check for sethi instruction */
138 if (IS_SETHI(mcode_sethi)) {
139 u4 mcode_sub, mcode_ldx;
144 /* make sure the sequence of instructions is a loadhi */
145 if ((IS_SUB(mcode_sub)) && (IS_LDX_IMM(mcode_ldx)))
149 /* get 22-bit immediate of sethi instruction */
151 disp = (int32_t) (mcode_sethi & 0x3fffff);
154 /* goto next instruction */
156 /* make sure it's a sub instruction (pv - big_disp) */
157 assert(IS_SUB(mcode_sub));
160 /* get displacement of load instruction */
162 assert(IS_LDX_IMM(mcode_ldx));
164 disp += decode_13bit_imm(mcode_ldx);
166 pa = ((uint8_t *) pv) + disp;
172 /* we didn't find a sethi, or it didn't belong to a loadhi */
173 /* check for simple (one-instruction) load */
177 /* shift and mask rd */
179 mcode_masked = (mcode >> 13) & 0x060fff;
181 /* get the offset from the instruction */
183 disp = decode_13bit_imm(mcode);
185 /* check for call with rs1 == REG_METHODPTR: ldx [g2+x],pv_caller */
187 if (mcode_masked == 0x0602c5) {
188 /* in this case we use the passed method pointer */
190 /* return NULL if no mptr was specified (used for replacement) */
195 pa = ((uint8_t *) mptr) + disp;
198 /* in the normal case we check for a `ldx [i5+x],pv_caller' instruction */
200 assert(mcode_masked == 0x0602fb);
202 /* and get the final data segment address */
204 pa = ((uint8_t *) pv) + disp;
211 /* md_patch_replacement_point **************************************************
213 Patch the given replacement point.
215 *******************************************************************************/
217 #if defined(ENABLE_REPLACEMENT)
218 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
223 /* restore the patched-over instruction */
224 *(u4*)(pc) = *(u4*)(savedmcode);
227 /* save the current machine code */
228 *(u4*)(savedmcode) = *(u4*)(pc);
230 /* build the machine code for the patch */
231 assert(0); /* XXX build trap instruction below */
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) */
244 * These are local overrides for various environment variables in Emacs.
245 * Please do not remove this and leave it at the end of the file, where
246 * Emacs will automagically detect them.
247 * ---------------------------------------------------------------------
250 * indent-tabs-mode: t
254 * vim:noexpandtab:sw=4:ts=4: