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-abi.h"
39 #if defined(ENABLE_THREADS)
40 # include "threads/native/threads.h"
43 #include "vm/builtin.h"
44 #include "vm/exceptions.h"
45 #include "vm/signallocal.h"
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.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 == EXCEPTION_HARDWARE_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 type. */
117 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
122 case EXCEPTION_HARDWARE_COMPILER:
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();
143 case EXCEPTION_HARDWARE_PATCHER:
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_replace_executionstate_read **********************************************
212 Read the given context into an executionstate for Replacement.
214 *******************************************************************************/
216 #if defined(ENABLE_REPLACEMENT)
217 void md_replace_executionstate_read(executionstate_t *es, void *context)
223 _uc = (ucontext_t *) context;
224 _mc = &_uc->uc_mcontext;
226 /* read special registers */
227 es->pc = (u1 *) _mc->sc_pc;
228 es->sp = (u1 *) _mc->sc_regs[REG_SP];
229 es->pv = (u1 *) _mc->sc_regs[REG_PV];
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 for (i = 0; i < FLT_REG_CNT; i++)
237 es->fltregs[i] = _mc->sc_fpregs[i];
242 /* md_replace_executionstate_write *********************************************
244 Write the given executionstate back to the context for Replacement.
246 *******************************************************************************/
248 #if defined(ENABLE_REPLACEMENT)
249 void md_replace_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 for (i = 0; i < FLT_REG_CNT; i++)
264 _mc->sc_fpregs[i] = es->fltregs[i];
266 /* write special registers */
267 _mc->sc_pc = (ptrint) es->pc;
268 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
269 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
274 /* md_critical_section_restart *************************************************
276 Search the critical sections tree for a matching section and set
277 the PC to the restart point, if necessary.
279 *******************************************************************************/
281 #if defined(ENABLE_THREADS)
282 void md_critical_section_restart(ucontext_t *_uc)
288 _mc = &_uc->uc_mcontext;
290 pc = (u1 *) _mc->sc_pc;
292 npc = critical_find_restart_point(pc);
295 _mc->sc_pc = (ptrint) npc;
301 * These are local overrides for various environment variables in Emacs.
302 * Please do not remove this and leave it at the end of the file, where
303 * Emacs will automagically detect them.
304 * ---------------------------------------------------------------------
307 * indent-tabs-mode: t