1 /* src/vm/jit/mips/md.c - machine dependent MIPS functions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
32 $Id: md.c 3112 2005-07-27 10:35:06Z twisti $
45 #include "vm/jit/mips/md-abi.h"
46 #include "vm/jit/mips/types.h"
48 #include "vm/exceptions.h"
49 #include "vm/stringlocal.h"
50 #include "vm/jit/asmpart.h"
51 #include "vm/jit/stacktrace.h"
54 /* md_init *********************************************************************
56 Do some machine dependent initialization.
58 *******************************************************************************/
62 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
63 /* dummy allocation here to ensure that the GC is initialized. */
65 heap_allocate(1, 0, NULL);
68 /* Turn off flush-to-zero */
72 n.fc_word = get_fpc_csr();
73 n.fc_struct.flush = 0;
74 set_fpc_csr(n.fc_word);
79 /* signal_handler_sigsegv ******************************************************
81 NullPointerException signal handler for hardware null pointer check.
83 *******************************************************************************/
85 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
96 _uc = (struct ucontext *) _p;
97 _mc = &_uc->uc_mcontext;
99 instr = *((u4 *) (_mc->gregs[CTX_EPC]));
100 addr = _mc->gregs[(instr >> 21) & 0x1f];
103 pv = (u1 *) _mc->gregs[REG_PV];
104 sp = (u1 *) _mc->gregs[REG_SP];
105 ra = (functionptr) _mc->gregs[REG_RA]; /* this is correct for leafs*/
106 xpc = (functionptr) _mc->gregs[CTX_EPC];
108 _mc->gregs[REG_ITMP1_XPTR] =
109 (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
111 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
112 _mc->gregs[CTX_EPC] = (ptrint) asm_handle_exception;
115 addr += (long) ((instr << 16) >> 16);
117 throw_cacao_exception_exit(string_java_lang_InternalError,
118 "faulting address: 0x%lx at 0x%lx\n",
119 addr, _mc->gregs[CTX_EPC]);
124 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
125 void thread_restartcriticalsection(ucontext_t *uc)
129 critical = thread_checkcritical((void*) uc->uc_mcontext.gregs[CTX_EPC]);
132 uc->uc_mcontext.gregs[CTX_EPC] = (ptrint) critical;
137 void docacheflush(u1 *p, long bytelen)
140 long psize = sysconf(_SC_PAGESIZE);
141 p -= (long) p & (psize - 1);
142 e += psize - ((((long) e - 1) & (psize - 1)) + 1);
144 mprotect(p, bytelen, PROT_READ | PROT_WRITE | PROT_EXEC);
148 /* md_stacktrace_get_returnaddress *********************************************
150 Returns the return address of the current stackframe, specified by
151 the passed stack pointer and the stack frame size.
153 *******************************************************************************/
155 functionptr md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
159 /* on MIPS the return address is located on the top of the stackframe */
161 ra = (functionptr) *((u1 **) (sp + framesize - SIZEOF_VOID_P));
167 /* codegen_findmethod **********************************************************
172 237affe8 lda pv,-24(ra)
174 *******************************************************************************/
176 functionptr codegen_findmethod(functionptr pc)
186 /* get first instruction word after jump */
188 mcode = *((u4 *) ra);
190 /* check if we have 2 instructions (ldah, lda) */
192 if ((mcode >> 16) == 0x3c19) {
193 /* get displacement of first instruction (lui) */
195 offset = (s4) (mcode << 16);
198 /* get displacement of second instruction (daddiu) */
200 mcode = *((u4 *) (ra + 1 * 4));
202 if ((mcode >> 16) != 0x6739) {
203 log_text("No `daddiu' instruction found on return address!");
207 offset = (s2) (mcode & 0x0000ffff);
211 /* get offset of first instruction (daddiu) */
213 mcode = *((u4 *) ra);
215 if ((mcode >> 16) != 0x67fe) {
216 log_text("No `daddiu s8,ra,x' instruction found on return address!");
220 offset = (s2) (mcode & 0x0000ffff);
224 return (functionptr) pv;
229 * These are local overrides for various environment variables in Emacs.
230 * Please do not remove this and leave it at the end of the file, where
231 * Emacs will automagically detect them.
232 * ---------------------------------------------------------------------
235 * indent-tabs-mode: t