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.h"
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/stacktrace.h"
46 #include "vm/jit/trap.h"
48 #include "vmcore/system.h"
51 /* md_signal_handler_sigsegv ***************************************************
53 NullPointerException signal handler for hardware null pointer
56 *******************************************************************************/
58 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
75 _uc = (ucontext_t *) _p;
76 _mc = &_uc->uc_mcontext;
78 pv = (u1 *) _mc->sc_regs[REG_PV];
79 sp = (u1 *) _mc->sc_regs[REG_SP];
80 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
81 xpc = (u1 *) _mc->sc_pc;
83 /* get exception-throwing instruction */
85 mcode = *((u4 *) xpc);
87 d = M_MEM_GET_Ra(mcode);
88 s1 = M_MEM_GET_Rb(mcode);
89 disp = M_MEM_GET_Memory_disp(mcode);
91 val = _mc->sc_regs[d];
93 /* check for special-load */
96 /* we use the exception type as load displacement */
100 if (type == TRAP_COMPILER) {
101 /* The XPC is the RA minus 1, because the RA points to the
102 instruction after the call. */
108 /* This is a normal NPE: addr must be NULL and the NPE-type
111 addr = _mc->sc_regs[s1];
115 /* Handle the trap. */
117 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
124 _mc->sc_regs[REG_PV] = (uintptr_t) p;
125 _mc->sc_pc = (uintptr_t) p;
129 /* Get and set the PV from the parent Java method. */
131 pv = md_codegen_get_pv_from_pc(ra);
133 _mc->sc_regs[REG_PV] = (uintptr_t) pv;
135 /* Get the exception object. */
137 p = builtin_retrieve_exception();
150 _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
151 _mc->sc_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
152 _mc->sc_pc = (uintptr_t) asm_handle_exception;
157 /* md_signal_handler_sigusr1 ***************************************************
159 Signal handler for suspending threads.
161 *******************************************************************************/
163 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
164 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
171 _uc = (ucontext_t *) _p;
172 _mc = &_uc->uc_mcontext;
174 /* get the PC and SP for this thread */
175 pc = (u1 *) _mc->sc_pc;
176 sp = (u1 *) _mc->sc_regs[REG_SP];
178 /* now suspend the current thread */
179 threads_suspend_ack(pc, sp);
184 /* md_signal_handler_sigusr2 ***************************************************
186 Signal handler for profiling sampling.
188 *******************************************************************************/
190 #if defined(ENABLE_THREADS)
191 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
200 _uc = (ucontext_t *) _p;
201 _mc = &_uc->uc_mcontext;
203 pc = (u1 *) _mc->sc_pc;
210 /* md_executionstate_read ******************************************************
212 Read the given context into an executionstate.
214 *******************************************************************************/
216 void md_executionstate_read(executionstate_t *es, void *context)
222 _uc = (ucontext_t *) context;
223 _mc = &_uc->uc_mcontext;
225 /* read special registers */
226 es->pc = (u1 *) _mc->sc_pc;
227 es->sp = (u1 *) _mc->sc_regs[REG_SP];
228 es->pv = (u1 *) _mc->sc_regs[REG_PV];
229 es->ra = (u1 *) _mc->sc_regs[REG_RA];
231 /* read integer registers */
232 for (i = 0; i < INT_REG_CNT; i++)
233 es->intregs[i] = _mc->sc_regs[i];
235 /* read float registers */
236 /* Do not use the assignment operator '=', as the type of
237 * the _mc->sc_fpregs[i] can cause invalid conversions. */
239 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
240 system_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
244 /* md_executionstate_write *****************************************************
246 Write the given executionstate back to the context.
248 *******************************************************************************/
250 void md_executionstate_write(executionstate_t *es, void *context)
256 _uc = (ucontext_t *) context;
257 _mc = &_uc->uc_mcontext;
259 /* write integer registers */
260 for (i = 0; i < INT_REG_CNT; i++)
261 _mc->sc_regs[i] = es->intregs[i];
263 /* write float registers */
264 /* Do not use the assignment operator '=', as the type of
265 * the _mc->sc_fpregs[i] can cause invalid conversions. */
267 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
268 system_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
270 /* write special registers */
271 _mc->sc_pc = (ptrint) es->pc;
272 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
273 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
274 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
278 /* md_critical_section_restart *************************************************
280 Search the critical sections tree for a matching section and set
281 the PC to the restart point, if necessary.
283 *******************************************************************************/
285 #if defined(ENABLE_THREADS)
286 void md_critical_section_restart(ucontext_t *_uc)
292 _mc = &_uc->uc_mcontext;
294 pc = (u1 *) _mc->sc_pc;
296 npc = critical_find_restart_point(pc);
299 _mc->sc_pc = (ptrint) npc;
305 * These are local overrides for various environment variables in Emacs.
306 * Please do not remove this and leave it at the end of the file, where
307 * Emacs will automagically detect them.
308 * ---------------------------------------------------------------------
311 * indent-tabs-mode: t