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/exceptions.h"
44 #include "vm/signallocal.h"
45 #include "vm/stringlocal.h"
46 #include "vm/jit/asmpart.h"
48 #if defined(ENABLE_PROFILING)
49 # include "vm/jit/optimizing/profile.h"
52 #include "vm/jit/stacktrace.h"
55 /* md_signal_handler_sigsegv ***************************************************
57 Signal handler for hardware-exceptions.
59 *******************************************************************************/
61 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
65 unsigned long *_gregs;
79 _uc = (ucontext_t *) _p;
81 #if defined(__UCLIBC__)
82 _mc = &(_uc->uc_mcontext);
83 _gregs = _mc->regs->gpr;
85 _mc = _uc->uc_mcontext.uc_regs;
89 pv = (u1 *) _gregs[REG_PV];
90 sp = (u1 *) _gregs[REG_SP];
91 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
92 xpc = (u1 *) _gregs[PT_NIP];
94 /* get exception-throwing instruction */
96 mcode = *((u4 *) xpc);
98 s1 = M_INSTR_OP2_IMM_A(mcode);
99 disp = M_INSTR_OP2_IMM_I(mcode);
100 d = M_INSTR_OP2_IMM_D(mcode);
104 /* check for special-load */
106 if (s1 == REG_ZERO) {
107 /* we use the exception type as load displacement */
112 /* This is a normal NPE: addr must be NULL and the NPE-type
116 type = EXCEPTION_HARDWARE_NULLPOINTER;
119 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
122 /* Handle the type. */
124 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
126 /* set registers (only if exception object ready) */
129 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
130 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
131 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
136 /* md_signal_handler_sigtrap ***************************************************
138 Signal handler for hardware-traps.
140 *******************************************************************************/
142 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
146 unsigned long *_gregs;
157 _uc = (ucontext_t *) _p;
159 #if defined(__UCLIBC__)
160 _mc = &(_uc->uc_mcontext);
161 _gregs = _mc->regs->gpr;
163 _mc = _uc->uc_mcontext.uc_regs;
167 pv = (u1 *) _gregs[REG_PV];
168 sp = (u1 *) _gregs[REG_SP];
169 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
170 xpc = (u1 *) _gregs[PT_NIP];
172 /* get exception-throwing instruction */
174 mcode = *((u4 *) xpc);
176 s1 = M_OP3_GET_A(mcode);
178 /* for now we only handle ArrayIndexOutOfBoundsException */
180 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
183 /* Handle the type. */
185 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
189 _gregs[REG_ITMP1_XPTR] = (intptr_t) p;
190 _gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
191 _gregs[PT_NIP] = (intptr_t) asm_handle_exception;
195 /* md_signal_handler_sigusr1 ***************************************************
197 Signal handler for suspending threads.
199 *******************************************************************************/
201 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
202 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
206 unsigned long *_gregs;
210 _uc = (ucontext_t *) _p;
212 #if defined(__UCLIBC__)
213 _mc = &(_uc->uc_mcontext);
214 _gregs = _mc->regs->gpr;
216 _mc = _uc->uc_mcontext.uc_regs;
220 /* get the PC and SP for this thread */
222 pc = (u1 *) _gregs[PT_NIP];
223 sp = (u1 *) _gregs[REG_SP];
225 /* now suspend the current thread */
227 threads_suspend_ack(pc, sp);
232 /* md_signal_handler_sigusr2 ***************************************************
234 Signal handler for profiling sampling.
236 *******************************************************************************/
238 #if defined(ENABLE_THREADS)
239 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
244 unsigned long *_gregs;
249 _uc = (ucontext_t *) _p;
251 #if defined(__UCLIBC__)
252 _mc = &(_uc->uc_mcontext);
253 _gregs = _mc->regs->gpr;
255 _mc = _uc->uc_mcontext.uc_regs;
259 pc = (u1 *) _gregs[PT_NIP];
266 /* md_critical_section_restart *************************************************
268 Search the critical sections tree for a matching section and set
269 the PC to the restart point, if necessary.
271 *******************************************************************************/
273 #if defined(ENABLE_THREADS)
274 void md_critical_section_restart(ucontext_t *_uc)
277 unsigned long *_gregs;
281 #if defined(__UCLIBC__)
282 _mc = &(_uc->uc_mcontext);
283 _gregs = _mc->regs->gpr;
285 _mc = _uc->uc_mcontext.uc_regs;
289 pc = (u1 *) _gregs[PT_NIP];
291 npc = critical_find_restart_point(pc);
294 _gregs[PT_NIP] = (ptrint) npc;
300 * These are local overrides for various environment variables in Emacs.
301 * Please do not remove this and leave it at the end of the file, where
302 * Emacs will automagically detect them.
303 * ---------------------------------------------------------------------
306 * indent-tabs-mode: t