1 /* src/vm/jit/mips/md.c - machine dependent MIPS 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: Christian Thalinger
31 $Id: md.c 4357 2006-01-22 23:33:38Z twisti $
43 #include "toolbox/logging.h"
44 #include "vm/global.h"
45 #include "vm/jit/stacktrace.h"
48 void docacheflush(u1 *p, long bytelen)
51 long psize = sysconf(_SC_PAGESIZE);
52 p -= (long) p & (psize - 1);
53 e += psize - ((((long) e - 1) & (psize - 1)) + 1);
55 mprotect(p, bytelen, PROT_READ | PROT_WRITE | PROT_EXEC);
59 /* md_stacktrace_get_returnaddress *********************************************
61 Returns the return address of the current stackframe, specified by
62 the passed stack pointer and the stack frame size.
64 *******************************************************************************/
66 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
70 /* on MIPS the return address is located on the top of the stackframe */
72 /* XXX change this if we ever want to use 4-byte stackslots */
73 /* ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P)); */
74 ra = *((u1 **) (sp + framesize - 8));
80 /* md_assembler_get_patch_address **********************************************
82 Gets the patch address of the currently compiled method. The offset
83 is extracted from the load instruction(s) before the jump and added
84 to the right base address (PV or REG_METHODPTR).
86 *******************************************************************************/
88 u1 *md_assembler_get_patch_address(u1 *ra, stackframeinfo *sfi, u1 *mptr)
94 /* go back to the actual load instruction (3 instructions on MIPS) */
98 /* get first instruction word on current PC */
100 mcode = *((u4 *) ra);
102 /* check if we have 2 instructions (lui) */
104 if ((mcode >> 16) == 0x3c19) {
105 /* XXX write a regression for this */
108 /* get displacement of first instruction (lui) */
110 offset = (s4) (mcode << 16);
112 /* get displacement of second instruction (daddiu) */
114 mcode = *((u4 *) (ra + 1 * 4));
116 if ((mcode >> 16) != 0x6739) {
117 log_text("No `daddiu' instruction found on return address!");
121 offset += (s2) (mcode & 0x0000ffff);
124 /* get first instruction (ld) */
126 mcode = *((u4 *) ra);
128 /* get the offset from the instruction */
130 offset = (s2) (mcode & 0x0000ffff);
132 /* check for call with REG_METHODPTR: ld s8,x(t9) */
134 #if SIZEOF_VOID_P == 8
135 if ((mcode >> 16) == 0xdf3e) {
137 if ((mcode >> 16) == 0x8f3e) {
139 /* in this case we use the passed method pointer */
144 /* in the normal case we check for a `ld s8,x(s8)' instruction */
146 #if SIZEOF_VOID_P == 8
147 if ((mcode >> 16) != 0xdfde) {
149 if ((mcode >> 16) != 0x8fde) {
151 log_text("No `ld s8,x(s8)' instruction found!");
155 /* and get the final data segment address */
157 pa = sfi->pv + offset;
165 /* md_codegen_findmethod *******************************************************
171 27feff9c addiu s8,ra,-100
173 *******************************************************************************/
175 u1 *md_codegen_findmethod(u1 *ra)
181 /* get the offset of the instructions */
183 /* get first instruction word after jump */
185 mcode = *((u4 *) ra);
187 /* check if we have 2 instructions (lui, daddiu) */
189 if ((mcode >> 16) == 0x3c19) {
190 /* get displacement of first instruction (lui) */
192 offset = (s4) (mcode << 16);
194 /* get displacement of second instruction (daddiu) */
196 mcode = *((u4 *) (ra + 1 * 4));
198 #if SIZEOF_VOID_P == 8
199 if ((mcode >> 16) != 0x6739) {
201 if ((mcode >> 16) != 0x2739) {
203 log_text("No `daddiu' instruction found on return address!");
207 offset += (s2) (mcode & 0x0000ffff);
210 /* get offset of first instruction (daddiu) */
212 mcode = *((u4 *) ra);
214 #if SIZEOF_VOID_P == 8
215 if ((mcode >> 16) != 0x67fe) {
217 if ((mcode >> 16) != 0x27fe) {
219 log_text("No `daddiu s8,ra,x' instruction found on return address!");
223 offset = (s2) (mcode & 0x0000ffff);
226 /* calculate PV via RA + offset */
235 * These are local overrides for various environment variables in Emacs.
236 * Please do not remove this and leave it at the end of the file, where
237 * Emacs will automagically detect them.
238 * ---------------------------------------------------------------------
241 * indent-tabs-mode: t