1 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
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.h"
43 #include "vm/exceptions.h"
44 #include "vm/signallocal.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/executionstate.h"
48 #include "vm/jit/trap.h"
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
59 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do
60 a dummy allocation here to ensure that the GC is
63 #if defined(ENABLE_GC_BOEHM)
68 /* Turn off flush-to-zero */
72 n.fc_word = get_fpc_csr();
73 n.fc_struct.flush = 0;
74 set_fpc_csr(n.fc_word);
80 /* md_signal_handler_sigsegv ***************************************************
82 NullPointerException signal handler for hardware null pointer
85 *******************************************************************************/
87 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
106 _uc = (struct ucontext *) _p;
107 _mc = &_uc->uc_mcontext;
109 #if defined(__UCLIBC__)
110 _gregs = _mc->gpregs;
115 /* In glibc's ucontext.h the registers are defined as long long,
116 even for MIPS32, so we cast them. This is not the case for
119 pv = (u1 *) (ptrint) _gregs[REG_PV];
120 sp = (u1 *) (ptrint) _gregs[REG_SP];
121 ra = (u1 *) (ptrint) _gregs[REG_RA]; /* this is correct for leafs */
123 #if !defined(__UCLIBC__)
124 # if ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 5))
125 /* NOTE: We only need this for pre glibc-2.5. */
127 xpc = (u1 *) (ptrint) _mc->pc;
129 /* get the cause of this exception */
133 /* check the cause to find the faulting instruction */
135 /* TODO: use defines for that stuff */
137 switch (cause & 0x0000003c) {
139 /* TLBL: XPC is ok */
143 /* AdEL: XPC is of the following instruction */
148 xpc = (u1 *) (ptrint) _mc->pc;
151 xpc = (u1 *) (ptrint) _gregs[CTX_EPC];
154 /* get exception-throwing instruction */
156 mcode = *((u4 *) xpc);
158 d = M_ITYPE_GET_RT(mcode);
159 s1 = M_ITYPE_GET_RS(mcode);
160 disp = M_ITYPE_GET_IMM(mcode);
162 /* check for special-load */
164 if (s1 == REG_ZERO) {
165 /* we use the exception type as load displacement */
170 if (type == TRAP_COMPILER) {
171 /* The XPC is the RA minus 4, because the RA points to the
172 instruction after the call. */
178 /* This is a normal NPE: addr must be NULL and the NPE-type
186 /* Handle the trap. */
188 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
195 _gregs[REG_PV] = (uintptr_t) p;
196 #if defined(__UCLIBC__)
197 _gregs[CTX_EPC] = (uintptr_t) p;
199 _mc->pc = (uintptr_t) p;
204 /* Get and set the PV from the parent Java method. */
206 pv = md_codegen_get_pv_from_pc(ra);
208 _gregs[REG_PV] = (uintptr_t) pv;
210 /* Get the exception object. */
212 p = builtin_retrieve_exception();
220 /* We set the PC again because the cause may have changed
223 #if defined(__UCLIBC__)
224 _gregs[CTX_EPC] = (uintptr_t) xpc;
226 _mc->pc = (uintptr_t) xpc;
234 _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
235 _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
236 #if defined(__UCLIBC__)
237 _gregs[CTX_EPC] = (uintptr_t) asm_handle_exception;
239 _mc->pc = (uintptr_t) asm_handle_exception;
245 /* md_signal_handler_sigusr2 ***************************************************
249 *******************************************************************************/
251 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
257 * Read the given context into an executionstate.
259 * @param es execution state
260 * @param context machine context
262 void md_executionstate_read(executionstate_t* es, void* context)
269 vm_abort("md_executionstate_read: PLEASE REVISE ME!");
271 _uc = (ucontext_t*) context;
272 _mc = &_uc->uc_mcontext;
274 #if defined(__UCLIBC__)
275 _gregs = _mc->gpregs;
280 /* Read special registers. */
282 /* In glibc's ucontext.h the registers are defined as long long,
283 even for MIPS32, so we cast them. This is not the case for
286 #if defined(__UCLIBC__)
287 es->pc = _gregs[CTX_EPC];
289 es->pc = (void*) (uintptr_t) _mc->pc;
292 es->sp = (void*) (uintptr_t) _gregs[REG_SP];
293 es->pv = (void*) (uintptr_t) _gregs[REG_PV];
294 es->ra = (void*) (uintptr_t) _gregs[REG_RA];
296 /* Read integer registers. */
298 for (i = 0; i < INT_REG_CNT; i++)
299 es->intregs[i] = _gregs[i];
301 /* Read float registers. */
303 /* Do not use the assignment operator '=', as the type of the
304 _mc->fpregs[i] can cause invalid conversions. */
306 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
307 system_memcpy(&es->fltregs, &_mc->fpregs.fp_r, sizeof(_mc->fpregs.fp_r));
312 * Write the given executionstate back to the context.
314 * @param es execution state
315 * @param context machine context
317 void md_executionstate_write(executionstate_t* es, void* context)
324 vm_abort("md_executionstate_write: PLEASE REVISE ME!");
326 _uc = (ucontext_t *) context;
327 _mc = &_uc->uc_mcontext;
329 /* Write integer registers. */
331 for (i = 0; i < INT_REG_CNT; i++)
332 _gregs[i] = es->intregs[i];
334 /* Write float registers. */
336 /* Do not use the assignment operator '=', as the type of the
337 _mc->fpregs[i] can cause invalid conversions. */
339 assert(sizeof(_mc->fpregs.fp_r) == sizeof(es->fltregs));
340 system_memcpy(&_mc->fpregs.fp_r, &es->fltregs, sizeof(_mc->fpregs.fp_r));
342 /* Write special registers. */
344 #if defined(__UCLIBC__)
345 _gregs[CTX_EPC] = es->pc;
347 _mc->pc = (uintptr_t) es->pc;
350 _gregs[REG_SP] = (uintptr_t) es->sp;
351 _gregs[REG_PV] = (uintptr_t) es->pv;
352 _gregs[REG_RA] = (uintptr_t) es->ra;
357 * These are local overrides for various environment variables in Emacs.
358 * Please do not remove this and leave it at the end of the file, where
359 * Emacs will automagically detect them.
360 * ---------------------------------------------------------------------
363 * indent-tabs-mode: t
367 * vim:noexpandtab:sw=4:ts=4: