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)
74 _uc = (ucontext_t *) _p;
75 _mc = &_uc->uc_mcontext;
77 pv = (u1 *) _mc->sc_regs[REG_PV];
78 sp = (u1 *) _mc->sc_regs[REG_SP];
79 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
80 xpc = (u1 *) _mc->sc_pc;
82 /* get exception-throwing instruction */
84 mcode = *((u4 *) xpc);
86 d = M_MEM_GET_A(mcode);
87 s1 = M_MEM_GET_B(mcode);
88 disp = M_MEM_GET_DISP(mcode);
90 val = _mc->sc_regs[d];
92 /* check for special-load */
95 /* we use the exception type as load displacement */
100 /* This is a normal NPE: addr must be NULL and the NPE-type
103 addr = _mc->sc_regs[s1];
107 /* create stackframeinfo */
109 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
111 /* Handle the type. */
113 p = signal_handle(xpc, type, val);
115 /* remove stackframeinfo */
117 stacktrace_remove_stackframeinfo(&sfi);
122 _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
123 _mc->sc_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
124 _mc->sc_pc = (intptr_t) asm_handle_exception;
129 /* md_signal_handler_sigusr2 ***************************************************
131 Signal handler for profiling sampling.
133 *******************************************************************************/
135 #if defined(ENABLE_THREADS)
136 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
145 _uc = (ucontext_t *) _p;
146 _mc = &_uc->uc_mcontext;
148 pc = (u1 *) _mc->sc_pc;
155 /* md_replace_executionstate_read **********************************************
157 Read the given context into an executionstate for Replacement.
159 *******************************************************************************/
161 #if defined(ENABLE_REPLACEMENT)
162 void md_replace_executionstate_read(executionstate_t *es, void *context)
168 _uc = (ucontext_t *) context;
169 _mc = &_uc->uc_mcontext;
171 /* read special registers */
172 es->pc = (u1 *) _mc->sc_pc;
173 es->sp = (u1 *) _mc->sc_regs[REG_SP];
174 es->pv = (u1 *) _mc->sc_regs[REG_PV];
176 /* read integer registers */
177 for (i = 0; i < INT_REG_CNT; i++)
178 es->intregs[i] = _mc->sc_regs[i];
180 /* read float registers */
181 for (i = 0; i < FLT_REG_CNT; i++)
182 es->fltregs[i] = _mc->sc_fpregs[i];
187 /* md_replace_executionstate_write *********************************************
189 Write the given executionstate back to the context for Replacement.
191 *******************************************************************************/
193 #if defined(ENABLE_REPLACEMENT)
194 void md_replace_executionstate_write(executionstate_t *es, void *context)
200 _uc = (ucontext_t *) context;
201 _mc = &_uc->uc_mcontext;
203 /* write integer registers */
204 for (i = 0; i < INT_REG_CNT; i++)
205 _mc->sc_regs[i] = es->intregs[i];
207 /* write float registers */
208 for (i = 0; i < FLT_REG_CNT; i++)
209 _mc->sc_fpregs[i] = es->fltregs[i];
211 /* write special registers */
213 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
214 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
219 /* md_critical_section_restart *************************************************
221 Search the critical sections tree for a matching section and set
222 the PC to the restart point, if necessary.
224 *******************************************************************************/
226 #if defined(ENABLE_THREADS)
227 void md_critical_section_restart(ucontext_t *_uc)
233 _mc = &_uc->uc_mcontext;
235 pc = (u1 *) _mc->sc_pc;
237 npc = critical_find_restart_point(pc);
240 _mc->sc_pc = (ptrint) npc;
246 * These are local overrides for various environment variables in Emacs.
247 * Please do not remove this and leave it at the end of the file, where
248 * Emacs will automagically detect them.
249 * ---------------------------------------------------------------------
252 * indent-tabs-mode: t