1 /* src/vm/jit/i386/darwin/md-os.c - machine dependent i386 Darwin functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
31 $Id: md-os.c 5074 2006-07-04 16:05:35Z twisti $
44 #include "vm/jit/i386/codegen.h"
46 #include "threads/threads-common.h"
48 #include "vm/exceptions.h"
49 #include "vm/global.h"
50 #include "vm/signallocal.h"
51 #include "vm/stringlocal.h"
52 #include "vm/jit/asmpart.h"
53 #include "vm/jit/stacktrace.h"
55 #include "vm/jit/i386/codegen.h"
58 /* md_signal_handler_sigsegv ***************************************************
60 Signal handler for hardware exceptions.
62 *******************************************************************************/
64 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
70 i386_thread_state_t *_ss;
83 _uc = (ucontext_t *) _p;
84 _mc = _uc->uc_mcontext;
87 pv = NULL; /* is resolved during stackframeinfo creation */
89 xpc = (u1 *) _ss->eip;
90 ra = xpc; /* return address is equal to XPC */
92 /* get exception-throwing instruction */
94 opc = M_ALD_MEM_GET_OPC(xpc);
95 mod = M_ALD_MEM_GET_MOD(xpc);
96 rm = M_ALD_MEM_GET_RM(xpc);
98 /* for values see emit_mov_mem_reg and emit_mem */
100 if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
101 /* this was a hardware-exception */
103 d = M_ALD_MEM_GET_REG(xpc);
104 disp = M_ALD_MEM_GET_DISP(xpc);
106 /* we use the exception type as load displacement */
110 val = (d == 0) ? _ss->eax :
111 ((d == 1) ? _ss->ecx :
112 ((d == 2) ? _ss->edx :
113 ((d == 3) ? _ss->ebx :
114 ((d == 4) ? _ss->esp :
115 ((d == 5) ? _ss->ebp :
116 ((d == 6) ? _ss->esi : _ss->edi))))));
119 /* this was a normal NPE */
121 type = EXCEPTION_HARDWARE_NULLPOINTER;
124 /* generate appropriate exception */
126 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val, &sfi);
130 _ss->eax = (ptrint) o;
131 _ss->ecx = (ptrint) xpc;
132 _ss->eip = (ptrint) asm_handle_exception;
136 /* md_signal_handler_sigfpe ****************************************************
138 ArithmeticException signal handler for hardware divide by zero
141 *******************************************************************************/
143 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
149 i386_thread_state_t *_ss;
155 java_objectheader *o;
158 _uc = (ucontext_t *) _p;
159 _mc = _uc->uc_mcontext;
162 pv = NULL; /* is resolved during stackframeinfo creation */
163 sp = (u1 *) _ss->esp;
164 xpc = (u1 *) _ss->eip;
165 ra = xpc; /* return address is equal to xpc */
167 /* this is an ArithmeticException */
169 type = EXCEPTION_HARDWARE_ARITHMETIC;
172 /* generate appropriate exception */
174 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val, &sfi);
176 _ss->eax = (ptrint) o;
177 _ss->ecx = (ptrint) xpc;
178 _ss->eip = (ptrint) asm_handle_exception;
182 /* md_signal_handler_sigusr2 ***************************************************
184 Signal handler for profiling sampling.
186 *******************************************************************************/
188 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
193 i386_thread_state_t *_ss;
198 _uc = (ucontext_t *) _p;
199 _mc = _uc->uc_mcontext;
202 pc = (u1 *) _ss->eip;
208 #if defined(ENABLE_THREADS)
209 void thread_restartcriticalsection(ucontext_t *_uc)
212 i386_thread_state_t *_ss;
216 _mc = _uc->uc_mcontext;
219 pc = (u1 *) _ss->eip;
221 rpc = critical_find_restart_point(pc);
224 _ss->eip = (ptrint) rpc;
230 * These are local overrides for various environment variables in Emacs.
231 * Please do not remove this and leave it at the end of the file, where
232 * Emacs will automagically detect them.
233 * ---------------------------------------------------------------------
236 * indent-tabs-mode: t