1 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 #include <sgidefs.h> /* required for _MIPS_SIM_ABI* defines (before signal.h) */
36 #include "vm/jit/mips/codegen.h"
37 #include "vm/jit/mips/md.h"
38 #include "vm/jit/mips/md-abi.h"
41 #include "mm/memory.hpp"
43 #include "vm/signallocal.hpp"
45 #include "vm/jit/executionstate.h"
46 #include "vm/jit/trap.hpp"
49 /* md_init *********************************************************************
51 Do some machine dependent initialization.
53 *******************************************************************************/
57 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do
58 a dummy allocation here to ensure that the GC is
61 #if defined(ENABLE_GC_BOEHM)
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);
79 * NullPointerException signal handler for hardware null pointer check.
81 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
85 ucontext_t* _uc = (struct ucontext *) _p;
86 mcontext_t* _mc = &_uc->uc_mcontext;
89 #if !defined(__UCLIBC__)
90 # if ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
91 /* NOTE: We only need this for pre glibc-2.5. */
93 /* get the cause of this exception */
97 /* check the cause to find the faulting instruction */
99 /* TODO: use defines for that stuff */
101 switch (cause & 0x0000003c) {
103 /* TLBL: XPC is ok */
107 /* AdEL: XPC is of the following instruction */
111 xpc = (void*) (_mc->pc + disp);
113 xpc = (void*) _mc->pc;
116 xpc = (void*) _gregs[CTX_EPC];
120 trap_handle(TRAP_SIGSEGV, xpc, _p);
125 * Illegal Instruction signal handler for hardware exception checks.
127 void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
129 ucontext_t* _uc = (struct ucontext *) _p;
130 mcontext_t* _mc = &_uc->uc_mcontext;
132 #if !defined(__UCLIBC__)
133 void* xpc = (void*) _mc->pc;
135 void* xpc = (void*) _gregs[CTX_EPC];
139 trap_handle(TRAP_SIGILL, xpc, _p);
143 /* md_signal_handler_sigusr2 ***************************************************
147 *******************************************************************************/
149 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
155 * Read the given context into an executionstate.
157 * @param es execution state
158 * @param context machine context
160 void md_executionstate_read(executionstate_t* es, void* context)
167 _uc = (ucontext_t*) context;
168 _mc = &_uc->uc_mcontext;
170 #if defined(__UCLIBC__)
171 _gregs = _mc->gpregs;
176 /* Read special registers. */
178 /* In glibc's ucontext.h the registers are defined as long long,
179 even for MIPS32, so we cast them. This is not the case for
182 #if defined(__UCLIBC__)
183 es->pc = _gregs[CTX_EPC];
185 es->pc = (void*) (uintptr_t) _mc->pc;
188 es->sp = (void*) (uintptr_t) _gregs[REG_SP];
189 es->pv = (void*) (uintptr_t) _gregs[REG_PV];
190 es->ra = (void*) (uintptr_t) _gregs[REG_RA];
192 /* Read integer registers. */
194 for (i = 0; i < INT_REG_CNT; i++)
195 es->intregs[i] = _gregs[i];
197 /* Read float registers. */
199 /* Do not use the assignment operator '=', as the type of the
200 _mc->fpregs[i] can cause invalid conversions. */
202 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
203 os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
208 * Write the given executionstate back to the context.
210 * @param es execution state
211 * @param context machine context
213 void md_executionstate_write(executionstate_t* es, void* context)
220 _uc = (ucontext_t *) context;
221 _mc = &_uc->uc_mcontext;
223 #if defined(__UCLIBC__)
224 _gregs = _mc->gpregs;
229 /* Write integer registers. */
231 for (i = 0; i < INT_REG_CNT; i++)
232 _gregs[i] = es->intregs[i];
234 /* Write float registers. */
236 /* Do not use the assignment operator '=', as the type of the
237 _mc->fpregs[i] can cause invalid conversions. */
239 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
240 os_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
242 /* Write special registers. */
244 #if defined(__UCLIBC__)
245 _gregs[CTX_EPC] = es->pc;
247 _mc->pc = (uintptr_t) es->pc;
250 _gregs[REG_SP] = (uintptr_t) es->sp;
251 _gregs[REG_PV] = (uintptr_t) es->pv;
252 _gregs[REG_RA] = (uintptr_t) es->ra;
257 * These are local overrides for various environment variables in Emacs.
258 * Please do not remove this and leave it at the end of the file, where
259 * Emacs will automagically detect them.
260 * ---------------------------------------------------------------------
263 * indent-tabs-mode: t
267 * vim:noexpandtab:sw=4:ts=4: