1 /* src/vm/jit/powerpc/darwin/md-os.c - machine dependent PowerPC Darwin functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35 #include "vm/jit/powerpc/codegen.h"
36 #include "vm/jit/powerpc/darwin/md-abi.h"
38 #include "threads/thread.h"
40 #include "vm/builtin.h"
41 #include "vm/exceptions.h"
42 #include "vm/global.h"
43 #include "vm/signallocal.h"
44 #include "vm/stringlocal.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/stacktrace.h"
50 /* md_signal_handler_sigsegv ***************************************************
52 NullPointerException signal handler for hardware null pointer
55 *******************************************************************************/
57 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
61 ppc_thread_state_t *_ss;
76 _uc = (ucontext_t *) _p;
77 _mc = _uc->uc_mcontext;
80 /* immitate a gregs array */
84 /* get register values */
88 ra = (u1 *) _ss->lr; /* this is correct for leafs */
89 xpc = (u1 *) _ss->srr0;
91 /* get exception-throwing instruction */
93 mcode = *((u4 *) xpc);
95 s1 = M_INSTR_OP2_IMM_A(mcode);
96 disp = M_INSTR_OP2_IMM_I(mcode);
97 d = M_INSTR_OP2_IMM_D(mcode);
101 /* check for special-load */
103 if (s1 == REG_ZERO) {
104 /* we use the exception type as load displacement */
108 if (type == EXCEPTION_HARDWARE_COMPILER) {
109 /* The XPC is the RA minus 4, because the RA points to the
110 instruction after the call. */
116 /* This is a normal NPE: addr must be NULL and the NPE-type
120 type = EXCEPTION_HARDWARE_NULLPOINTER;
123 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
126 /* Handle the type. */
128 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
133 case EXCEPTION_HARDWARE_COMPILER:
135 _ss->r13 = (uintptr_t) p; /* REG_PV */
136 _ss->srr0 = (uintptr_t) p;
140 /* Get and set the PV from the parent Java method. */
142 pv = md_codegen_get_pv_from_pc(ra);
144 _ss->r13 = (uintptr_t) pv;
146 /* Get the exception object. */
148 p = builtin_retrieve_exception();
154 case EXCEPTION_HARDWARE_PATCHER:
161 _ss->r11 = (uintptr_t) p;
162 _ss->r12 = (uintptr_t) xpc;
163 _ss->srr0 = (uintptr_t) asm_handle_exception;
168 /* md_signal_handler_sigtrap ***************************************************
170 Signal handler for hardware-traps.
172 *******************************************************************************/
174 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
178 ppc_thread_state_t *_ss;
190 _uc = (ucontext_t *) _p;
191 _mc = _uc->uc_mcontext;
194 /* immitate a gregs array */
198 /* get register values */
200 pv = (u1 *) _ss->r13;
202 ra = (u1 *) _ss->lr; /* this is correct for leafs */
203 xpc = (u1 *) _ss->srr0;
205 /* get exception-throwing instruction */
207 mcode = *((u4 *) xpc);
209 s1 = M_OP3_GET_A(mcode);
211 /* for now we only handle ArrayIndexOutOfBoundsException */
213 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
216 /* Handle the type. */
218 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
222 _ss->r11 = (intptr_t) p;
223 _ss->r12 = (intptr_t) xpc;
224 _ss->srr0 = (intptr_t) asm_handle_exception;
228 /* md_signal_handler_sigusr2 ***************************************************
230 Signal handler for profiling sampling.
232 *******************************************************************************/
234 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
239 ppc_thread_state_t *_ss;
244 _uc = (ucontext_t *) _p;
245 _mc = _uc->uc_mcontext;
248 pc = (u1 *) _ss->srr0;
254 /* md_critical_section_restart *************************************************
256 Search the critical sections tree for a matching section and set
257 the PC to the restart point, if necessary.
259 *******************************************************************************/
261 #if defined(ENABLE_THREADS)
262 void md_critical_section_restart(ucontext_t *_uc)
265 ppc_thread_state_t *_ss;
269 _mc = _uc->uc_mcontext;
272 pc = (u1 *) _ss->srr0;
274 npc = critical_find_restart_point(pc);
277 _ss->srr0 = (ptrint) npc;
283 * These are local overrides for various environment variables in Emacs.
284 * Please do not remove this and leave it at the end of the file, where
285 * Emacs will automagically detect them.
286 * ---------------------------------------------------------------------
289 * indent-tabs-mode: t