1 /* src/vm/jit/powerpc/md.h - machine dependent PowerPC functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #ifndef _VM_JIT_POWERPC_MD_H
27 #define _VM_JIT_POWERPC_MD_H
34 #include "vm/jit/powerpc/codegen.h"
36 #include "vm/global.h"
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/codegen-common.hpp"
43 /* md_stacktrace_get_returnaddress *********************************************
45 Returns the return address of the current stackframe, specified by
46 the passed stack pointer and the stack frame size.
48 *******************************************************************************/
50 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
54 /* Pn PowerPC the return address is located in the linkage
57 ra = *((void **) (((uintptr_t) sp) + stackframesize + LA_LR_OFFSET));
63 /* md_codegen_get_pv_from_pc ***************************************************
68 39abffe0 addi r13,r11,-32
73 3dabffff addis r13,r11,-1
74 39ad68b0 addi r13,r13,26800
76 *******************************************************************************/
78 inline static void* md_codegen_get_pv_from_pc(void* ra)
82 uint32_t* pc = (uint32_t*) ra;
84 /* get first instruction word after jump */
86 uint32_t mcode = pc[1];
88 /* check if we have 2 instructions (addis, addi) */
90 if ((mcode >> 16) == 0x3dab) {
91 /* get displacement of first instruction (addis) */
93 offset = (int32_t) (mcode << 16);
95 /* get displacement of second instruction (addi) */
99 /* check for addi instruction */
101 assert((mcode >> 16) == 0x39ad);
103 offset += (int16_t) (mcode & 0x0000ffff);
106 /* check for addi instruction */
108 assert((mcode >> 16) == 0x39ab);
110 /* get offset of first instruction (addi) */
112 offset = (int16_t) (mcode & 0x0000ffff);
115 /* calculate PV via RA + offset */
117 void* pv = (void*) (((uintptr_t) ra) + offset);
123 /* md_cacheflush ***************************************************************
125 Calls the system's function to flush the instruction and data
128 *******************************************************************************/
130 inline static void md_cacheflush(void *addr, int nbytes)
132 asm_cacheflush(addr, nbytes);
136 /* md_icacheflush **************************************************************
138 Calls the system's function to flush the instruction cache.
140 *******************************************************************************/
142 inline static void md_icacheflush(void *addr, int nbytes)
144 asm_cacheflush(addr, nbytes);
148 /* md_dcacheflush **************************************************************
150 Calls the system's function to flush the data cache.
152 *******************************************************************************/
154 inline static void md_dcacheflush(void *addr, int nbytes)
156 asm_cacheflush(addr, nbytes);
159 #endif /* _VM_JIT_POWERPC_MD_H */
163 * These are local overrides for various environment variables in Emacs.
164 * Please do not remove this and leave it at the end of the file, where
165 * Emacs will automagically detect them.
166 * ---------------------------------------------------------------------
169 * indent-tabs-mode: t
173 * vim:noexpandtab:sw=4:ts=4: