1 /* src/vm/jit/powerpc/darwin/md-os.c - machine dependent PowerPC Darwin 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 8178 2007-07-05 11:13:20Z michi $
38 #include "vm/jit/powerpc/codegen.h"
39 #include "vm/jit/powerpc/darwin/md-abi.h"
41 #if defined(ENABLE_THREADS)
42 # include "threads/native/threads.h"
45 #include "vm/exceptions.h"
46 #include "vm/global.h"
47 #include "vm/signallocal.h"
48 #include "vm/stringlocal.h"
50 #include "vm/jit/asmpart.h"
51 #include "vm/jit/stacktrace.h"
54 /* md_signal_handler_sigsegv ***************************************************
56 NullPointerException signal handler for hardware null pointer
59 *******************************************************************************/
61 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
66 ppc_thread_state_t *_ss;
81 _uc = (ucontext_t *) _p;
82 _mc = _uc->uc_mcontext;
85 /* immitate a gregs array */
89 /* get register values */
93 ra = (u1 *) _ss->lr; /* this is correct for leafs */
94 xpc = (u1 *) _ss->srr0;
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 /* generate appropriate exception */
126 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val, &sfi);
130 _ss->r11 = (ptrint) o;
131 _ss->r12 = (ptrint) xpc;
132 _ss->srr0 = (ptrint) 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)
147 ppc_thread_state_t *_ss;
157 java_objectheader *o;
159 _uc = (ucontext_t *) _p;
160 _mc = _uc->uc_mcontext;
163 /* immitate a gregs array */
167 /* get register values */
169 pv = (u1 *) _ss->r13;
171 ra = (u1 *) _ss->lr; /* this is correct for leafs */
172 xpc = (u1 *) _ss->srr0;
174 /* get exception-throwing instruction */
176 mcode = *((u4 *) xpc);
178 s1 = M_OP3_GET_A(mcode);
180 /* for now we only handle ArrayIndexOutOfBoundsException */
182 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
185 /* generate appropriate exception */
187 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val, &sfi);
191 _ss->r11 = (ptrint) o;
192 _ss->r12 = (ptrint) xpc;
193 _ss->srr0 = (ptrint) asm_handle_exception;
197 /* md_signal_handler_sigusr2 ***************************************************
199 Signal handler for profiling sampling.
201 *******************************************************************************/
203 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
208 ppc_thread_state_t *_ss;
213 _uc = (ucontext_t *) _p;
214 _mc = _uc->uc_mcontext;
217 pc = (u1 *) _ss->srr0;
223 /* md_critical_section_restart *************************************************
225 Search the critical sections tree for a matching section and set
226 the PC to the restart point, if necessary.
228 *******************************************************************************/
230 #if defined(ENABLE_THREADS)
231 void md_critical_section_restart(ucontext_t *_uc)
234 ppc_thread_state_t *_ss;
238 _mc = _uc->uc_mcontext;
241 pc = (u1 *) _ss->srr0;
243 npc = critical_find_restart_point(pc);
246 _ss->srr0 = (ptrint) npc;
252 * These are local overrides for various environment variables in Emacs.
253 * Please do not remove this and leave it at the end of the file, where
254 * Emacs will automagically detect them.
255 * ---------------------------------------------------------------------
258 * indent-tabs-mode: t