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 - 4);
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 - 4);
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 _uc = (ucontext_t*) context;
133 _mc = &_uc->uc_mcontext;
135 #if defined(__UCLIBC__)
136 _gregs = _mc->gpregs;
141 /* Read special registers. */
143 /* In glibc's ucontext.h the registers are defined as long long,
144 even for MIPS32, so we cast them. This is not the case for
147 #if defined(__UCLIBC__)
148 es->pc = _gregs[CTX_EPC];
150 es->pc = (void*) (uintptr_t) _mc->pc;
153 es->sp = (void*) (uintptr_t) _gregs[REG_SP];
154 es->pv = (void*) (uintptr_t) _gregs[REG_PV];
155 es->ra = (void*) (uintptr_t) _gregs[REG_RA];
157 /* Read integer registers. */
159 for (i = 0; i < INT_REG_CNT; i++)
160 es->intregs[i] = _gregs[i];
162 /* Read float registers. */
164 /* Do not use the assignment operator '=', as the type of the
165 _mc->fpregs[i] can cause invalid conversions. */
167 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
168 os_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
173 * Write the given executionstate back to the context.
175 * @param es execution state
176 * @param context machine context
178 void md_executionstate_write(executionstate_t* es, void* context)
185 _uc = (ucontext_t *) context;
186 _mc = &_uc->uc_mcontext;
188 #if defined(__UCLIBC__)
189 _gregs = _mc->gpregs;
194 /* Write integer registers. */
196 for (i = 0; i < INT_REG_CNT; i++)
197 _gregs[i] = es->intregs[i];
199 /* Write float registers. */
201 /* Do not use the assignment operator '=', as the type of the
202 _mc->fpregs[i] can cause invalid conversions. */
204 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
205 os_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
207 /* Write special registers. */
209 #if defined(__UCLIBC__)
210 _gregs[CTX_EPC] = es->pc;
212 _mc->pc = (uintptr_t) es->pc;
215 _gregs[REG_SP] = (uintptr_t) es->sp;
216 _gregs[REG_PV] = (uintptr_t) es->pv;
217 _gregs[REG_RA] = (uintptr_t) es->ra;
222 * These are local overrides for various environment variables in Emacs.
223 * Please do not remove this and leave it at the end of the file, where
224 * Emacs will automagically detect them.
225 * ---------------------------------------------------------------------
228 * indent-tabs-mode: t
232 * vim:noexpandtab:sw=4:ts=4: