1 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux 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
29 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
36 #include "vm/jit/mips/codegen.h"
37 #include "vm/jit/mips/md.h"
38 #include "vm/jit/mips/md-abi.h"
40 #include "mm/gc-common.h"
41 #include "mm/memory.h"
43 #include "vm/exceptions.h"
44 #include "vm/signallocal.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/stacktrace.h"
48 #include "vm/jit/trap.h"
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
59 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do
60 a dummy allocation here to ensure that the GC is
63 #if defined(ENABLE_GC_BOEHM)
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);
80 /* md_signal_handler_sigsegv ***************************************************
82 NullPointerException signal handler for hardware null pointer
85 *******************************************************************************/
87 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
106 _uc = (struct ucontext *) _p;
107 _mc = &_uc->uc_mcontext;
109 #if defined(__UCLIBC__)
110 _gregs = _mc->gpregs;
115 /* In glibc's ucontext.h the registers are defined as long long,
116 even for MIPS32, so we cast them. This is not the case for
119 pv = (u1 *) (ptrint) _gregs[REG_PV];
120 sp = (u1 *) (ptrint) _gregs[REG_SP];
121 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
123 #if !defined(__UCLIBC__) && ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
124 /* NOTE: We only need this for pre glibc-2.5. */
126 xpc = (u1 *) (ptrint) _mc->pc;
128 /* get the cause of this exception */
132 /* check the cause to find the faulting instruction */
134 /* TODO: use defines for that stuff */
136 switch (cause & 0x0000003c) {
138 /* TLBL: XPC is ok */
142 /* AdEL: XPC is of the following instruction */
147 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
150 /* get exception-throwing instruction */
152 mcode = *((u4 *) xpc);
154 d = M_ITYPE_GET_RT(mcode);
155 s1 = M_ITYPE_GET_RS(mcode);
156 disp = M_ITYPE_GET_IMM(mcode);
158 /* check for special-load */
160 if (s1 == REG_ZERO) {
161 /* we use the exception type as load displacement */
166 if (type == TRAP_COMPILER) {
167 /* The XPC is the RA minus 4, because the RA points to the
168 instruction after the call. */
174 /* This is a normal NPE: addr must be NULL and the NPE-type
182 /* Handle the trap. */
184 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
191 _gregs[REG_PV] = (uintptr_t) p;
192 #if defined(__UCLIBC__)
193 _gregs[CTX_EPC] = (uintptr_t) p;
195 _mc->pc = (uintptr_t) p;
200 /* Get and set the PV from the parent Java method. */
202 pv = md_codegen_get_pv_from_pc(ra);
204 _gregs[REG_PV] = (uintptr_t) pv;
206 /* Get the exception object. */
208 p = builtin_retrieve_exception();
216 /* We set the PC again because the cause may have changed
219 #if defined(__UCLIBC__)
220 _gregs[CTX_EPC] = (uintptr_t) xpc;
222 _mc->pc = (uintptr_t) xpc;
230 _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
231 _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
232 #if defined(__UCLIBC__)
233 _gregs[CTX_EPC] = (uintptr_t) asm_handle_exception;
235 _mc->pc = (uintptr_t) asm_handle_exception;
241 /* md_signal_handler_sigusr2 ***************************************************
245 *******************************************************************************/
247 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
252 /* md_critical_section_restart *************************************************
254 Search the critical sections tree for a matching section and set
255 the PC to the restart point, if necessary.
257 *******************************************************************************/
259 #if defined(ENABLE_THREADS)
260 void md_critical_section_restart(ucontext_t *_uc)
266 _mc = &_uc->uc_mcontext;
268 #if defined(__UCLIBC__)
269 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
271 pc = (u1 *) (ptrint) _mc->pc;
274 npc = critical_find_restart_point(pc);
277 #if defined(__UCLIBC__)
278 _mc->gpregs[CTX_EPC] = (ptrint) npc;
280 _mc->pc = (ptrint) npc;
288 * These are local overrides for various environment variables in Emacs.
289 * Please do not remove this and leave it at the end of the file, where
290 * Emacs will automagically detect them.
291 * ---------------------------------------------------------------------
294 * indent-tabs-mode: t
298 * vim:noexpandtab:sw=4:ts=4: