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 8283 2007-08-09 15:10:05Z twisti $
39 #include "vm/jit/powerpc/codegen.h"
40 #include "vm/jit/powerpc/darwin/md-abi.h"
42 #if defined(ENABLE_THREADS)
43 # include "threads/native/threads.h"
46 #include "vm/exceptions.h"
47 #include "vm/global.h"
48 #include "vm/signallocal.h"
49 #include "vm/stringlocal.h"
51 #include "vm/jit/asmpart.h"
52 #include "vm/jit/stacktrace.h"
55 /* md_signal_handler_sigsegv ***************************************************
57 NullPointerException signal handler for hardware null pointer
60 *******************************************************************************/
62 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
67 ppc_thread_state_t *_ss;
82 _uc = (ucontext_t *) _p;
83 _mc = _uc->uc_mcontext;
86 /* immitate a gregs array */
90 /* get register values */
94 ra = (u1 *) _ss->lr; /* this is correct for leafs */
95 xpc = (u1 *) _ss->srr0;
97 /* get exception-throwing instruction */
99 mcode = *((u4 *) xpc);
101 s1 = M_INSTR_OP2_IMM_A(mcode);
102 disp = M_INSTR_OP2_IMM_I(mcode);
103 d = M_INSTR_OP2_IMM_D(mcode);
107 /* check for special-load */
109 if (s1 == REG_ZERO) {
110 /* we use the exception type as load displacement */
115 /* This is a normal NPE: addr must be NULL and the NPE-type
119 type = EXCEPTION_HARDWARE_NULLPOINTER;
122 vm_abort("md_signal_handler_sigsegv: faulting address is not NULL: addr=%p", addr);
125 /* create stackframeinfo */
127 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
129 /* Handle the type. */
131 p = signal_handle(xpc, type, val);
133 /* remove stackframeinfo */
135 stacktrace_remove_stackframeinfo(&sfi);
137 /* set registers (only if exception object ready) */
140 _ss->r11 = (intptr_t) p;
141 _ss->r12 = (intptr_t) xpc;
142 _ss->srr0 = (intptr_t) asm_handle_exception;
147 /* md_signal_handler_sigtrap ***************************************************
149 Signal handler for hardware-traps.
151 *******************************************************************************/
153 void md_signal_handler_sigtrap(int sig, siginfo_t *siginfo, void *_p)
158 ppc_thread_state_t *_ss;
170 _uc = (ucontext_t *) _p;
171 _mc = _uc->uc_mcontext;
174 /* immitate a gregs array */
178 /* get register values */
180 pv = (u1 *) _ss->r13;
182 ra = (u1 *) _ss->lr; /* this is correct for leafs */
183 xpc = (u1 *) _ss->srr0;
185 /* get exception-throwing instruction */
187 mcode = *((u4 *) xpc);
189 s1 = M_OP3_GET_A(mcode);
191 /* for now we only handle ArrayIndexOutOfBoundsException */
193 type = EXCEPTION_HARDWARE_ARRAYINDEXOUTOFBOUNDS;
196 /* create stackframeinfo */
198 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
200 /* Handle the type. */
202 p = signal_handle(xpc, type, val);
204 /* remove stackframeinfo */
206 stacktrace_remove_stackframeinfo(&sfi);
210 _ss->r11 = (intptr_t) p;
211 _ss->r12 = (intptr_t) xpc;
212 _ss->srr0 = (intptr_t) asm_handle_exception;
216 /* md_signal_handler_sigusr2 ***************************************************
218 Signal handler for profiling sampling.
220 *******************************************************************************/
222 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
227 ppc_thread_state_t *_ss;
232 _uc = (ucontext_t *) _p;
233 _mc = _uc->uc_mcontext;
236 pc = (u1 *) _ss->srr0;
242 /* md_critical_section_restart *************************************************
244 Search the critical sections tree for a matching section and set
245 the PC to the restart point, if necessary.
247 *******************************************************************************/
249 #if defined(ENABLE_THREADS)
250 void md_critical_section_restart(ucontext_t *_uc)
253 ppc_thread_state_t *_ss;
257 _mc = _uc->uc_mcontext;
260 pc = (u1 *) _ss->srr0;
262 npc = critical_find_restart_point(pc);
265 _ss->srr0 = (ptrint) npc;
271 * These are local overrides for various environment variables in Emacs.
272 * Please do not remove this and leave it at the end of the file, where
273 * Emacs will automagically detect them.
274 * ---------------------------------------------------------------------
277 * indent-tabs-mode: t