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)
83 ucontext_t* _uc = (struct ucontext *) _p;
84 mcontext_t* _mc = &_uc->uc_mcontext;
86 void* xpc = (void*) _mc->pc;
89 trap_handle(TRAP_SIGSEGV, xpc, _p);
94 * Illegal Instruction signal handler for hardware exception checks.
96 void md_signal_handler_sigill(int sig, siginfo_t* siginfo, void* _p)
98 ucontext_t* _uc = (struct ucontext *) _p;
99 mcontext_t* _mc = &_uc->uc_mcontext;
101 void* xpc = (void*) _mc->pc;
104 trap_handle(TRAP_SIGILL, xpc, _p);
108 /* md_signal_handler_sigusr2 ***************************************************
112 *******************************************************************************/
114 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
120 * Read the given context into an executionstate.
122 * @param es execution state
123 * @param context machine context
125 void md_executionstate_read(executionstate_t* es, void* context)
132 vm_abort("md_executionstate_read: PLEASE REVISE ME!");
134 _uc = (ucontext_t*) context;
135 _mc = &_uc->uc_mcontext;
137 #if defined(__UCLIBC__)
138 _gregs = _mc->gpregs;
143 /* Read special registers. */
145 /* In glibc's ucontext.h the registers are defined as long long,
146 even for MIPS32, so we cast them. This is not the case for
149 #if defined(__UCLIBC__)
150 es->pc = _gregs[CTX_EPC];
152 es->pc = (void*) (uintptr_t) _mc->pc;
155 es->sp = (void*) (uintptr_t) _gregs[REG_SP];
156 es->pv = (void*) (uintptr_t) _gregs[REG_PV];
157 es->ra = (void*) (uintptr_t) _gregs[REG_RA];
159 /* Read integer registers. */
161 for (i = 0; i < INT_REG_CNT; i++)
162 es->intregs[i] = _gregs[i];
164 /* Read float registers. */
166 /* Do not use the assignment operator '=', as the type of the
167 _mc->fpregs[i] can cause invalid conversions. */
169 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
170 os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
175 * Write the given executionstate back to the context.
177 * @param es execution state
178 * @param context machine context
180 void md_executionstate_write(executionstate_t* es, void* context)
187 vm_abort("md_executionstate_write: PLEASE REVISE ME!");
189 _uc = (ucontext_t *) context;
190 _mc = &_uc->uc_mcontext;
192 /* Write integer registers. */
194 for (i = 0; i < INT_REG_CNT; i++)
195 _gregs[i] = es->intregs[i];
197 /* Write 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(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
205 /* Write special registers. */
207 #if defined(__UCLIBC__)
208 _gregs[CTX_EPC] = es->pc;
210 _mc->pc = (uintptr_t) es->pc;
213 _gregs[REG_SP] = (uintptr_t) es->sp;
214 _gregs[REG_PV] = (uintptr_t) es->pv;
215 _gregs[REG_RA] = (uintptr_t) es->ra;
220 * These are local overrides for various environment variables in Emacs.
221 * Please do not remove this and leave it at the end of the file, where
222 * Emacs will automagically detect them.
223 * ---------------------------------------------------------------------
226 * indent-tabs-mode: t
230 * vim:noexpandtab:sw=4:ts=4: