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 7605 2007-03-29 11:04:25Z twisti $
37 #include "vm/jit/powerpc/codegen.h"
38 #include "vm/jit/powerpc/linux/md-abi.h"
40 #if defined(ENABLE_THREADS)
41 # include "threads/native/threads.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)
79 _uc = (ucontext_t *) _p;
80 _mc = _uc->uc_mcontext.uc_regs;
82 pv = (u1 *) _mc->gregs[REG_PV];
83 sp = (u1 *) _mc->gregs[REG_SP];
84 ra = (u1 *) _mc->gregs[PT_LNK]; /* this is correct for leafs */
85 xpc = (u1 *) _mc->gregs[PT_NIP];
87 /* get exception-throwing instruction */
89 mcode = *((u4 *) xpc);
91 s1 = M_INSTR_OP2_IMM_A(mcode);
92 disp = M_INSTR_OP2_IMM_I(mcode);
93 d = M_INSTR_OP2_IMM_D(mcode);
97 /* check for special-load */
100 /* we use the exception type as load displacement */
105 /* This is a normal NPE: addr must be NULL and the NPE-type
108 addr = _mc->gregs[s1];
111 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
116 /* generate appropriate exception */
118 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
122 _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
123 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
124 _mc->gregs[PT_NIP] = (ptrint) asm_handle_exception;
128 /* md_signal_handler_sigtrap ***************************************************
130 Signal handler for hardware-traps.
132 *******************************************************************************/
134 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
146 java_objectheader *o;
148 _uc = (ucontext_t *) _p;
149 _mc = _uc->uc_mcontext.uc_regs;
151 pv = (u1 *) _mc->gregs[REG_PV];
152 sp = (u1 *) _mc->gregs[REG_SP];
153 ra = (u1 *) _mc->gregs[PT_LNK]; /* this is correct for leafs */
154 xpc = (u1 *) _mc->gregs[PT_NIP];
156 /* get exception-throwing instruction */
158 mcode = *((u4 *) xpc);
160 s1 = M_OP3_GET_A(mcode);
162 /* for now we only handle ArrayIndexOutOfBoundsException */
164 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
165 val = _mc->gregs[s1];
167 /* generate appropriate exception */
169 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
173 _mc->gregs[REG_ITMP1_XPTR] = (ptrint) o;
174 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
175 _mc->gregs[PT_NIP] = (ptrint) asm_handle_exception;
179 /* md_signal_handler_sigusr2 ***************************************************
181 Signal handler for profiling sampling.
183 *******************************************************************************/
185 #if defined(ENABLE_THREADS)
186 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
195 _uc = (ucontext_t *) _p;
196 _mc = _uc->uc_mcontext.uc_regs;
198 pc = (u1 *) _mc->gregs[PT_NIP];
204 void thread_restartcriticalsection(ucontext_t *_uc)
210 _mc = _uc->uc_mcontext.uc_regs;
212 pc = (u1 *) _mc->gregs[PT_NIP];
214 critical = critical_find_restart_point(pc);
217 _mc->gregs[PT_NIP] = (ptrint) critical;
223 * These are local overrides for various environment variables in Emacs.
224 * Please do not remove this and leave it at the end of the file, where
225 * Emacs will automagically detect them.
226 * ---------------------------------------------------------------------
229 * indent-tabs-mode: t