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
25 $Id: md-os.c 8283 2007-08-09 15:10:05Z twisti $
38 #include "vm/jit/alpha/codegen.h"
39 #include "vm/jit/alpha/md-abi.h"
41 #if defined(ENABLE_THREADS)
42 # include "threads/native/threads.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)
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_A(mcode);
89 s1 = M_MEM_GET_B(mcode);
90 disp = M_MEM_GET_DISP(mcode);
92 val = _mc->sc_regs[d];
94 /* check for special-load */
97 /* we use the exception type as load displacement */
102 /* This is a normal NPE: addr must be NULL and the NPE-type
105 addr = _mc->sc_regs[s1];
109 /* create stackframeinfo */
111 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
113 /* Handle the type. */
115 p = signal_handle(xpc, type, val);
117 /* remove stackframeinfo */
119 stacktrace_remove_stackframeinfo(&sfi);
124 _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
125 _mc->sc_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
126 _mc->sc_pc = (intptr_t) asm_handle_exception;
131 /* md_signal_handler_sigusr2 ***************************************************
133 Signal handler for profiling sampling.
135 *******************************************************************************/
137 #if defined(ENABLE_THREADS)
138 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
147 _uc = (ucontext_t *) _p;
148 _mc = &_uc->uc_mcontext;
150 pc = (u1 *) _mc->sc_pc;
157 /* md_replace_executionstate_read **********************************************
159 Read the given context into an executionstate for Replacement.
161 *******************************************************************************/
163 #if defined(ENABLE_REPLACEMENT)
164 void md_replace_executionstate_read(executionstate_t *es, void *context)
170 _uc = (ucontext_t *) context;
171 _mc = &_uc->uc_mcontext;
173 /* read special registers */
174 es->pc = (u1 *) _mc->sc_pc;
175 es->sp = (u1 *) _mc->sc_regs[REG_SP];
176 es->pv = (u1 *) _mc->sc_regs[REG_PV];
178 /* read integer registers */
179 for (i = 0; i < INT_REG_CNT; i++)
180 es->intregs[i] = _mc->sc_regs[i];
182 /* read float registers */
183 for (i = 0; i < FLT_REG_CNT; i++)
184 es->fltregs[i] = _mc->sc_fpregs[i];
189 /* md_replace_executionstate_write *********************************************
191 Write the given executionstate back to the context for Replacement.
193 *******************************************************************************/
195 #if defined(ENABLE_REPLACEMENT)
196 void md_replace_executionstate_write(executionstate_t *es, void *context)
202 _uc = (ucontext_t *) context;
203 _mc = &_uc->uc_mcontext;
205 /* write integer registers */
206 for (i = 0; i < INT_REG_CNT; i++)
207 _mc->sc_regs[i] = es->intregs[i];
209 /* write float registers */
210 for (i = 0; i < FLT_REG_CNT; i++)
211 _mc->sc_fpregs[i] = es->fltregs[i];
213 /* write special registers */
215 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
216 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
221 /* md_critical_section_restart *************************************************
223 Search the critical sections tree for a matching section and set
224 the PC to the restart point, if necessary.
226 *******************************************************************************/
228 #if defined(ENABLE_THREADS)
229 void md_critical_section_restart(ucontext_t *_uc)
235 _mc = &_uc->uc_mcontext;
237 pc = (u1 *) _mc->sc_pc;
239 npc = critical_find_restart_point(pc);
242 _mc->sc_pc = (ptrint) npc;
248 * These are local overrides for various environment variables in Emacs.
249 * Please do not remove this and leave it at the end of the file, where
250 * Emacs will automagically detect them.
251 * ---------------------------------------------------------------------
254 * indent-tabs-mode: t