1 /* src/vm/jit/alpha/md.c - machine dependent Alpha functions
3 Copyright (C) 1996-2005, 2006 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
25 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
30 Changes: Joseph Wenninger
34 $Id: md.c 4673 2006-03-22 15:30:06Z edwin $
44 #if defined(__LINUX__)
47 extern unsigned long ieee_get_fp_control();
48 extern void ieee_set_fp_control(unsigned long fp_control);
53 #include "vm/jit/alpha/md-abi.h"
55 #include "vm/exceptions.h"
56 #include "vm/stringlocal.h"
57 #include "vm/jit/asmpart.h"
58 #include "vm/jit/stacktrace.h"
60 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
61 #include "vm/options.h" /* XXX debug */
62 #include "vm/jit/disass.h" /* XXX debug */
66 /* global variables ***********************************************************/
68 bool has_ext_instr_set = false; /* has instruction set extensions */
71 /* md_init *********************************************************************
73 Do some machine dependent initialization.
75 *******************************************************************************/
79 /* check for extended instruction set */
81 has_ext_instr_set = !asm_md_init();
83 #if defined(__LINUX__)
84 /* Linux on Digital Alpha needs an initialisation of the ieee
85 floating point control for IEEE compliant arithmetic (option
86 -mieee of GCC). Under Digital Unix this is done
89 /* initialize floating point control */
91 ieee_set_fp_control(ieee_get_fp_control()
92 & ~IEEE_TRAP_ENABLE_INV
93 & ~IEEE_TRAP_ENABLE_DZE
94 /* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */
95 & ~IEEE_TRAP_ENABLE_OVF);
100 /* md_stacktrace_get_returnaddress *********************************************
102 Returns the return address of the current stackframe, specified by
103 the passed stack pointer and the stack frame size.
105 *******************************************************************************/
107 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
111 /* on Alpha the return address is located on the top of the stackframe */
113 ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P));
119 /* md_assembler_get_patch_address **********************************************
121 Gets the patch address of the currently compiled method. The offset
122 is extracted from the load instruction(s) before the jump and added
123 to the right base address (PV or REG_METHODPTR).
127 a77bffb8 ldq pv,-72(pv)
132 a77c0000 ldq pv,0(at)
135 *******************************************************************************/
137 u1 *md_assembler_get_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
141 u1 *pa; /* patch address */
143 /* go back to the actual load instruction (2 instructions on Alpha) */
147 /* get first instruction word on current PC */
149 mcode = *((u4 *) ra);
151 /* check if we have 2 instructions (lui) */
153 if ((mcode >> 16) == 0x3c19) {
154 /* XXX write a regression for this */
157 /* get displacement of first instruction (lui) */
159 offset = (s4) (mcode << 16);
161 /* get displacement of second instruction (daddiu) */
163 mcode = *((u4 *) (ra + 1 * 4));
165 assert((mcode >> 16) == 0x6739);
167 offset += (s2) (mcode & 0x0000ffff);
170 /* get first instruction (ldq) */
172 mcode = *((u4 *) ra);
174 /* get the offset from the instruction */
176 offset = (s2) (mcode & 0x0000ffff);
178 /* check for call with REG_METHODPTR: ldq pv,0(at) */
180 if ((mcode >> 16) == 0xa77c) {
181 /* in this case we use the passed method pointer */
186 /* in the normal case we check for a `ldq pv,-72(pv)' instruction */
188 assert((mcode >> 16) == 0xa77b);
190 /* and get the final data segment address */
192 pa = sfi->pv + offset;
200 /* md_codegen_findmethod *******************************************************
205 277afffe ldah pv,-2(ra)
206 237ba61c lda pv,-23012(pv)
208 *******************************************************************************/
210 u1 *md_codegen_findmethod(u1 *ra)
218 /* get first instruction word after jump */
220 mcode = *((u4 *) ra);
222 /* check if we have 2 instructions (ldah, lda) */
224 if ((mcode >> 16) == 0x277a) {
225 /* get displacement of first instruction (ldah) */
227 offset = (s4) (mcode << 16);
230 /* get displacement of second instruction (lda) */
232 mcode = *((u4 *) (ra + 1 * 4));
234 assert((mcode >> 16) == 0x237b);
236 offset = (s2) (mcode & 0x0000ffff);
240 /* get displacement of first instruction (lda) */
242 assert((mcode >> 16) == 0x237a);
244 offset = (s2) (mcode & 0x0000ffff);
252 /* md_cacheflush ***************************************************************
254 Calls the system's function to flush the instruction and data
257 *******************************************************************************/
259 void md_cacheflush(u1 *addr, s4 nbytes)
261 asm_cacheflush(addr, nbytes);
265 /* md_icacheflush **************************************************************
267 Calls the system's function to flush the instruction cache.
269 *******************************************************************************/
271 void md_icacheflush(u1 *addr, s4 nbytes)
273 asm_cacheflush(addr, nbytes);
277 /* md_patch_replacement_point **************************************************
279 Patch the given replacement point.
281 *******************************************************************************/
283 void md_patch_replacement_point(rplpoint *rp)
287 /* save the current machine code */
288 mcode = *(u4*)rp->pc;
290 /* write the new machine code */
291 *(u4*)(rp->pc) = (u4) rp->mcode;
293 /* store saved mcode */
296 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
304 /* flush instruction cache */
305 md_icacheflush(rp->pc,4);
309 * These are local overrides for various environment variables in Emacs.
310 * Please do not remove this and leave it at the end of the file, where
311 * Emacs will automagically detect them.
312 * ---------------------------------------------------------------------
315 * indent-tabs-mode: t
319 * vim:noexpandtab:sw=4:ts=4: