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 #if defined(__LINUX__)
68 unsigned long int fpcw;
71 /* check for extended instruction set */
73 has_ext_instr_set = !asm_md_init();
75 #if defined(__LINUX__)
76 /* Linux on Digital Alpha needs an initialisation of the ieee
77 floating point control for IEEE compliant arithmetic (option
78 -mieee of GCC). Under Digital Unix this is done
81 /* initialize floating point control */
83 fpcw = ieee_get_fp_control();
86 & ~IEEE_TRAP_ENABLE_INV
87 & ~IEEE_TRAP_ENABLE_DZE
88 /* We dont want underflow. */
89 /* & ~IEEE_TRAP_ENABLE_UNF */
90 & ~IEEE_TRAP_ENABLE_OVF;
93 /* | IEEE_TRAP_ENABLE_INV */
94 /* | IEEE_TRAP_ENABLE_DZE */
95 /* | IEEE_TRAP_ENABLE_OVF */
96 /* | IEEE_TRAP_ENABLE_UNF */
97 /* | IEEE_TRAP_ENABLE_INE */
98 /* | IEEE_TRAP_ENABLE_DNO; */
100 ieee_set_fp_control(fpcw);
105 /* md_stacktrace_get_returnaddress *********************************************
107 Returns the return address of the current stackframe, specified by
108 the passed stack pointer and the stack frame size.
110 *******************************************************************************/
112 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
116 /* on Alpha the return address is located on the top of the stackframe */
118 ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P));
124 /* md_jit_method_patch_address *************************************************
126 Gets the patch address of the currently compiled method. The offset
127 is extracted from the load instruction(s) before the jump and added
128 to the right base address (PV or REG_METHODPTR).
130 INVOKESTATIC/SPECIAL:
132 a77bffb8 ldq pv,-72(pv)
137 a7900000 ldq at,0(a0)
138 a77c0000 ldq pv,0(at)
143 a7900000 ldq at,0(a0)
144 a79cff98 ldq at,-104(at)
145 a77c0018 ldq pv,24(at)
148 *******************************************************************************/
150 void *md_jit_method_patch_address(void *pv, void *ra, void *mptr)
157 void *pa; /* patch address */
159 /* Go back to the load instruction (2 instructions). */
161 pc = ((uint32_t *) ra) - 2;
163 /* Get first instruction word. */
167 /* Get opcode, base register and displacement. */
169 opcode = M_MEM_GET_Opcode(mcode);
170 base = M_MEM_GET_Rb(mcode);
171 disp = M_MEM_GET_Memory_disp(mcode);
173 /* Check for short or long load (2 instructions). */
176 case 0x29: /* LDQ: TODO use define */
179 /* Calculate the data segment address. */
181 pa = ((uint8_t *) pv) + disp;
185 /* Return NULL if no mptr was specified (used for
191 /* Calculate the address in the vftbl. */
193 pa = ((uint8_t *) mptr) + disp;
197 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
202 case 0x09: /* LDAH: TODO use define */
203 /* XXX write a regression for this */
205 vm_abort("md_jit_method_patch_address: IMPLEMENT ME!");
211 vm_abort_disassemble(pc, 2, "md_jit_method_patch_address: unknown instruction %x", mcode);
219 /* md_codegen_get_pv_from_pc ***************************************************
224 277afffe ldah pv,-2(ra)
225 237ba61c lda pv,-23012(pv)
227 *******************************************************************************/
229 u1 *md_codegen_get_pv_from_pc(u1 *ra)
237 pc = (uint32_t *) ra;
239 /* Get first instruction word after jump. */
243 /* Get opcode and displacement. */
245 opcode = M_MEM_GET_Opcode(mcode);
246 disp = M_MEM_GET_Memory_disp(mcode);
248 /* Check for short or long load (2 instructions). */
251 case 0x08: /* LDA: TODO use define */
252 assert((mcode >> 16) == 0x237a);
254 pv = ((uint8_t *) pc) + disp;
257 case 0x09: /* LDAH: TODO use define */
258 pv = ((uint8_t *) pc) + (disp << 16);
260 /* Get displacement of second instruction (LDA). */
264 assert((mcode >> 16) == 0x237b);
266 disp = M_MEM_GET_Memory_disp(mcode);
268 pv = ((uint8_t *) pv) + disp;
272 vm_abort_disassemble(pc, 2, "md_codegen_get_pv_from_pc: unknown instruction %x", mcode);
280 /* md_cacheflush ***************************************************************
282 Calls the system's function to flush the instruction and data
285 *******************************************************************************/
287 void md_cacheflush(u1 *addr, s4 nbytes)
289 asm_cacheflush(addr, nbytes);
293 /* md_icacheflush **************************************************************
295 Calls the system's function to flush the instruction cache.
297 *******************************************************************************/
299 void md_icacheflush(u1 *addr, s4 nbytes)
301 asm_cacheflush(addr, nbytes);
305 /* md_dcacheflush **************************************************************
307 Calls the system's function to flush the data cache.
309 *******************************************************************************/
311 void md_dcacheflush(u1 *addr, s4 nbytes)
317 /* md_patch_replacement_point **************************************************
319 Patch the given replacement point.
321 *******************************************************************************/
323 #if defined(ENABLE_REPLACEMENT)
324 void md_patch_replacement_point(u1 *pc, u1 *savedmcode, bool revert)
329 /* restore the patched-over instruction */
330 *(u4*)(pc) = *(u4*)(savedmcode);
333 /* save the current machine code */
334 *(u4*)(savedmcode) = *(u4*)(pc);
336 /* build the machine code for the patch */
337 mcode = (0xa41f0000 | (EXCEPTION_HARDWARE_PATCHER));
339 /* write the new machine code */
343 /* flush instruction cache */
344 md_icacheflush(pc,4);
346 #endif /* defined(ENABLE_REPLACEMENT) */
350 * These are local overrides for various environment variables in Emacs.
351 * Please do not remove this and leave it at the end of the file, where
352 * Emacs will automagically detect them.
353 * ---------------------------------------------------------------------
356 * indent-tabs-mode: t
360 * vim:noexpandtab:sw=4:ts=4: