1 /* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha 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
34 #include "vm/jit/alpha/codegen.h"
35 #include "vm/jit/alpha/md.h"
36 #include "vm/jit/alpha/md-abi.h"
38 #include "threads/thread.hpp"
40 #include "vm/builtin.h"
41 #include "vm/signallocal.h"
43 #include "vm/jit/asmpart.h"
44 #include "vm/jit/executionstate.h"
45 #include "vm/jit/trap.h"
47 #include "vmcore/os.hpp"
50 /* md_signal_handler_sigsegv ***************************************************
52 NullPointerException signal handler for hardware null pointer
55 *******************************************************************************/
57 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
74 _uc = (ucontext_t *) _p;
75 _mc = &_uc->uc_mcontext;
77 pv = (u1 *) _mc->sc_regs[REG_PV];
78 sp = (u1 *) _mc->sc_regs[REG_SP];
79 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
80 xpc = (u1 *) _mc->sc_pc;
82 /* get exception-throwing instruction */
84 mcode = *((u4 *) xpc);
86 d = M_MEM_GET_Ra(mcode);
87 s1 = M_MEM_GET_Rb(mcode);
88 disp = M_MEM_GET_Memory_disp(mcode);
90 val = _mc->sc_regs[d];
92 /* check for special-load */
95 /* we use the exception type as load displacement */
99 if (type == TRAP_COMPILER) {
100 /* The XPC is the RA minus 1, because the RA points to the
101 instruction after the call. */
107 /* This is a normal NPE: addr must be NULL and the NPE-type
110 addr = _mc->sc_regs[s1];
114 /* Handle the trap. */
116 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
123 _mc->sc_regs[REG_PV] = (uintptr_t) p;
124 _mc->sc_pc = (uintptr_t) p;
128 /* Get and set the PV from the parent Java method. */
130 pv = md_codegen_get_pv_from_pc(ra);
132 _mc->sc_regs[REG_PV] = (uintptr_t) pv;
134 /* Get the exception object. */
136 p = builtin_retrieve_exception();
149 _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
150 _mc->sc_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
151 _mc->sc_pc = (uintptr_t) asm_handle_exception;
156 /* md_signal_handler_sigusr1 ***************************************************
158 Signal handler for suspending threads.
160 *******************************************************************************/
162 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
163 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
170 _uc = (ucontext_t *) _p;
171 _mc = &_uc->uc_mcontext;
173 /* get the PC and SP for this thread */
174 pc = (u1 *) _mc->sc_pc;
175 sp = (u1 *) _mc->sc_regs[REG_SP];
177 /* now suspend the current thread */
178 threads_suspend_ack(pc, sp);
183 /* md_signal_handler_sigusr2 ***************************************************
185 Signal handler for profiling sampling.
187 *******************************************************************************/
189 #if defined(ENABLE_THREADS)
190 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
199 _uc = (ucontext_t *) _p;
200 _mc = &_uc->uc_mcontext;
202 pc = (u1 *) _mc->sc_pc;
209 /* md_executionstate_read ******************************************************
211 Read the given context into an executionstate.
213 *******************************************************************************/
215 void md_executionstate_read(executionstate_t *es, void *context)
221 _uc = (ucontext_t *) context;
222 _mc = &_uc->uc_mcontext;
224 /* read special registers */
225 es->pc = (u1 *) _mc->sc_pc;
226 es->sp = (u1 *) _mc->sc_regs[REG_SP];
227 es->pv = (u1 *) _mc->sc_regs[REG_PV];
228 es->ra = (u1 *) _mc->sc_regs[REG_RA];
230 /* read integer registers */
231 for (i = 0; i < INT_REG_CNT; i++)
232 es->intregs[i] = _mc->sc_regs[i];
234 /* read float registers */
235 /* Do not use the assignment operator '=', as the type of
236 * the _mc->sc_fpregs[i] can cause invalid conversions. */
238 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
239 os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
243 /* md_executionstate_write *****************************************************
245 Write the given executionstate back to the context.
247 *******************************************************************************/
249 void md_executionstate_write(executionstate_t *es, void *context)
255 _uc = (ucontext_t *) context;
256 _mc = &_uc->uc_mcontext;
258 /* write integer registers */
259 for (i = 0; i < INT_REG_CNT; i++)
260 _mc->sc_regs[i] = es->intregs[i];
262 /* write float registers */
263 /* Do not use the assignment operator '=', as the type of
264 * the _mc->sc_fpregs[i] can cause invalid conversions. */
266 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
267 os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
269 /* write special registers */
270 _mc->sc_pc = (ptrint) es->pc;
271 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
272 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
273 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
278 * These are local overrides for various environment variables in Emacs.
279 * Please do not remove this and leave it at the end of the file, where
280 * Emacs will automagically detect them.
281 * ---------------------------------------------------------------------
284 * indent-tabs-mode: t