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
36 #include "vm/jit/powerpc/codegen.h"
37 #include "vm/jit/powerpc/linux/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"
46 #include "vm/stringlocal.h"
47 #include "vm/jit/asmpart.h"
49 #if defined(ENABLE_PROFILING)
50 # include "vm/jit/optimizing/profile.h"
53 #include "vm/jit/stacktrace.h"
56 /* md_signal_handler_sigsegv ***************************************************
58 Signal handler for hardware-exceptions.
60 *******************************************************************************/
62 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
66 unsigned long *_gregs;
80 _uc = (ucontext_t *) _p;
82 #if defined(__UCLIBC__)
83 _mc = &(_uc->uc_mcontext);
84 _gregs = _mc->regs->gpr;
86 _mc = _uc->uc_mcontext.uc_regs;
90 pv = (u1 *) _gregs[REG_PV];
91 sp = (u1 *) _gregs[REG_SP];
92 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
93 xpc = (u1 *) _gregs[PT_NIP];
95 /* get exception-throwing instruction */
97 mcode = *((u4 *) xpc);
99 s1 = M_INSTR_OP2_IMM_A(mcode);
100 disp = M_INSTR_OP2_IMM_I(mcode);
101 d = M_INSTR_OP2_IMM_D(mcode);
105 /* check for special-load */
107 if (s1 == REG_ZERO) {
108 /* we use the exception type as load displacement */
112 if (type == EXCEPTION_HARDWARE_COMPILER) {
113 /* The XPC is the RA minus 4, because the RA points to the
114 instruction after the call. */
120 /* This is a normal NPE: addr must be NULL and the NPE-type
124 type = EXCEPTION_HARDWARE_NULLPOINTER;
127 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
130 /* Handle the type. */
132 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
137 case EXCEPTION_HARDWARE_COMPILER:
139 _gregs[REG_PV] = (uintptr_t) p;
140 _gregs[PT_NIP] = (uintptr_t) p;
144 /* Get and set the PV from the parent Java method. */
146 pv = md_codegen_get_pv_from_pc(ra);
148 _gregs[REG_PV] = (uintptr_t) pv;
150 /* Get the exception object. */
152 p = builtin_retrieve_exception();
158 case EXCEPTION_HARDWARE_PATCHER:
165 _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
166 _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
167 _gregs[PT_NIP] = (uintptr_t) asm_handle_exception;
172 /* md_signal_handler_sigtrap ***************************************************
174 Signal handler for hardware-traps.
176 *******************************************************************************/
178 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
182 unsigned long *_gregs;
193 _uc = (ucontext_t *) _p;
195 #if defined(__UCLIBC__)
196 _mc = &(_uc->uc_mcontext);
197 _gregs = _mc->regs->gpr;
199 _mc = _uc->uc_mcontext.uc_regs;
203 pv = (u1 *) _gregs[REG_PV];
204 sp = (u1 *) _gregs[REG_SP];
205 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
206 xpc = (u1 *) _gregs[PT_NIP];
208 /* get exception-throwing instruction */
210 mcode = *((u4 *) xpc);
212 s1 = M_OP3_GET_A(mcode);
214 /* for now we only handle ArrayIndexOutOfBoundsException */
216 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
219 /* Handle the type. */
221 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
225 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
226 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
227 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
231 /* md_signal_handler_sigusr1 ***************************************************
233 Signal handler for suspending threads.
235 *******************************************************************************/
237 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
238 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
242 unsigned long *_gregs;
246 _uc = (ucontext_t *) _p;
248 #if defined(__UCLIBC__)
249 _mc = &(_uc->uc_mcontext);
250 _gregs = _mc->regs->gpr;
252 _mc = _uc->uc_mcontext.uc_regs;
256 /* get the PC and SP for this thread */
258 pc = (u1 *) _gregs[PT_NIP];
259 sp = (u1 *) _gregs[REG_SP];
261 /* now suspend the current thread */
263 threads_suspend_ack(pc, sp);
268 /* md_signal_handler_sigusr2 ***************************************************
270 Signal handler for profiling sampling.
272 *******************************************************************************/
274 #if defined(ENABLE_THREADS)
275 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
280 unsigned long *_gregs;
285 _uc = (ucontext_t *) _p;
287 #if defined(__UCLIBC__)
288 _mc = &(_uc->uc_mcontext);
289 _gregs = _mc->regs->gpr;
291 _mc = _uc->uc_mcontext.uc_regs;
295 pc = (u1 *) _gregs[PT_NIP];
302 /* md_critical_section_restart *************************************************
304 Search the critical sections tree for a matching section and set
305 the PC to the restart point, if necessary.
307 *******************************************************************************/
309 #if defined(ENABLE_THREADS)
310 void md_critical_section_restart(ucontext_t *_uc)
313 unsigned long *_gregs;
317 #if defined(__UCLIBC__)
318 _mc = &(_uc->uc_mcontext);
319 _gregs = _mc->regs->gpr;
321 _mc = _uc->uc_mcontext.uc_regs;
325 pc = (u1 *) _gregs[PT_NIP];
327 npc = critical_find_restart_point(pc);
330 _gregs[PT_NIP] = (ptrint) npc;
336 * These are local overrides for various environment variables in Emacs.
337 * Please do not remove this and leave it at the end of the file, where
338 * Emacs will automagically detect them.
339 * ---------------------------------------------------------------------
342 * indent-tabs-mode: t