1 /* src/vm/jit/powerpc64/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_POWERPC64_MD_H
27 #define _VM_JIT_POWERPC64_MD_H
34 #include "vm/jit/powerpc64/codegen.h"
36 #include "vm/global.h"
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/jit.h"
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 /* On PowerPC64 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 39cbffe0 addi r14,r11,-32
73 3dcbffff addis r14,r11,-1
74 39ce68b0 addi r14,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) == 0x3dcb) {
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) == 0x39ce);
103 offset += (int16_t) (mcode & 0x0000ffff);
105 else if ((mcode >> 16) == 0x39cb) {
106 /* get offset of first instruction (addi) */
108 offset = (int16_t) (mcode & 0x0000ffff);
111 vm_abort("md_codegen_get_pv_from_pc: unknown instruction %x", mcode);
113 /* keep compiler happy */
118 /* calculate PV via RA + offset */
120 void* pv = (void*) (((uintptr_t) ra) + offset);
126 /* md_cacheflush ***************************************************************
128 Calls the system's function to flush the instruction and data
131 *******************************************************************************/
133 inline static void md_cacheflush(void *addr, int nbytes)
135 asm_cacheflush(addr, nbytes);
139 /* md_icacheflush **************************************************************
141 Calls the system's function to flush the instruction cache.
143 *******************************************************************************/
145 inline static void md_icacheflush(void *addr, int nbytes)
147 asm_cacheflush(addr, nbytes);
151 /* md_dcacheflush **************************************************************
153 Calls the system's function to flush the data cache.
155 *******************************************************************************/
157 inline static void md_dcacheflush(void *addr, int nbytes)
159 asm_cacheflush(addr, nbytes);
162 #endif /* _VM_JIT_POWERPC64_MD_H */
166 * These are local overrides for various environment variables in Emacs.
167 * Please do not remove this and leave it at the end of the file, where
168 * Emacs will automagically detect them.
169 * ---------------------------------------------------------------------
172 * indent-tabs-mode: t
176 * vim:noexpandtab:sw=4:ts=4: