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.hpp"
40 #include "vm/builtin.h"
41 #include "vm/global.h"
42 #include "vm/signallocal.h"
44 #include "vm/jit/asmpart.h"
47 /* md_signal_handler_sigsegv ***************************************************
49 NullPointerException signal handler for hardware null pointer
52 *******************************************************************************/
54 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
58 ppc_thread_state_t *_ss;
73 _uc = (ucontext_t *) _p;
74 _mc = _uc->uc_mcontext;
77 /* immitate a gregs array */
81 /* get register values */
85 ra = (u1 *) _ss->lr; /* this is correct for leafs */
86 xpc = (u1 *) _ss->srr0;
88 /* get exception-throwing instruction */
90 mcode = *((u4 *) xpc);
92 s1 = M_INSTR_OP2_IMM_A(mcode);
93 disp = M_INSTR_OP2_IMM_I(mcode);
94 d = M_INSTR_OP2_IMM_D(mcode);
98 /* check for special-load */
100 if (s1 == REG_ZERO) {
101 /* we use the exception type as load displacement */
105 if (type == EXCEPTION_HARDWARE_COMPILER) {
106 /* The XPC is the RA minus 4, because the RA points to the
107 instruction after the call. */
113 /* This is a normal NPE: addr must be NULL and the NPE-type
117 type = EXCEPTION_HARDWARE_NULLPOINTER;
120 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
123 /* Handle the type. */
125 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
130 case EXCEPTION_HARDWARE_COMPILER:
132 _ss->r13 = (uintptr_t) p; /* REG_PV */
133 _ss->srr0 = (uintptr_t) p;
137 /* Get and set the PV from the parent Java method. */
139 pv = md_codegen_get_pv_from_pc(ra);
141 _ss->r13 = (uintptr_t) pv;
143 /* Get the exception object. */
145 p = builtin_retrieve_exception();
151 case EXCEPTION_HARDWARE_PATCHER:
158 _ss->r11 = (uintptr_t) p;
159 _ss->r12 = (uintptr_t) xpc;
160 _ss->srr0 = (uintptr_t) asm_handle_exception;
165 /* md_signal_handler_sigtrap ***************************************************
167 Signal handler for hardware-traps.
169 *******************************************************************************/
171 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
175 ppc_thread_state_t *_ss;
187 _uc = (ucontext_t *) _p;
188 _mc = _uc->uc_mcontext;
191 /* immitate a gregs array */
195 /* get register values */
197 pv = (u1 *) _ss->r13;
199 ra = (u1 *) _ss->lr; /* this is correct for leafs */
200 xpc = (u1 *) _ss->srr0;
202 /* get exception-throwing instruction */
204 mcode = *((u4 *) xpc);
206 s1 = M_OP3_GET_A(mcode);
208 /* for now we only handle ArrayIndexOutOfBoundsException */
210 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
213 /* Handle the type. */
215 p = signal_handle(type, val, pv, sp, ra, xpc, _p);
219 _ss->r11 = (intptr_t) p;
220 _ss->r12 = (intptr_t) xpc;
221 _ss->srr0 = (intptr_t) asm_handle_exception;
225 /* md_signal_handler_sigusr2 ***************************************************
227 Signal handler for profiling sampling.
229 *******************************************************************************/
231 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
236 ppc_thread_state_t *_ss;
241 _uc = (ucontext_t *) _p;
242 _mc = _uc->uc_mcontext;
245 pc = (u1 *) _ss->srr0;
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