1 /* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 #include "vm/jit/alpha/codegen.h"
37 #include "vm/jit/alpha/md.h"
38 #include "vm/jit/alpha/md-abi.h"
40 #if defined(ENABLE_THREADS)
41 # include "threads/native/threads.h"
44 #include "vm/builtin.h"
45 #include "vm/exceptions.h"
46 #include "vm/signallocal.h"
48 #include "vm/jit/asmpart.h"
49 #include "vm/jit/stacktrace.h"
52 /* md_signal_handler_sigsegv ***************************************************
54 NullPointerException signal handler for hardware null pointer
57 *******************************************************************************/
59 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
76 _uc = (ucontext_t *) _p;
77 _mc = &_uc->uc_mcontext;
79 pv = (u1 *) _mc->sc_regs[REG_PV];
80 sp = (u1 *) _mc->sc_regs[REG_SP];
81 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
82 xpc = (u1 *) _mc->sc_pc;
84 /* get exception-throwing instruction */
86 mcode = *((u4 *) xpc);
88 d = M_MEM_GET_Ra(mcode);
89 s1 = M_MEM_GET_Rb(mcode);
90 disp = M_MEM_GET_Memory_disp(mcode);
92 val = _mc->sc_regs[d];
94 /* check for special-load */
97 /* we use the exception type as load displacement */
101 if (type == EXCEPTION_HARDWARE_COMPILER) {
102 /* The XPC is the RA minus 1, because the RA points to the
103 instruction after the call. */
109 /* This is a normal NPE: addr must be NULL and the NPE-type
112 addr = _mc->sc_regs[s1];
116 /* Handle the type. */
118 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
123 case EXCEPTION_HARDWARE_COMPILER:
125 _mc->sc_regs[REG_PV] = (uintptr_t) p;
126 _mc->sc_pc = (uintptr_t) p;
130 /* Get and set the PV from the parent Java method. */
132 pv = md_codegen_get_pv_from_pc(ra);
134 _mc->sc_regs[REG_PV] = (uintptr_t) pv;
136 /* Get the exception object. */
138 p = builtin_retrieve_exception();
144 case EXCEPTION_HARDWARE_PATCHER:
151 _mc->sc_regs[REG_ITMP1_XPTR] = (uintptr_t) p;
152 _mc->sc_regs[REG_ITMP2_XPC] = (uintptr_t) xpc;
153 _mc->sc_pc = (uintptr_t) asm_handle_exception;
158 /* md_signal_handler_sigusr1 ***************************************************
160 Signal handler for suspending threads.
162 *******************************************************************************/
164 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
165 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
172 _uc = (ucontext_t *) _p;
173 _mc = &_uc->uc_mcontext;
175 /* get the PC and SP for this thread */
176 pc = (u1 *) _mc->sc_pc;
177 sp = (u1 *) _mc->sc_regs[REG_SP];
179 /* now suspend the current thread */
180 threads_suspend_ack(pc, sp);
185 /* md_signal_handler_sigusr2 ***************************************************
187 Signal handler for profiling sampling.
189 *******************************************************************************/
191 #if defined(ENABLE_THREADS)
192 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
201 _uc = (ucontext_t *) _p;
202 _mc = &_uc->uc_mcontext;
204 pc = (u1 *) _mc->sc_pc;
211 /* md_replace_executionstate_read **********************************************
213 Read the given context into an executionstate for Replacement.
215 *******************************************************************************/
217 #if defined(ENABLE_REPLACEMENT)
218 void md_replace_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 memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
247 /* md_replace_executionstate_write *********************************************
249 Write the given executionstate back to the context for Replacement.
251 *******************************************************************************/
253 #if defined(ENABLE_REPLACEMENT)
254 void md_replace_executionstate_write(executionstate_t *es, void *context)
260 _uc = (ucontext_t *) context;
261 _mc = &_uc->uc_mcontext;
263 /* write integer registers */
264 for (i = 0; i < INT_REG_CNT; i++)
265 _mc->sc_regs[i] = es->intregs[i];
267 /* write float registers */
268 /* Do not use the assignment operator '=', as the type of
269 * the _mc->sc_fpregs[i] can cause invalid conversions. */
271 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
272 memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
274 /* write special registers */
275 _mc->sc_pc = (ptrint) es->pc;
276 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
277 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
278 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
283 /* md_critical_section_restart *************************************************
285 Search the critical sections tree for a matching section and set
286 the PC to the restart point, if necessary.
288 *******************************************************************************/
290 #if defined(ENABLE_THREADS)
291 void md_critical_section_restart(ucontext_t *_uc)
297 _mc = &_uc->uc_mcontext;
299 pc = (u1 *) _mc->sc_pc;
301 npc = critical_find_restart_point(pc);
304 _mc->sc_pc = (ptrint) npc;
310 * These are local overrides for various environment variables in Emacs.
311 * Please do not remove this and leave it at the end of the file, where
312 * Emacs will automagically detect them.
313 * ---------------------------------------------------------------------
316 * indent-tabs-mode: t