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
37 #include "vm/jit/powerpc/codegen.h"
38 #include "vm/jit/powerpc/darwin/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/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)
65 ppc_thread_state_t *_ss;
80 _uc = (ucontext_t *) _p;
81 _mc = _uc->uc_mcontext;
84 /* immitate a gregs array */
88 /* get register values */
92 ra = (u1 *) _ss->lr; /* this is correct for leafs */
93 xpc = (u1 *) _ss->srr0;
95 /* get exception-throwing instruction */
97 mcode = *((u4 *) xpc);
99 s1 = M_INSTR_OP2_IMM_A(mcode);
100 disp = M_INSTR_OP2_IMM_I(mcode);
101 d = M_INSTR_OP2_IMM_D(mcode);
105 /* check for special-load */
107 if (s1 == REG_ZERO) {
108 /* we use the exception type as load displacement */
112 if (type == EXCEPTION_HARDWARE_COMPILER) {
113 /* The XPC is the RA minus 4, because the RA points to the
114 instruction after the call. */
120 /* This is a normal NPE: addr must be NULL and the NPE-type
124 type = EXCEPTION_HARDWARE_NULLPOINTER;
127 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
130 /* Handle the type. */
132 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
137 case EXCEPTION_HARDWARE_COMPILER:
139 _ss->r13 = (uintptr_t) p; /* REG_PV */
140 _ss->srr0 = (uintptr_t) p;
144 /* Get and set the PV from the parent Java method. */
146 pv = md_codegen_get_pv_from_pc(ra);
148 _ss->r13 = (uintptr_t) pv;
150 /* Get the exception object. */
152 p = builtin_retrieve_exception();
158 case EXCEPTION_HARDWARE_PATCHER:
165 _ss->r11 = (uintptr_t) p;
166 _ss->r12 = (uintptr_t) xpc;
167 _ss->srr0 = (uintptr_t) asm_handle_exception;
172 /* md_signal_handler_sigtrap ***************************************************
174 Signal handler for hardware-traps.
176 *******************************************************************************/
178 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
182 ppc_thread_state_t *_ss;
194 _uc = (ucontext_t *) _p;
195 _mc = _uc->uc_mcontext;
198 /* immitate a gregs array */
202 /* get register values */
204 pv = (u1 *) _ss->r13;
206 ra = (u1 *) _ss->lr; /* this is correct for leafs */
207 xpc = (u1 *) _ss->srr0;
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 _ss->r11 = (intptr_t) p;
227 _ss->r12 = (intptr_t) xpc;
228 _ss->srr0 = (intptr_t) asm_handle_exception;
232 /* md_signal_handler_sigusr2 ***************************************************
234 Signal handler for profiling sampling.
236 *******************************************************************************/
238 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
243 ppc_thread_state_t *_ss;
248 _uc = (ucontext_t *) _p;
249 _mc = _uc->uc_mcontext;
252 pc = (u1 *) _ss->srr0;
258 /* md_critical_section_restart *************************************************
260 Search the critical sections tree for a matching section and set
261 the PC to the restart point, if necessary.
263 *******************************************************************************/
265 #if defined(ENABLE_THREADS)
266 void md_critical_section_restart(ucontext_t *_uc)
269 ppc_thread_state_t *_ss;
273 _mc = _uc->uc_mcontext;
276 pc = (u1 *) _ss->srr0;
278 npc = critical_find_restart_point(pc);
281 _ss->srr0 = (ptrint) npc;
287 * These are local overrides for various environment variables in Emacs.
288 * Please do not remove this and leave it at the end of the file, where
289 * Emacs will automagically detect them.
290 * ---------------------------------------------------------------------
293 * indent-tabs-mode: t