1 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
3 Copyright (C) 1996-2005, 2006, 2007 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
31 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
38 #include "vm/jit/mips/codegen.h"
39 #include "vm/jit/mips/md-abi.h"
41 #include "mm/gc-common.h"
43 #include "vm/signallocal.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/stacktrace.h"
49 /* md_init *********************************************************************
51 Do some machine dependent initialization.
53 *******************************************************************************/
57 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
58 /* dummy allocation here to ensure that the GC is initialized. */
60 #if defined(ENABLE_GC_BOEHM)
65 /* Turn off flush-to-zero */
69 n.fc_word = get_fpc_csr();
70 n.fc_struct.flush = 0;
71 set_fpc_csr(n.fc_word);
77 /* md_signal_handler_sigsegv ***************************************************
79 NullPointerException signal handler for hardware null pointer
82 *******************************************************************************/
84 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
104 _uc = (struct ucontext *) _p;
105 _mc = &_uc->uc_mcontext;
107 #if defined(__UCLIBC__)
108 _gregs = _mc->gpregs;
113 /* In glibc's ucontext.h the registers are defined as long long,
114 even for MIPS32, so we cast them. This is not the case for
117 pv = (u1 *) (ptrint) _gregs[REG_PV];
118 sp = (u1 *) (ptrint) _gregs[REG_SP];
119 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
121 #if !defined(__UCLIBC__) && ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
122 /* NOTE: We only need this for pre glibc-2.5. */
124 xpc = (u1 *) (ptrint) _mc->pc;
126 /* get the cause of this exception */
130 /* check the cause to find the faulting instruction */
132 /* TODO: use defines for that stuff */
134 switch (cause & 0x0000003c) {
136 /* TLBL: XPC is ok */
140 /* AdEL: XPC is of the following instruction */
145 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
148 /* get exception-throwing instruction */
150 mcode = *((u4 *) xpc);
152 d = M_ITYPE_GET_RT(mcode);
153 s1 = M_ITYPE_GET_RS(mcode);
154 disp = M_ITYPE_GET_IMM(mcode);
156 /* check for special-load */
158 if (s1 == REG_ZERO) {
159 /* we use the exception type as load displacement */
165 /* This is a normal NPE: addr must be NULL and the NPE-type
173 /* create stackframeinfo */
175 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
177 /* Handle the type. */
179 p = signal_handle(xpc, type, val);
181 /* remove stackframeinfo */
183 stacktrace_remove_stackframeinfo(&sfi);
185 /* set registers (only if exception object ready) */
188 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
189 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
191 #if defined(__UCLIBC__)
192 _gregs[CTX_EPC] = (intptr_t) asm_handle_exception;
194 _mc->pc = (intptr_t) asm_handle_exception;
198 #if defined(__UCLIBC__)
199 _gregs[CTX_EPC] = (intptr_t) xpc;
201 _mc->pc = (intptr_t) xpc;
207 /* md_signal_handler_sigusr2 ***************************************************
211 *******************************************************************************/
213 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
218 /* md_critical_section_restart *************************************************
220 Search the critical sections tree for a matching section and set
221 the PC to the restart point, if necessary.
223 *******************************************************************************/
225 #if defined(ENABLE_THREADS)
226 void md_critical_section_restart(ucontext_t *_uc)
232 _mc = &_uc->uc_mcontext;
234 #if defined(__UCLIBC__)
235 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
237 pc = (u1 *) (ptrint) _mc->pc;
240 npc = critical_find_restart_point(pc);
243 #if defined(__UCLIBC__)
244 _mc->gpregs[CTX_EPC] = (ptrint) npc;
246 _mc->pc = (ptrint) npc;
254 * These are local overrides for various environment variables in Emacs.
255 * Please do not remove this and leave it at the end of the file, where
256 * Emacs will automagically detect them.
257 * ---------------------------------------------------------------------
260 * indent-tabs-mode: t
264 * vim:noexpandtab:sw=4:ts=4: