1 /* src/vm/jit/alpha/md.c - machine dependent Alpha 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
34 #if defined(__LINUX__)
37 extern unsigned long ieee_get_fp_control();
38 extern void ieee_set_fp_control(unsigned long fp_control);
41 #include "vm/jit/alpha/codegen.h"
42 #include "vm/jit/alpha/md.h"
44 #include "vm/exceptions.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/jit.h"
50 /* global variables ***********************************************************/
52 bool has_ext_instr_set = false; /* has instruction set extensions */
55 /* md_init *********************************************************************
57 Do some machine dependent initialization.
59 *******************************************************************************/
63 #if defined(__LINUX__)
64 unsigned long int fpcw;
67 /* check for extended instruction set */
69 has_ext_instr_set = !asm_md_init();
71 #if defined(__LINUX__)
72 /* Linux on Digital Alpha needs an initialisation of the ieee
73 floating point control for IEEE compliant arithmetic (option
74 -mieee of GCC). Under Digital Unix this is done
77 /* initialize floating point control */
79 fpcw = ieee_get_fp_control();
82 & ~IEEE_TRAP_ENABLE_INV
83 & ~IEEE_TRAP_ENABLE_DZE
84 /* We dont want underflow. */
85 /* & ~IEEE_TRAP_ENABLE_UNF */
86 & ~IEEE_TRAP_ENABLE_OVF;
89 /* | IEEE_TRAP_ENABLE_INV */
90 /* | IEEE_TRAP_ENABLE_DZE */
91 /* | IEEE_TRAP_ENABLE_OVF */
92 /* | IEEE_TRAP_ENABLE_UNF */
93 /* | IEEE_TRAP_ENABLE_INE */
94 /* | IEEE_TRAP_ENABLE_DNO; */
96 ieee_set_fp_control(fpcw);
101 /* md_jit_method_patch_address *************************************************
103 Gets the patch address of the currently compiled method. The offset
104 is extracted from the load instruction(s) before the jump and added
105 to the right base address (PV or REG_METHODPTR).
107 INVOKESTATIC/SPECIAL:
109 a77bffb8 ldq pv,-72(pv)
114 a7900000 ldq at,0(a0)
115 a77c0000 ldq pv,0(at)
120 a7900000 ldq at,0(a0)
121 a79cff98 ldq at,-104(at)
122 a77c0018 ldq pv,24(at)
125 *******************************************************************************/
127 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
134 void *pa; /* patch address */
136 /* Go back to the load instruction (2 instructions). */
138 pc = ((uint32_t *) ra) - 2;
140 /* Get first instruction word. */
144 /* Get opcode, base register and displacement. */
146 opcode = M_MEM_GET_Opcode(mcode);
147 base = M_MEM_GET_Rb(mcode);
148 disp = M_MEM_GET_Memory_disp(mcode);
150 /* Check for short or long load (2 instructions). */
153 case 0x29: /* LDQ: TODO use define */
156 /* Calculate the data segment address. */
158 pa = ((uint8_t *) pv) + disp;
162 /* Return NULL if no mptr was specified (used for
168 /* Calculate the address in the vftbl. */
170 pa = ((uint8_t *) mptr) + disp;
174 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
179 case 0x09: /* LDAH: TODO use define */
180 /* XXX write a regression for this */
182 vm_abort("md_jit_method_patch_address: IMPLEMENT ME!");
188 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
196 /* md_patch_replacement_point **************************************************
198 Patch the given replacement point.
200 *******************************************************************************/
202 #if defined(ENABLE_REPLACEMENT)
203 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
208 /* restore the patched-over instruction */
209 *(u4*)(pc) = *(u4*)(savedmcode);
212 /* save the current machine code */
213 *(u4*)(savedmcode) = *(u4*)(pc);
215 /* build the machine code for the patch */
216 mcode = (0xa41f0000 | (EXCEPTION_HARDWARE_PATCHER));
218 /* write the new machine code */
222 /* flush instruction cache */
223 md_icacheflush(pc,4);
225 #endif /* defined(ENABLE_REPLACEMENT) */
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t
239 * vim:noexpandtab:sw=4:ts=4: