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"
50 /* md_init *********************************************************************
52 Do some machine dependent initialization.
54 *******************************************************************************/
58 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do
59 a dummy allocation here to ensure that the GC is
62 #if defined(ENABLE_GC_BOEHM)
67 /* Turn off flush-to-zero */
71 n.fc_word = get_fpc_csr();
72 n.fc_struct.flush = 0;
73 set_fpc_csr(n.fc_word);
79 /* md_signal_handler_sigsegv ***************************************************
81 NullPointerException signal handler for hardware null pointer
84 *******************************************************************************/
86 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
105 _uc = (struct ucontext *) _p;
106 _mc = &_uc->uc_mcontext;
108 #if defined(__UCLIBC__)
109 _gregs = _mc->gpregs;
114 /* In glibc's ucontext.h the registers are defined as long long,
115 even for MIPS32, so we cast them. This is not the case for
118 pv = (u1 *) (ptrint) _gregs[REG_PV];
119 sp = (u1 *) (ptrint) _gregs[REG_SP];
120 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
122 #if !defined(__UCLIBC__)
123 # if ((__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) _mc->pc;
150 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
153 /* get exception-throwing instruction */
155 mcode = *((u4 *) xpc);
157 d = M_ITYPE_GET_RT(mcode);
158 s1 = M_ITYPE_GET_RS(mcode);
159 disp = M_ITYPE_GET_IMM(mcode);
161 /* check for special-load */
163 if (s1 == REG_ZERO) {
164 /* we use the exception type as load displacement */
169 if (type == EXCEPTION_HARDWARE_COMPILER) {
170 /* The XPC is the RA minus 4, because the RA points to the
171 instruction after the call. */
177 /* This is a normal NPE: addr must be NULL and the NPE-type
185 /* Handle the type. */
187 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
192 case EXCEPTION_HARDWARE_COMPILER:
194 _gregs[REG_PV] = (uintptr_t) p;
195 #if defined(__UCLIBC__)
196 _gregs[CTX_EPC] = (uintptr_t) p;
198 _mc->pc = (uintptr_t) p;
203 /* Get and set the PV from the parent Java method. */
205 pv = md_codegen_get_pv_from_pc(ra);
207 _gregs[REG_PV] = (uintptr_t) pv;
209 /* Get the exception object. */
211 p = builtin_retrieve_exception();
217 case EXCEPTION_HARDWARE_PATCHER:
219 /* We set the PC again because the cause may have changed
222 #if defined(__UCLIBC__)
223 _gregs[CTX_EPC] = (uintptr_t) xpc;
225 _mc->pc = (uintptr_t) xpc;
233 _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
234 _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
235 #if defined(__UCLIBC__)
236 _gregs[CTX_EPC] = (uintptr_t) asm_handle_exception;
238 _mc->pc = (uintptr_t) asm_handle_exception;
244 /* md_signal_handler_sigusr2 ***************************************************
248 *******************************************************************************/
250 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
255 /* md_critical_section_restart *************************************************
257 Search the critical sections tree for a matching section and set
258 the PC to the restart point, if necessary.
260 *******************************************************************************/
262 #if defined(ENABLE_THREADS)
263 void md_critical_section_restart(ucontext_t *_uc)
269 _mc = &_uc->uc_mcontext;
271 #if defined(__UCLIBC__)
272 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
274 pc = (u1 *) (ptrint) _mc->pc;
277 npc = critical_find_restart_point(pc);
280 #if defined(__UCLIBC__)
281 _mc->gpregs[CTX_EPC] = (ptrint) npc;
283 _mc->pc = (ptrint) npc;
291 * These are local overrides for various environment variables in Emacs.
292 * Please do not remove this and leave it at the end of the file, where
293 * Emacs will automagically detect them.
294 * ---------------------------------------------------------------------
297 * indent-tabs-mode: t
301 * vim:noexpandtab:sw=4:ts=4: