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 8283 2007-08-09 15:10:05Z twisti $
33 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
40 #include "vm/jit/mips/codegen.h"
41 #include "vm/jit/mips/md-abi.h"
43 #include "mm/gc-common.h"
45 #include "vm/signallocal.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)
63 heap_allocate(1, 0, NULL);
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)
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 */
167 /* This is a normal NPE: addr must be NULL and the NPE-type
175 /* create stackframeinfo */
177 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
179 /* Handle the type. */
181 p = signal_handle(xpc, type, val);
183 /* remove stackframeinfo */
185 stacktrace_remove_stackframeinfo(&sfi);
187 /* set registers (only if exception object ready) */
190 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
191 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
193 #if defined(__UCLIBC__)
194 _gregs[CTX_EPC] = (intptr_t) asm_handle_exception;
196 _mc->pc = (intptr_t) asm_handle_exception;
200 #if defined(__UCLIBC__)
201 _gregs[CTX_EPC] = (intptr_t) xpc;
203 _mc->pc = (intptr_t) xpc;
209 /* md_signal_handler_sigusr2 ***************************************************
213 *******************************************************************************/
215 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
220 /* md_critical_section_restart *************************************************
222 Search the critical sections tree for a matching section and set
223 the PC to the restart point, if necessary.
225 *******************************************************************************/
227 #if defined(ENABLE_THREADS)
228 void md_critical_section_restart(ucontext_t *_uc)
234 _mc = &_uc->uc_mcontext;
236 #if defined(__UCLIBC__)
237 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
239 pc = (u1 *) (ptrint) _mc->pc;
242 npc = critical_find_restart_point(pc);
245 #if defined(__UCLIBC__)
246 _mc->gpregs[CTX_EPC] = (ptrint) npc;
248 _mc->pc = (ptrint) npc;
256 * These are local overrides for various environment variables in Emacs.
257 * Please do not remove this and leave it at the end of the file, where
258 * Emacs will automagically detect them.
259 * ---------------------------------------------------------------------
262 * indent-tabs-mode: t
266 * vim:noexpandtab:sw=4:ts=4: