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/md.h"
38 #include "vm/jit/powerpc/linux/md-abi.h"
40 #if defined(ENABLE_THREADS)
41 # include "threads/native/threads.h"
44 #include "vm/builtin.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)
67 unsigned long *_gregs;
81 _uc = (ucontext_t *) _p;
83 #if defined(__UCLIBC__)
84 _mc = &(_uc->uc_mcontext);
85 _gregs = _mc->regs->gpr;
87 _mc = _uc->uc_mcontext.uc_regs;
91 pv = (u1 *) _gregs[REG_PV];
92 sp = (u1 *) _gregs[REG_SP];
93 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
94 xpc = (u1 *) _gregs[PT_NIP];
96 /* get exception-throwing instruction */
98 mcode = *((u4 *) xpc);
100 s1 = M_INSTR_OP2_IMM_A(mcode);
101 disp = M_INSTR_OP2_IMM_I(mcode);
102 d = M_INSTR_OP2_IMM_D(mcode);
106 /* check for special-load */
108 if (s1 == REG_ZERO) {
109 /* we use the exception type as load displacement */
113 if (type == EXCEPTION_HARDWARE_COMPILER) {
114 /* The XPC is the RA minus 4, because the RA points to the
115 instruction after the call. */
121 /* This is a normal NPE: addr must be NULL and the NPE-type
125 type = EXCEPTION_HARDWARE_NULLPOINTER;
128 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
131 /* Handle the type. */
133 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
138 case EXCEPTION_HARDWARE_COMPILER:
140 _gregs[REG_PV] = (uintptr_t) p;
141 _gregs[PT_NIP] = (uintptr_t) p;
145 /* Get and set the PV from the parent Java method. */
147 pv = md_codegen_get_pv_from_pc(ra);
149 _gregs[REG_PV] = (uintptr_t) pv;
151 /* Get the exception object. */
153 p = builtin_retrieve_exception();
159 case EXCEPTION_HARDWARE_PATCHER:
166 _gregs[REG_ITMP1_XPTR] = (uintptr_t) p;
167 _gregs[REG_ITMP2_XPC] = (uintptr_t) xpc;
168 _gregs[PT_NIP] = (uintptr_t) asm_handle_exception;
173 /* md_signal_handler_sigtrap ***************************************************
175 Signal handler for hardware-traps.
177 *******************************************************************************/
179 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
183 unsigned long *_gregs;
194 _uc = (ucontext_t *) _p;
196 #if defined(__UCLIBC__)
197 _mc = &(_uc->uc_mcontext);
198 _gregs = _mc->regs->gpr;
200 _mc = _uc->uc_mcontext.uc_regs;
204 pv = (u1 *) _gregs[REG_PV];
205 sp = (u1 *) _gregs[REG_SP];
206 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
207 xpc = (u1 *) _gregs[PT_NIP];
209 /* get exception-throwing instruction */
211 mcode = *((u4 *) xpc);
213 s1 = M_OP3_GET_A(mcode);
215 /* for now we only handle ArrayIndexOutOfBoundsException */
217 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
220 /* Handle the type. */
222 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
226 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
227 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
228 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
232 /* md_signal_handler_sigusr1 ***************************************************
234 Signal handler for suspending threads.
236 *******************************************************************************/
238 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
239 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
243 unsigned long *_gregs;
247 _uc = (ucontext_t *) _p;
249 #if defined(__UCLIBC__)
250 _mc = &(_uc->uc_mcontext);
251 _gregs = _mc->regs->gpr;
253 _mc = _uc->uc_mcontext.uc_regs;
257 /* get the PC and SP for this thread */
259 pc = (u1 *) _gregs[PT_NIP];
260 sp = (u1 *) _gregs[REG_SP];
262 /* now suspend the current thread */
264 threads_suspend_ack(pc, sp);
269 /* md_signal_handler_sigusr2 ***************************************************
271 Signal handler for profiling sampling.
273 *******************************************************************************/
275 #if defined(ENABLE_THREADS)
276 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
281 unsigned long *_gregs;
286 _uc = (ucontext_t *) _p;
288 #if defined(__UCLIBC__)
289 _mc = &(_uc->uc_mcontext);
290 _gregs = _mc->regs->gpr;
292 _mc = _uc->uc_mcontext.uc_regs;
296 pc = (u1 *) _gregs[PT_NIP];
303 /* md_critical_section_restart *************************************************
305 Search the critical sections tree for a matching section and set
306 the PC to the restart point, if necessary.
308 *******************************************************************************/
310 #if defined(ENABLE_THREADS)
311 void md_critical_section_restart(ucontext_t *_uc)
314 unsigned long *_gregs;
318 #if defined(__UCLIBC__)
319 _mc = &(_uc->uc_mcontext);
320 _gregs = _mc->regs->gpr;
322 _mc = _uc->uc_mcontext.uc_regs;
326 pc = (u1 *) _gregs[PT_NIP];
328 npc = critical_find_restart_point(pc);
331 _gregs[PT_NIP] = (ptrint) npc;
337 * These are local overrides for various environment variables in Emacs.
338 * Please do not remove this and leave it at the end of the file, where
339 * Emacs will automagically detect them.
340 * ---------------------------------------------------------------------
343 * indent-tabs-mode: t