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 8243 2007-07-31 08:57:54Z michi $
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)
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 */
114 /* This is a normal NPE: addr must be NULL and the NPE-type
118 type = EXCEPTION_HARDWARE_NULLPOINTER;
121 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
124 /* create stackframeinfo */
126 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
128 /* generate appropriate exception */
130 e = exceptions_new_hardware_exception(xpc, type, val);
132 /* remove stackframeinfo */
134 stacktrace_remove_stackframeinfo(&sfi);
136 /* set registers (only if exception object ready) */
139 _gregs[REG_ITMP1_XPTR] = (ptrint) e;
140 _gregs[REG_ITMP2_XPC] = (ptrint) xpc;
141 _gregs[PT_NIP] = (ptrint) asm_handle_exception;
146 /* md_signal_handler_sigtrap ***************************************************
148 Signal handler for hardware-traps.
150 *******************************************************************************/
152 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
157 unsigned long *_gregs;
166 java_objectheader *e;
168 _uc = (ucontext_t *) _p;
170 #if defined(__UCLIBC__)
171 _mc = &(_uc->uc_mcontext);
172 _gregs = _mc->regs->gpr;
174 _mc = _uc->uc_mcontext.uc_regs;
178 pv = (u1 *) _gregs[REG_PV];
179 sp = (u1 *) _gregs[REG_SP];
180 ra = (u1 *) _gregs[PT_LNK]; /* this is correct for leafs */
181 xpc = (u1 *) _gregs[PT_NIP];
183 /* get exception-throwing instruction */
185 mcode = *((u4 *) xpc);
187 s1 = M_OP3_GET_A(mcode);
189 /* for now we only handle ArrayIndexOutOfBoundsException */
191 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
194 /* create stackframeinfo */
196 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
198 /* generate appropriate exception */
200 e = exceptions_new_hardware_exception(xpc, type, val);
202 /* remove stackframeinfo */
204 stacktrace_remove_stackframeinfo(&sfi);
208 _gregs[REG_ITMP1_XPTR] = (ptrint) e;
209 _gregs[REG_ITMP2_XPC] = (ptrint) xpc;
210 _gregs[PT_NIP] = (ptrint) asm_handle_exception;
214 /* md_signal_handler_sigusr2 ***************************************************
216 Signal handler for profiling sampling.
218 *******************************************************************************/
220 #if defined(ENABLE_THREADS)
221 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
226 unsigned long *_gregs;
231 _uc = (ucontext_t *) _p;
233 #if defined(__UCLIBC__)
234 _mc = &(_uc->uc_mcontext);
235 _gregs = _mc->regs->gpr;
237 _mc = _uc->uc_mcontext.uc_regs;
241 pc = (u1 *) _gregs[PT_NIP];
248 /* md_critical_section_restart *************************************************
250 Search the critical sections tree for a matching section and set
251 the PC to the restart point, if necessary.
253 *******************************************************************************/
255 #if defined(ENABLE_THREADS)
256 void md_critical_section_restart(ucontext_t *_uc)
259 unsigned long *_gregs;
263 #if defined(__UCLIBC__)
264 _mc = &(_uc->uc_mcontext);
265 _gregs = _mc->regs->gpr;
267 _mc = _uc->uc_mcontext.uc_regs;
271 pc = (u1 *) _gregs[PT_NIP];
273 npc = critical_find_restart_point(pc);
276 _gregs[PT_NIP] = (ptrint) npc;
282 * These are local overrides for various environment variables in Emacs.
283 * Please do not remove this and leave it at the end of the file, where
284 * Emacs will automagically detect them.
285 * ---------------------------------------------------------------------
288 * indent-tabs-mode: t