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);
43 #include "vm/jit/alpha/codegen.h"
44 #include "vm/jit/alpha/md-abi.h"
46 #include "vm/exceptions.h"
48 #include "vm/jit/asmpart.h"
49 #include "vm/jit/codegen-common.h"
50 #include "vm/jit/jit.h"
51 #include "vm/jit/md.h"
54 /* global variables ***********************************************************/
56 bool has_ext_instr_set = false; /* has instruction set extensions */
59 /* md_init *********************************************************************
61 Do some machine dependent initialization.
63 *******************************************************************************/
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 ieee_set_fp_control(ieee_get_fp_control()
80 & ~IEEE_TRAP_ENABLE_INV
81 & ~IEEE_TRAP_ENABLE_DZE
82 /* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */
83 & ~IEEE_TRAP_ENABLE_OVF);
88 /* md_stacktrace_get_returnaddress *********************************************
90 Returns the return address of the current stackframe, specified by
91 the passed stack pointer and the stack frame size.
93 *******************************************************************************/
95 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
99 /* on Alpha the return address is located on the top of the stackframe */
101 ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P));
107 /* md_jit_method_patch_address *************************************************
109 Gets the patch address of the currently compiled method. The offset
110 is extracted from the load instruction(s) before the jump and added
111 to the right base address (PV or REG_METHODPTR).
113 INVOKESTATIC/SPECIAL:
115 a77bffb8 ldq pv,-72(pv)
120 a7900000 ldq at,0(a0)
121 a77c0000 ldq pv,0(at)
126 a7900000 ldq at,0(a0)
127 a79cff98 ldq at,-104(at)
128 a77c0018 ldq pv,24(at)
131 *******************************************************************************/
133 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
140 void *pa; /* patch address */
142 /* Go back to the load instruction (2 instructions). */
144 pc = ((uint32_t *) ra) - 2;
146 /* Get first instruction word. */
150 /* Get opcode, base register and displacement. */
152 opcode = M_MEM_GET_Opcode(mcode);
153 base = M_MEM_GET_Rb(mcode);
154 disp = M_MEM_GET_Memory_disp(mcode);
156 /* Check for short or long load (2 instructions). */
159 case 0x29: /* LDQ: TODO use define */
162 /* Calculate the data segment address. */
164 pa = ((uint8_t *) pv) + disp;
168 /* Return NULL if no mptr was specified (used for
174 /* Calculate the address in the vftbl. */
176 pa = ((uint8_t *) mptr) + disp;
180 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
185 case 0x09: /* LDAH: TODO use define */
186 /* XXX write a regression for this */
188 vm_abort("md_jit_method_patch_address: IMPLEMENT ME!");
194 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
202 /* md_codegen_get_pv_from_pc ***************************************************
207 277afffe ldah pv,-2(ra)
208 237ba61c lda pv,-23012(pv)
210 *******************************************************************************/
212 u1 *md_codegen_get_pv_from_pc(u1 *ra)
220 /* get first instruction word after jump */
222 mcode = *((u4 *) ra);
224 /* check if we have 2 instructions (ldah, lda) */
226 if ((mcode >> 16) == 0x277a) {
227 /* get displacement of first instruction (ldah) */
229 offset = (s4) (mcode << 16);
232 /* get displacement of second instruction (lda) */
234 mcode = *((u4 *) (ra + 1 * 4));
236 assert((mcode >> 16) == 0x237b);
238 offset = (s2) (mcode & 0x0000ffff);
242 /* get displacement of first instruction (lda) */
244 assert((mcode >> 16) == 0x237a);
246 offset = (s2) (mcode & 0x0000ffff);
254 /* md_cacheflush ***************************************************************
256 Calls the system's function to flush the instruction and data
259 *******************************************************************************/
261 void md_cacheflush(u1 *addr, s4 nbytes)
263 asm_cacheflush(addr, nbytes);
267 /* md_icacheflush **************************************************************
269 Calls the system's function to flush the instruction cache.
271 *******************************************************************************/
273 void md_icacheflush(u1 *addr, s4 nbytes)
275 asm_cacheflush(addr, nbytes);
279 /* md_dcacheflush **************************************************************
281 Calls the system's function to flush the data cache.
283 *******************************************************************************/
285 void md_dcacheflush(u1 *addr, s4 nbytes)
291 /* md_patch_replacement_point **************************************************
293 Patch the given replacement point.
295 *******************************************************************************/
297 #if defined(ENABLE_REPLACEMENT)
298 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
303 /* restore the patched-over instruction */
304 *(u4*)(pc) = *(u4*)(savedmcode);
307 /* save the current machine code */
308 *(u4*)(savedmcode) = *(u4*)(pc);
310 /* build the machine code for the patch */
311 mcode = (0xa41f0000 | (EXCEPTION_HARDWARE_PATCHER));
313 /* write the new machine code */
317 /* flush instruction cache */
318 md_icacheflush(pc,4);
320 #endif /* defined(ENABLE_REPLACEMENT) */
324 * These are local overrides for various environment variables in Emacs.
325 * Please do not remove this and leave it at the end of the file, where
326 * Emacs will automagically detect them.
327 * ---------------------------------------------------------------------
330 * indent-tabs-mode: t
334 * vim:noexpandtab:sw=4:ts=4: