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
25 $Id: md-os.c 7688 2007-04-12 09:05:12Z michi $
33 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
39 #include "vm/jit/mips/codegen.h"
40 #include "vm/jit/mips/md-abi.h"
42 #include "mm/gc-common.h"
44 #include "vm/exceptions.h"
45 #include "vm/stringlocal.h"
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.h"
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
59 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
60 /* dummy allocation here to ensure that the GC is initialized. */
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)
103 java_objectheader *o;
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__) && ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
123 /* NOTE: We only need this for pre glibc-2.5. */
125 xpc = (u1 *) (ptrint) _mc->pc;
127 /* get the cause of this exception */
131 /* check the cause to find the faulting instruction */
133 /* TODO: use defines for that stuff */
135 switch (cause & 0x0000003c) {
137 /* TLBL: XPC is ok */
141 /* AdEL: XPC is of the following instruction */
146 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
149 /* get exception-throwing instruction */
151 mcode = *((u4 *) xpc);
153 d = M_ITYPE_GET_RT(mcode);
154 s1 = M_ITYPE_GET_RS(mcode);
155 disp = M_ITYPE_GET_IMM(mcode);
157 /* check for special-load */
159 if (s1 == REG_ZERO) {
160 /* we use the exception type as load displacement */
166 /* This is a normal NPE: addr must be NULL and the NPE-type
174 /* generate appropriate exception */
176 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
180 _gregs[REG_ITMP1_XPTR] = (ptrint) o;
181 _gregs[REG_ITMP2_XPC] = (ptrint) xpc;
183 #if defined(__UCLIBC__)
184 _gregs[CTX_EPC] = (ptrint) asm_handle_exception;
186 _mc->pc = (ptrint) asm_handle_exception;
191 /* md_signal_handler_sigusr2 ***************************************************
195 *******************************************************************************/
197 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
202 #if defined(ENABLE_THREADS)
203 void thread_restartcriticalsection(ucontext_t *_uc)
209 _mc = &_uc->uc_mcontext;
211 #if defined(__UCLIBC__)
212 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
214 pc = (u1 *) (ptrint) _mc->pc;
217 npc = critical_find_restart_point(pc);
220 #if defined(__UCLIBC__)
221 _mc->gpregs[CTX_EPC] = (ptrint) npc;
223 _mc->pc = (ptrint) npc;
231 * These are local overrides for various environment variables in Emacs.
232 * Please do not remove this and leave it at the end of the file, where
233 * Emacs will automagically detect them.
234 * ---------------------------------------------------------------------
237 * indent-tabs-mode: t
241 * vim:noexpandtab:sw=4:ts=4: