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 Contact: cacao@cacaojvm.org
27 Authors: Andreas Krall
31 $Id: md-os.c 7206 2007-01-11 22:39:52Z twisti $
39 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
45 #include "vm/jit/mips/md-abi.h"
47 #include "mm/gc-common.h"
48 #include "vm/exceptions.h"
49 #include "vm/signallocal.h"
50 #include "vm/stringlocal.h"
51 #include "vm/jit/asmpart.h"
52 #include "vm/jit/stacktrace.h"
55 /* md_init *********************************************************************
57 Do some machine dependent initialization.
59 *******************************************************************************/
63 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
64 /* dummy allocation here to ensure that the GC is initialized. */
66 #if defined(ENABLE_GC_BOEHM)
67 heap_allocate(1, 0, NULL);
71 /* Turn off flush-to-zero */
75 n.fc_word = get_fpc_csr();
76 n.fc_struct.flush = 0;
77 set_fpc_csr(n.fc_word);
83 /* md_signal_handler_sigsegv ***************************************************
85 NullPointerException signal handler for hardware null pointer
88 *******************************************************************************/
90 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
102 _uc = (struct ucontext *) _p;
103 _mc = &_uc->uc_mcontext;
105 #if defined(__UCLIBC__)
106 _gregs = _mc->gpregs;
111 /* In glibc's ucontext.h the registers are defined as long long,
112 even for MIPS32, so we cast them. This is not the case for
115 pv = (u1 *) (ptrint) _gregs[REG_PV];
116 sp = (u1 *) (ptrint) _gregs[REG_SP];
117 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
119 #if defined(__UCLIBC__)
120 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
122 xpc = (u1 *) (ptrint) _mc->pc;
125 instr = *((u4 *) xpc);
126 addr = _gregs[(instr >> 21) & 0x1f];
129 _gregs[REG_ITMP1_XPTR] =
130 (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
132 _gregs[REG_ITMP2_XPC] = (ptrint) xpc;
134 #if defined(__UCLIBC__)
135 _gregs[CTX_EPC] = (ptrint) asm_handle_exception;
137 _mc->pc = (ptrint) asm_handle_exception;
141 addr += (long) ((instr << 16) >> 16);
143 throw_cacao_exception_exit(string_java_lang_InternalError,
144 "faulting address: 0x%lx at 0x%lx\n",
150 /* md_signal_handler_sigusr2 ***************************************************
154 *******************************************************************************/
156 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
161 #if defined(ENABLE_THREADS)
162 void thread_restartcriticalsection(ucontext_t *_uc)
168 _mc = &_uc->uc_mcontext;
170 #if defined(__UCLIBC__)
171 pc = (u1 *) (ptrint) _mc->gpregs[CTX_EPC];
173 pc = (u1 *) (ptrint) _mc->pc;
176 npc = critical_find_restart_point(pc);
179 #if defined(__UCLIBC__)
180 _mc->gpregs[CTX_EPC] = (ptrint) npc;
182 _mc->pc = (ptrint) npc;
190 * These are local overrides for various environment variables in Emacs.
191 * Please do not remove this and leave it at the end of the file, where
192 * Emacs will automagically detect them.
193 * ---------------------------------------------------------------------
196 * indent-tabs-mode: t
200 * vim:noexpandtab:sw=4:ts=4: