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/signallocal.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/stacktrace.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 */
99 /* This is a normal NPE: addr must be NULL and the NPE-type
102 addr = _mc->sc_regs[s1];
106 /* Handle the type. */
108 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
113 _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
114 _mc->sc_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
115 _mc->sc_pc = (intptr_t) asm_handle_exception;
120 /* md_signal_handler_sigusr1 ***************************************************
122 Signal handler for suspending threads.
124 *******************************************************************************/
126 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
127 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
134 _uc = (ucontext_t *) _p;
135 _mc = &_uc->uc_mcontext;
137 /* get the PC and SP for this thread */
138 pc = (u1 *) _mc->sc_pc;
139 sp = (u1 *) _mc->sc_regs[REG_SP];
141 /* now suspend the current thread */
142 threads_suspend_ack(pc, sp);
147 /* md_signal_handler_sigusr2 ***************************************************
149 Signal handler for profiling sampling.
151 *******************************************************************************/
153 #if defined(ENABLE_THREADS)
154 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
163 _uc = (ucontext_t *) _p;
164 _mc = &_uc->uc_mcontext;
166 pc = (u1 *) _mc->sc_pc;
173 /* md_replace_executionstate_read **********************************************
175 Read the given context into an executionstate for Replacement.
177 *******************************************************************************/
179 #if defined(ENABLE_REPLACEMENT)
180 void md_replace_executionstate_read(executionstate_t *es, void *context)
186 _uc = (ucontext_t *) context;
187 _mc = &_uc->uc_mcontext;
189 /* read special registers */
190 es->pc = (u1 *) _mc->sc_pc;
191 es->sp = (u1 *) _mc->sc_regs[REG_SP];
192 es->pv = (u1 *) _mc->sc_regs[REG_PV];
194 /* read integer registers */
195 for (i = 0; i < INT_REG_CNT; i++)
196 es->intregs[i] = _mc->sc_regs[i];
198 /* read float registers */
199 for (i = 0; i < FLT_REG_CNT; i++)
200 es->fltregs[i] = _mc->sc_fpregs[i];
205 /* md_replace_executionstate_write *********************************************
207 Write the given executionstate back to the context for Replacement.
209 *******************************************************************************/
211 #if defined(ENABLE_REPLACEMENT)
212 void md_replace_executionstate_write(executionstate_t *es, void *context)
218 _uc = (ucontext_t *) context;
219 _mc = &_uc->uc_mcontext;
221 /* write integer registers */
222 for (i = 0; i < INT_REG_CNT; i++)
223 _mc->sc_regs[i] = es->intregs[i];
225 /* write float registers */
226 for (i = 0; i < FLT_REG_CNT; i++)
227 _mc->sc_fpregs[i] = es->fltregs[i];
229 /* write special registers */
230 _mc->sc_pc = (ptrint) es->pc;
231 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
232 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
237 /* md_critical_section_restart *************************************************
239 Search the critical sections tree for a matching section and set
240 the PC to the restart point, if necessary.
242 *******************************************************************************/
244 #if defined(ENABLE_THREADS)
245 void md_critical_section_restart(ucontext_t *_uc)
251 _mc = &_uc->uc_mcontext;
253 pc = (u1 *) _mc->sc_pc;
255 npc = critical_find_restart_point(pc);
258 _mc->sc_pc = (ptrint) npc;
264 * These are local overrides for various environment variables in Emacs.
265 * Please do not remove this and leave it at the end of the file, where
266 * Emacs will automagically detect them.
267 * ---------------------------------------------------------------------
270 * indent-tabs-mode: t