1 /* src/vm/jit/mips/md.h - machine dependent MIPS 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_MIPS_MD_H
27 #define _VM_JIT_MIPS_MD_H
33 #include <sys/cachectl.h>
35 #include "vm/global.h"
38 #include "vm/jit/asmpart.h"
39 #include "vm/jit/codegen-common.hpp"
42 * Returns the size (in bytes) of the current stackframe, specified by
43 * the passed codeinfo structure.
45 inline static int32_t md_stacktrace_get_framesize(codeinfo* code)
47 // Check for the asm_vm_call_method special case.
51 // On MIPS we use 8-byte stackslots.
52 return code->stackframesize * 8;
56 /* md_stacktrace_get_returnaddress *********************************************
58 Returns the return address of the current stackframe, specified by
59 the passed stack pointer and the stack frame size.
61 *******************************************************************************/
63 inline static void *md_stacktrace_get_returnaddress(void *sp, int32_t stackframesize)
67 /* On MIPS the return address is located on the top of the
70 ra = *((void **) (((uintptr_t) sp) + stackframesize - 8));
76 /* md_codegen_get_pv_from_pc ***************************************************
82 27feff9c addiu s8,ra,-100
84 *******************************************************************************/
86 inline static void* md_codegen_get_pv_from_pc(void* ra)
90 uint32_t* pc = (uint32_t*) ra;
92 /* get the offset of the instructions */
94 /* get first instruction word after jump */
96 uint32_t mcode = pc[0];
98 /* check if we have 2 instructions (lui, daddiu) */
100 if ((mcode >> 16) == 0x3c19) {
101 /* get displacement of first instruction (lui) */
103 offset = (int32_t) (mcode << 16);
105 /* get displacement of second instruction (daddiu) */
109 #if SIZEOF_VOID_P == 8
110 assert((mcode >> 16) == 0x6739);
112 assert((mcode >> 16) == 0x2739);
115 offset += (int16_t) (mcode & 0x0000ffff);
118 /* get offset of first instruction (daddiu) */
120 #if SIZEOF_VOID_P == 8
121 assert((mcode >> 16) == 0x67fe);
123 assert((mcode >> 16) == 0x27fe);
126 offset = (int16_t) (mcode & 0x0000ffff);
129 /* calculate PV via RA + offset */
131 void* pv = (void*) (((uintptr_t) ra) + offset);
137 /* md_cacheflush ***************************************************************
139 Calls the system's function to flush the instruction and data
142 *******************************************************************************/
144 inline static void md_cacheflush(void *addr, int nbytes)
146 cacheflush(addr, nbytes, BCACHE);
150 /* md_icacheflush **************************************************************
152 Calls the system's function to flush the instruction cache.
154 *******************************************************************************/
156 inline static void md_icacheflush(void *addr, int nbytes)
158 cacheflush(addr, nbytes, ICACHE);
162 /* md_dcacheflush **************************************************************
164 Calls the system's function to flush the data cache.
166 *******************************************************************************/
168 inline static void md_dcacheflush(void *addr, int nbytes)
170 cacheflush(addr, nbytes, DCACHE);
173 #endif /* _VM_JIT_MIPS_MD_H */
177 * These are local overrides for various environment variables in Emacs.
178 * Please do not remove this and leave it at the end of the file, where
179 * Emacs will automagically detect them.
180 * ---------------------------------------------------------------------
183 * indent-tabs-mode: t
187 * vim:noexpandtab:sw=4:ts=4: