1 /* src/vm/jit/powerpc/darwin/md-os.c - machine dependent PowerPC Darwin functions
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Christian Thalinger
31 $Id: md-os.c 2962 2005-07-09 18:08:06Z twisti $
41 #include "vm/jit/powerpc/types.h"
42 #include "vm/jit/powerpc/darwin/md-abi.h"
44 #include "vm/exceptions.h"
45 #include "vm/global.h"
46 #include "vm/stringlocal.h"
47 #include "vm/jit/asmpart.h"
51 /* cacao_catch_Handler *********************************************************
55 *******************************************************************************/
57 int cacao_catch_Handler(mach_port_t thread)
59 #if defined(USE_THREADS)
63 /* java_objectheader *xptr; */
66 thread_state_flavor_t flavor = PPC_THREAD_STATE;
67 mach_msg_type_number_t thread_state_count = PPC_THREAD_STATE_COUNT;
68 ppc_thread_state_t thread_state;
74 r = thread_get_state(thread, flavor,
75 (natural_t*)&thread_state, &thread_state_count);
76 if (r != KERN_SUCCESS) {
77 log_text("thread_get_state failed");
81 regs = &thread_state.r0;
82 crashpc = thread_state.srr0;
84 instr = *(s4*) crashpc;
85 reg = (instr >> 16) & 31;
88 /* This is now handled in asmpart because it needs to run in the throwing
90 /* xptr = new_nullpointerexception(); */
92 regs[REG_ITMP2_XPC] = crashpc;
93 /* regs[REG_ITMP1_XPTR] = (u4) xptr; */
94 thread_state.srr0 = (u4) asm_handle_nullptr_exception;
96 r = thread_set_state(thread, flavor,
97 (natural_t*)&thread_state, thread_state_count);
98 if (r != KERN_SUCCESS) {
99 log_text("thread_set_state failed");
106 throw_cacao_exception_exit(string_java_lang_InternalError,
107 "Segmentation fault at %p", regs[reg]);
115 /* signal_handler_sigsegv ******************************************************
117 NullPointerException signal handler for hardware null pointer check.
119 *******************************************************************************/
121 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
125 ppc_thread_state_t *_ss;
135 _uc = (ucontext_t *) _p;
136 _mc = _uc->uc_mcontext;
139 /* check for NullPointerException */
143 instr = *((u4 *) _ss->srr0);
144 reg = (instr >> 16) & 31;
148 /* allocate stackframeinfo on heap */
150 sfi = NEW(stackframeinfo);
152 /* create exception */
154 pv = (u1 *) _ss->r13;
156 ra = (functionptr) _ss->srr0;
158 stacktrace_create_inline_stackframeinfo(sfi, pv, sp, ra);
160 _ss->r11 = (ptrint) new_nullpointerexception();
162 stacktrace_remove_stackframeinfo(sfi);
164 FREE(sfi, stackframeinfo);
166 /* set the REG_ITMP1_XPTR, REG_ITMP2_XPC and new PC */
168 _ss->r12 = _ss->srr0;
169 _ss->srr0 = (ptrint) asm_handle_exception;
172 throw_cacao_exception_exit(string_java_lang_InternalError,
173 "Segmentation fault: 0x%08lx at 0x%08lx",
180 * These are local overrides for various environment variables in Emacs.
181 * Please do not remove this and leave it at the end of the file, where
182 * Emacs will automagically detect them.
183 * ---------------------------------------------------------------------
186 * indent-tabs-mode: t