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 4817 2006-04-23 23:03:50Z twisti $
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_get_method_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).
125 INVOKESTATIC/SPECIAL:
127 a77bffb8 ldq pv,-72(pv)
132 a7900000 ldq at,0(a0)
133 a77c0000 ldq pv,0(at)
138 a7900000 ldq at,0(a0)
139 a79cff98 ldq at,-104(at)
140 a77c0018 ldq pv,24(at)
143 *******************************************************************************/
145 u1 *md_get_method_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
149 u1 *pa; /* patch address */
151 /* go back to the actual load instruction (2 instructions on Alpha) */
155 /* get first instruction word on current PC */
157 mcode = *((u4 *) ra);
159 /* check if we have 2 instructions (lui) */
161 if ((mcode >> 16) == 0x3c19) {
162 /* XXX write a regression for this */
165 /* get displacement of first instruction (lui) */
167 offset = (s4) (mcode << 16);
169 /* get displacement of second instruction (daddiu) */
171 mcode = *((u4 *) (ra + 1 * 4));
173 assert((mcode >> 16) == 0x6739);
175 offset += (s2) (mcode & 0x0000ffff);
178 /* get first instruction (ldq) */
180 mcode = *((u4 *) ra);
182 /* get the offset from the instruction */
184 offset = (s2) (mcode & 0x0000ffff);
186 /* check for call with REG_METHODPTR: ldq pv,0(at) */
188 if ((mcode >> 16) == 0xa77c) {
189 /* in this case we use the passed method pointer */
194 /* in the normal case we check for a `ldq pv,-72(pv)' instruction */
196 assert((mcode >> 16) == 0xa77b);
198 /* and get the final data segment address */
200 pa = sfi->pv + offset;
208 /* md_codegen_findmethod *******************************************************
213 277afffe ldah pv,-2(ra)
214 237ba61c lda pv,-23012(pv)
216 *******************************************************************************/
218 u1 *md_codegen_findmethod(u1 *ra)
226 /* get first instruction word after jump */
228 mcode = *((u4 *) ra);
230 /* check if we have 2 instructions (ldah, lda) */
232 if ((mcode >> 16) == 0x277a) {
233 /* get displacement of first instruction (ldah) */
235 offset = (s4) (mcode << 16);
238 /* get displacement of second instruction (lda) */
240 mcode = *((u4 *) (ra + 1 * 4));
242 assert((mcode >> 16) == 0x237b);
244 offset = (s2) (mcode & 0x0000ffff);
248 /* get displacement of first instruction (lda) */
250 assert((mcode >> 16) == 0x237a);
252 offset = (s2) (mcode & 0x0000ffff);
260 /* md_cacheflush ***************************************************************
262 Calls the system's function to flush the instruction and data
265 *******************************************************************************/
267 void md_cacheflush(u1 *addr, s4 nbytes)
269 asm_cacheflush(addr, nbytes);
273 /* md_icacheflush **************************************************************
275 Calls the system's function to flush the instruction cache.
277 *******************************************************************************/
279 void md_icacheflush(u1 *addr, s4 nbytes)
281 asm_cacheflush(addr, nbytes);
285 /* md_patch_replacement_point **************************************************
287 Patch the given replacement point.
289 *******************************************************************************/
291 void md_patch_replacement_point(rplpoint *rp)
295 /* save the current machine code */
296 mcode = *(u4*)rp->pc;
298 /* write the new machine code */
299 *(u4*)(rp->pc) = (u4) rp->mcode;
301 /* store saved mcode */
304 #if !defined(NDEBUG) && defined(ENABLE_DISASSEMBLER)
312 /* flush instruction cache */
313 md_icacheflush(rp->pc,4);
317 * These are local overrides for various environment variables in Emacs.
318 * Please do not remove this and leave it at the end of the file, where
319 * Emacs will automagically detect them.
320 * ---------------------------------------------------------------------
323 * indent-tabs-mode: t
327 * vim:noexpandtab:sw=4:ts=4: