1 /* src/vm/jit/alpha/md.c - machine dependent Alpha 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
31 #if defined(__LINUX__)
34 extern unsigned long ieee_get_fp_control();
35 extern void ieee_set_fp_control(unsigned long fp_control);
38 #include "vm/jit/alpha/codegen.h"
39 #include "vm/jit/alpha/md.h"
41 #include "vm/jit/asmpart.h"
42 #include "vm/jit/jit.hpp"
43 #include "vm/jit/trap.h"
46 /* global variables ***********************************************************/
48 bool has_ext_instr_set = false; /* has instruction set extensions */
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
59 #if defined(__LINUX__)
60 unsigned long int fpcw;
63 /* check for extended instruction set */
65 has_ext_instr_set = !asm_md_init();
67 #if defined(__LINUX__)
68 /* Linux on Digital Alpha needs an initialisation of the ieee
69 floating point control for IEEE compliant arithmetic (option
70 -mieee of GCC). Under Digital Unix this is done
73 /* initialize floating point control */
75 fpcw = ieee_get_fp_control();
78 & ~IEEE_TRAP_ENABLE_INV
79 & ~IEEE_TRAP_ENABLE_DZE
80 /* We dont want underflow. */
81 /* & ~IEEE_TRAP_ENABLE_UNF */
82 & ~IEEE_TRAP_ENABLE_OVF;
85 /* | IEEE_TRAP_ENABLE_INV */
86 /* | IEEE_TRAP_ENABLE_DZE */
87 /* | IEEE_TRAP_ENABLE_OVF */
88 /* | IEEE_TRAP_ENABLE_UNF */
89 /* | IEEE_TRAP_ENABLE_INE */
90 /* | IEEE_TRAP_ENABLE_DNO; */
92 ieee_set_fp_control(fpcw);
97 /* md_jit_method_patch_address *************************************************
99 Gets the patch address of the currently compiled method. The offset
100 is extracted from the load instruction(s) before the jump and added
101 to the right base address (PV or REG_METHODPTR).
103 INVOKESTATIC/SPECIAL:
105 a77bffb8 ldq pv,-72(pv)
110 a7900000 ldq at,0(a0)
111 a77c0000 ldq pv,0(at)
116 a7900000 ldq at,0(a0)
117 a79cff98 ldq at,-104(at)
118 a77c0018 ldq pv,24(at)
121 *******************************************************************************/
123 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
130 void *pa; /* patch address */
132 /* Go back to the load instruction (2 instructions). */
134 pc = ((uint32_t *) ra) - 2;
136 /* Get first instruction word. */
140 /* Get opcode, base register and displacement. */
142 opcode = M_MEM_GET_Opcode(mcode);
143 base = M_MEM_GET_Rb(mcode);
144 disp = M_MEM_GET_Memory_disp(mcode);
146 /* Check for short or long load (2 instructions). */
149 case 0x29: /* LDQ: TODO use define */
152 /* Calculate the data segment address. */
154 pa = ((uint8_t *) pv) + disp;
158 /* Return NULL if no mptr was specified (used for
164 /* Calculate the address in the vftbl. */
166 pa = ((uint8_t *) mptr) + disp;
170 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
175 case 0x09: /* LDAH: TODO use define */
176 /* XXX write a regression for this */
178 vm_abort("md_jit_method_patch_address: IMPLEMENT ME!");
184 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
192 /* md_patch_replacement_point **************************************************
194 Patch the given replacement point.
196 *******************************************************************************/
198 #if defined(ENABLE_REPLACEMENT)
199 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
204 /* restore the patched-over instruction */
205 *(u4*)(pc) = *(u4*)(savedmcode);
208 /* save the current machine code */
209 *(u4*)(savedmcode) = *(u4*)(pc);
211 /* build the machine code for the patch */
212 mcode = (0xa41f0000 | (TRAP_PATCHER));
214 /* write the new machine code */
218 /* flush instruction cache */
219 md_icacheflush(pc,4);
221 #endif /* defined(ENABLE_REPLACEMENT) */
225 * These are local overrides for various environment variables in Emacs.
226 * Please do not remove this and leave it at the end of the file, where
227 * Emacs will automagically detect them.
228 * ---------------------------------------------------------------------
231 * indent-tabs-mode: t
235 * vim:noexpandtab:sw=4:ts=4: