1 /* src/vm/jit/sparc64/md.c - machine dependent SPARC64 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
28 #ifndef _VM_JIT_SPARC64_MD_H
29 #define _VM_JIT_SPARC64_MD_H
38 #include "vm/jit/codegen-common.h"
41 /* md_stacktrace_get_returnaddress *********************************************
43 Returns the return address of the current stackframe, specified by
44 the passed stack pointer and the stack frame size.
46 *******************************************************************************/
48 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
52 /* flush register windows to the stack */
55 /* the return address resides in register i7, the last register in the
56 * 16-extended-word save area
58 ra = *((void **) (((uintptr_t) sp) + 120 + BIAS));
60 /* NOTE: on SPARC ra is the address of the call instruction */
65 inline static void *md_get_framepointer(void *sp)
69 /* flush register windows to the stack */
72 fp = *((void **) (((uintptr_t) sp) + 112 + BIAS));
77 inline static void *md_get_pv_from_stackframe(void *sp)
81 /* flush register windows to the stack */
84 pv = *((void **) (((uintptr_t) sp) + 104 + BIAS));
90 /* md_codegen_get_pv_from_pc ***************************************************
92 This reconstructs and returns the PV of a method given a return address
93 pointer. (basically, same was as the generated code following the jump does)
99 277afffe ldah pv,-2(ra)
100 237ba61c lda pv,-23012(pv)
102 *******************************************************************************/
104 /* TODO Move these macros into the code generator. */
106 /* shift away 13-bit immediate, mask rd and rs1 */
107 #define SHIFT_AND_MASK(instr) \
108 ((instr >> 13) & 0x60fc1)
110 /* NOP is defined as a SETHI instruction with rd and imm. set to zero */
111 /* therefore we check if the 22-bit immediate is zero */
112 #define IS_SETHI(instr) \
113 (((instr & 0xc1c00000) == 0x01000000) \
114 && ((instr & 0x3fffff) != 0x0))
116 inline s2 decode_13bit_imm(u4 instr) {
119 /* mask everything else in the instruction */
120 imm = instr & 0x00001fff;
122 /* sign extend 13-bit to 16-bit */
129 inline static void *md_codegen_get_pv_from_pc(void *ra)
137 /* get the instruction word after jump and nop */
138 mcode = *((u4 *) (ra+8) );
140 /* check if we have a sethi insruction */
141 if (IS_SETHI(mcode)) {
144 /* get 22-bit immediate of sethi instruction */
145 offset = (s4) (mcode & 0x3fffff);
146 offset = offset << 10;
149 mcode = *((u4 *) (ra+12) );
150 xor_imm = decode_13bit_imm(mcode);
157 mcode_masked = SHIFT_AND_MASK(mcode);
159 assert(mcode_masked == 0x40001);
161 /* mask and extend the negative sign for the 13 bit immediate */
162 offset = decode_13bit_imm(mcode);
171 /* md_cacheflush ***************************************************************
173 Calls the system's function to flush the instruction and data
176 *******************************************************************************/
178 inline static void md_cacheflush(void *addr, int nbytes)
184 /* md_dcacheflush **************************************************************
186 Calls the system's function to flush the data cache.
188 *******************************************************************************/
190 inline static void md_dcacheflush(void *addr, int nbytes)
192 /* XXX don't know yet */
193 /* printf("md_dcacheflush\n"); */
194 __asm__ __volatile__ ( "membar 0x7F" : : : "memory" );
197 #endif /* _VM_JIT_SPARC64_MD_H */
201 * These are local overrides for various environment variables in Emacs.
202 * Please do not remove this and leave it at the end of the file, where
203 * Emacs will automagically detect them.
204 * ---------------------------------------------------------------------
207 * indent-tabs-mode: t
211 * vim:noexpandtab:sw=4:ts=4: