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 7252 2007-01-29 21:09:01Z twisti $
33 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
39 #include "vm/jit/mips/md-abi.h"
41 #include "mm/gc-common.h"
43 #include "vm/exceptions.h"
44 #include "vm/stringlocal.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 a */
59 /* dummy allocation here to ensure that the GC is initialized. */
61 #if defined(ENABLE_GC_BOEHM)
62 heap_allocate(1, 0, NULL);
66 /* Turn off flush-to-zero */
70 n.fc_word = get_fpc_csr();
71 n.fc_struct.flush = 0;
72 set_fpc_csr(n.fc_word);
78 /* md_signal_handler_sigsegv ***************************************************
80 NullPointerException signal handler for hardware null pointer
83 *******************************************************************************/
85 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
97 _uc = (struct ucontext *) _p;
98 _mc = &_uc->uc_mcontext;
100 #if defined(__UCLIBC__)
101 _gregs = _mc->gpregs;
106 /* In glibc's ucontext.h the registers are defined as long long,
107 even for MIPS32, so we cast them. This is not the case for
110 pv = (u1 *) (ptrint) _gregs[REG_PV];
111 sp = (u1 *) (ptrint) _gregs[REG_SP];
112 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
114 #if defined(__UCLIBC__)
115 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
117 xpc = (u1 *) (ptrint) _mc->pc;
120 instr = *((u4 *) xpc);
121 addr = _gregs[(instr >> 21) & 0x1f];
124 _gregs[REG_ITMP1_XPTR] =
125 (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
127 _gregs[REG_ITMP2_XPC] = (ptrint) xpc;
129 #if defined(__UCLIBC__)
130 _gregs[CTX_EPC] = (ptrint) asm_handle_exception;
132 _mc->pc = (ptrint) asm_handle_exception;
136 codegen_get_pv_from_pc(xpc);
138 /* this should not happen */
145 /* md_signal_handler_sigusr2 ***************************************************
149 *******************************************************************************/
151 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
156 #if defined(ENABLE_THREADS)
157 void thread_restartcriticalsection(ucontext_t *_uc)
163 _mc = &_uc->uc_mcontext;
165 #if defined(__UCLIBC__)
166 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
168 pc = (u1 *) (ptrint) _mc->pc;
171 npc = critical_find_restart_point(pc);
174 #if defined(__UCLIBC__)
175 _mc->gpregs[CTX_EPC] = (ptrint) npc;
177 _mc->pc = (ptrint) npc;
185 * These are local overrides for various environment variables in Emacs.
186 * Please do not remove this and leave it at the end of the file, where
187 * Emacs will automagically detect them.
188 * ---------------------------------------------------------------------
191 * indent-tabs-mode: t
195 * vim:noexpandtab:sw=4:ts=4: