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"
44 #include "vm/jit/asmpart.h"
45 #include "vm/jit/executionstate.h"
46 #include "vm/jit/trap.h"
49 /* md_signal_handler_sigsegv ***************************************************
51 NullPointerException signal handler for hardware null pointer
54 *******************************************************************************/
56 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
73 _uc = (ucontext_t *) _p;
74 _mc = &_uc->uc_mcontext;
76 pv = (u1 *) _mc->sc_regs[REG_PV];
77 sp = (u1 *) _mc->sc_regs[REG_SP];
78 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
79 xpc = (u1 *) _mc->sc_pc;
81 /* get exception-throwing instruction */
83 mcode = *((u4 *) xpc);
85 d = M_MEM_GET_Ra(mcode);
86 s1 = M_MEM_GET_Rb(mcode);
87 disp = M_MEM_GET_Memory_disp(mcode);
89 val = _mc->sc_regs[d];
91 /* check for special-load */
94 /* we use the exception type as load displacement */
98 if (type == TRAP_COMPILER) {
99 /* The XPC is the RA minus 1, because the RA points to the
100 instruction after the call. */
106 /* This is a normal NPE: addr must be NULL and the NPE-type
109 addr = _mc->sc_regs[s1];
113 /* Handle the trap. */
115 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
122 _mc->sc_regs[REG_PV] = (uintptr_t) p;
123 _mc->sc_pc = (uintptr_t) p;
127 /* Get and set the PV from the parent Java method. */
129 pv = md_codegen_get_pv_from_pc(ra);
131 _mc->sc_regs[REG_PV] = (uintptr_t) pv;
133 /* Get the exception object. */
135 p = builtin_retrieve_exception();
148 _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
149 _mc->sc_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
150 _mc->sc_pc = (uintptr_t) asm_handle_exception;
155 /* md_signal_handler_sigusr1 ***************************************************
157 Signal handler for suspending threads.
159 *******************************************************************************/
161 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
162 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
169 _uc = (ucontext_t *) _p;
170 _mc = &_uc->uc_mcontext;
172 /* get the PC and SP for this thread */
173 pc = (u1 *) _mc->sc_pc;
174 sp = (u1 *) _mc->sc_regs[REG_SP];
176 /* now suspend the current thread */
177 threads_suspend_ack(pc, sp);
182 /* md_signal_handler_sigusr2 ***************************************************
184 Signal handler for profiling sampling.
186 *******************************************************************************/
188 #if defined(ENABLE_THREADS)
189 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
198 _uc = (ucontext_t *) _p;
199 _mc = &_uc->uc_mcontext;
201 pc = (u1 *) _mc->sc_pc;
208 /* md_executionstate_read ******************************************************
210 Read the given context into an executionstate.
212 *******************************************************************************/
214 void md_executionstate_read(executionstate_t *es, void *context)
220 _uc = (ucontext_t *) context;
221 _mc = &_uc->uc_mcontext;
223 /* read special registers */
224 es->pc = (u1 *) _mc->sc_pc;
225 es->sp = (u1 *) _mc->sc_regs[REG_SP];
226 es->pv = (u1 *) _mc->sc_regs[REG_PV];
227 es->ra = (u1 *) _mc->sc_regs[REG_RA];
229 /* read integer registers */
230 for (i = 0; i < INT_REG_CNT; i++)
231 es->intregs[i] = _mc->sc_regs[i];
233 /* read float registers */
234 /* Do not use the assignment operator '=', as the type of
235 * the _mc->sc_fpregs[i] can cause invalid conversions. */
237 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
238 os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
242 /* md_executionstate_write *****************************************************
244 Write the given executionstate back to the context.
246 *******************************************************************************/
248 void md_executionstate_write(executionstate_t *es, void *context)
254 _uc = (ucontext_t *) context;
255 _mc = &_uc->uc_mcontext;
257 /* write integer registers */
258 for (i = 0; i < INT_REG_CNT; i++)
259 _mc->sc_regs[i] = es->intregs[i];
261 /* write float registers */
262 /* Do not use the assignment operator '=', as the type of
263 * the _mc->sc_fpregs[i] can cause invalid conversions. */
265 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
266 os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
268 /* write special registers */
269 _mc->sc_pc = (ptrint) es->pc;
270 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
271 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
272 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
277 * These are local overrides for various environment variables in Emacs.
278 * Please do not remove this and leave it at the end of the file, where
279 * Emacs will automagically detect them.
280 * ---------------------------------------------------------------------
283 * indent-tabs-mode: t