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 #if defined(ENABLE_THREADS)
39 # include "threads/native/threads.h"
42 #include "vm/builtin.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/stacktrace.h"
50 #include "vmcore/system.h"
53 /* md_signal_handler_sigsegv ***************************************************
55 NullPointerException signal handler for hardware null pointer
58 *******************************************************************************/
60 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
77 _uc = (ucontext_t *) _p;
78 _mc = &_uc->uc_mcontext;
80 pv = (u1 *) _mc->sc_regs[REG_PV];
81 sp = (u1 *) _mc->sc_regs[REG_SP];
82 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
83 xpc = (u1 *) _mc->sc_pc;
85 /* get exception-throwing instruction */
87 mcode = *((u4 *) xpc);
89 d = M_MEM_GET_Ra(mcode);
90 s1 = M_MEM_GET_Rb(mcode);
91 disp = M_MEM_GET_Memory_disp(mcode);
93 val = _mc->sc_regs[d];
95 /* check for special-load */
98 /* we use the exception type as load displacement */
102 if (type == EXCEPTION_HARDWARE_COMPILER) {
103 /* The XPC is the RA minus 1, because the RA points to the
104 instruction after the call. */
110 /* This is a normal NPE: addr must be NULL and the NPE-type
113 addr = _mc->sc_regs[s1];
117 /* Handle the type. */
119 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
124 case EXCEPTION_HARDWARE_COMPILER:
126 _mc->sc_regs[REG_PV] = (uintptr_t) p;
127 _mc->sc_pc = (uintptr_t) p;
131 /* Get and set the PV from the parent Java method. */
133 pv = md_codegen_get_pv_from_pc(ra);
135 _mc->sc_regs[REG_PV] = (uintptr_t) pv;
137 /* Get the exception object. */
139 p = builtin_retrieve_exception();
145 case EXCEPTION_HARDWARE_PATCHER:
152 _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
153 _mc->sc_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
154 _mc->sc_pc = (uintptr_t) asm_handle_exception;
159 /* md_signal_handler_sigusr1 ***************************************************
161 Signal handler for suspending threads.
163 *******************************************************************************/
165 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
166 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
173 _uc = (ucontext_t *) _p;
174 _mc = &_uc->uc_mcontext;
176 /* get the PC and SP for this thread */
177 pc = (u1 *) _mc->sc_pc;
178 sp = (u1 *) _mc->sc_regs[REG_SP];
180 /* now suspend the current thread */
181 threads_suspend_ack(pc, sp);
186 /* md_signal_handler_sigusr2 ***************************************************
188 Signal handler for profiling sampling.
190 *******************************************************************************/
192 #if defined(ENABLE_THREADS)
193 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
202 _uc = (ucontext_t *) _p;
203 _mc = &_uc->uc_mcontext;
205 pc = (u1 *) _mc->sc_pc;
212 /* md_executionstate_read ******************************************************
214 Read the given context into an executionstate.
216 *******************************************************************************/
218 void md_executionstate_read(executionstate_t *es, void *context)
224 _uc = (ucontext_t *) context;
225 _mc = &_uc->uc_mcontext;
227 /* read special registers */
228 es->pc = (u1 *) _mc->sc_pc;
229 es->sp = (u1 *) _mc->sc_regs[REG_SP];
230 es->pv = (u1 *) _mc->sc_regs[REG_PV];
231 es->ra = (u1 *) _mc->sc_regs[REG_RA];
233 /* read integer registers */
234 for (i = 0; i < INT_REG_CNT; i++)
235 es->intregs[i] = _mc->sc_regs[i];
237 /* read float registers */
238 /* Do not use the assignment operator '=', as the type of
239 * the _mc->sc_fpregs[i] can cause invalid conversions. */
241 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
242 system_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
246 /* md_executionstate_write *****************************************************
248 Write the given executionstate back to the context.
250 *******************************************************************************/
252 void md_executionstate_write(executionstate_t *es, void *context)
258 _uc = (ucontext_t *) context;
259 _mc = &_uc->uc_mcontext;
261 /* write integer registers */
262 for (i = 0; i < INT_REG_CNT; i++)
263 _mc->sc_regs[i] = es->intregs[i];
265 /* write float registers */
266 /* Do not use the assignment operator '=', as the type of
267 * the _mc->sc_fpregs[i] can cause invalid conversions. */
269 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
270 system_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
272 /* write special registers */
273 _mc->sc_pc = (ptrint) es->pc;
274 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
275 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
276 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
280 /* md_critical_section_restart *************************************************
282 Search the critical sections tree for a matching section and set
283 the PC to the restart point, if necessary.
285 *******************************************************************************/
287 #if defined(ENABLE_THREADS)
288 void md_critical_section_restart(ucontext_t *_uc)
294 _mc = &_uc->uc_mcontext;
296 pc = (u1 *) _mc->sc_pc;
298 npc = critical_find_restart_point(pc);
301 _mc->sc_pc = (ptrint) npc;
307 * These are local overrides for various environment variables in Emacs.
308 * Please do not remove this and leave it at the end of the file, where
309 * Emacs will automagically detect them.
310 * ---------------------------------------------------------------------
313 * indent-tabs-mode: t