1 /* src/vm/jit/powerpc/linux/md-os.c - machine dependent PowerPC 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/powerpc/codegen.h"
39 #include "vm/jit/powerpc/linux/md-abi.h"
41 #if defined(ENABLE_THREADS)
42 # include "threads/native/threads.h"
45 #include "vm/exceptions.h"
46 #include "vm/signallocal.h"
47 #include "vm/stringlocal.h"
48 #include "vm/jit/asmpart.h"
50 #if defined(ENABLE_PROFILING)
51 # include "vm/jit/optimizing/profile.h"
54 #include "vm/jit/stacktrace.h"
57 /* md_signal_handler_sigsegv ***************************************************
59 Signal handler for hardware-exceptions.
61 *******************************************************************************/
63 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
68 unsigned long *_gregs;
82 _uc = (ucontext_t *) _p;
84 #if defined(__UCLIBC__)
85 _mc = &(_uc->uc_mcontext);
86 _gregs = _mc->regs->gpr;
88 _mc = _uc->uc_mcontext.uc_regs;
92 pv = (u1 *) _gregs[REG_PV];
93 sp = (u1 *) _gregs[REG_SP];
94 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
95 xpc = (u1 *) _gregs[PT_NIP];
97 /* get exception-throwing instruction */
99 mcode = *((u4 *) xpc);
101 s1 = M_INSTR_OP2_IMM_A(mcode);
102 disp = M_INSTR_OP2_IMM_I(mcode);
103 d = M_INSTR_OP2_IMM_D(mcode);
107 /* check for special-load */
109 if (s1 == REG_ZERO) {
110 /* we use the exception type as load displacement */
115 /* This is a normal NPE: addr must be NULL and the NPE-type
119 type = EXCEPTION_HARDWARE_NULLPOINTER;
122 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
125 /* create stackframeinfo */
127 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
129 /* Handle the type. */
131 p = signal_handle(xpc, type, val);
133 /* remove stackframeinfo */
135 stacktrace_remove_stackframeinfo(&sfi);
137 /* set registers (only if exception object ready) */
140 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
141 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
142 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
147 /* md_signal_handler_sigtrap ***************************************************
149 Signal handler for hardware-traps.
151 *******************************************************************************/
153 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
158 unsigned long *_gregs;
169 _uc = (ucontext_t *) _p;
171 #if defined(__UCLIBC__)
172 _mc = &(_uc->uc_mcontext);
173 _gregs = _mc->regs->gpr;
175 _mc = _uc->uc_mcontext.uc_regs;
179 pv = (u1 *) _gregs[REG_PV];
180 sp = (u1 *) _gregs[REG_SP];
181 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
182 xpc = (u1 *) _gregs[PT_NIP];
184 /* get exception-throwing instruction */
186 mcode = *((u4 *) xpc);
188 s1 = M_OP3_GET_A(mcode);
190 /* for now we only handle ArrayIndexOutOfBoundsException */
192 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
195 /* create stackframeinfo */
197 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
199 /* Handle the type. */
201 p = signal_handle(xpc, type, val);
203 /* remove stackframeinfo */
205 stacktrace_remove_stackframeinfo(&sfi);
209 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
210 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
211 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
215 /* md_signal_handler_sigusr2 ***************************************************
217 Signal handler for profiling sampling.
219 *******************************************************************************/
221 #if defined(ENABLE_THREADS)
222 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
227 unsigned long *_gregs;
232 _uc = (ucontext_t *) _p;
234 #if defined(__UCLIBC__)
235 _mc = &(_uc->uc_mcontext);
236 _gregs = _mc->regs->gpr;
238 _mc = _uc->uc_mcontext.uc_regs;
242 pc = (u1 *) _gregs[PT_NIP];
249 /* md_critical_section_restart *************************************************
251 Search the critical sections tree for a matching section and set
252 the PC to the restart point, if necessary.
254 *******************************************************************************/
256 #if defined(ENABLE_THREADS)
257 void md_critical_section_restart(ucontext_t *_uc)
260 unsigned long *_gregs;
264 #if defined(__UCLIBC__)
265 _mc = &(_uc->uc_mcontext);
266 _gregs = _mc->regs->gpr;
268 _mc = _uc->uc_mcontext.uc_regs;
272 pc = (u1 *) _gregs[PT_NIP];
274 npc = critical_find_restart_point(pc);
277 _gregs[PT_NIP] = (ptrint) npc;
283 * These are local overrides for various environment variables in Emacs.
284 * Please do not remove this and leave it at the end of the file, where
285 * Emacs will automagically detect them.
286 * ---------------------------------------------------------------------
289 * indent-tabs-mode: t