1 /* src/vm/jit/i386/darwin/md-os.c - machine dependent i386 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 5074 2006-07-04 16:05:35Z twisti $
39 #include "vm/jit/i386/codegen.h"
41 #include "threads/threads-common.h"
43 #include "vm/exceptions.h"
44 #include "vm/global.h"
45 #include "vm/signallocal.h"
46 #include "vm/stringlocal.h"
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.h"
50 #include "vm/jit/i386/codegen.h"
53 /* md_signal_handler_sigsegv ***************************************************
55 Signal handler for hardware exceptions.
57 *******************************************************************************/
59 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
65 i386_thread_state_t *_ss;
78 _uc = (ucontext_t *) _p;
79 _mc = _uc->uc_mcontext;
82 pv = NULL; /* is resolved during stackframeinfo creation */
84 xpc = (u1 *) _ss->eip;
85 ra = xpc; /* return address is equal to XPC */
87 /* get exception-throwing instruction */
89 opc = M_ALD_MEM_GET_OPC(xpc);
90 mod = M_ALD_MEM_GET_MOD(xpc);
91 rm = M_ALD_MEM_GET_RM(xpc);
93 /* for values see emit_mov_mem_reg and emit_mem */
95 if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
96 /* this was a hardware-exception */
98 d = M_ALD_MEM_GET_REG(xpc);
99 disp = M_ALD_MEM_GET_DISP(xpc);
101 /* we use the exception type as load displacement */
105 val = (d == 0) ? _ss->eax :
106 ((d == 1) ? _ss->ecx :
107 ((d == 2) ? _ss->edx :
108 ((d == 3) ? _ss->ebx :
109 ((d == 4) ? _ss->esp :
110 ((d == 5) ? _ss->ebp :
111 ((d == 6) ? _ss->esi : _ss->edi))))));
114 /* this was a normal NPE */
116 type = EXCEPTION_HARDWARE_NULLPOINTER;
119 /* create stackframeinfo */
121 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
123 /* Handle the type. */
125 p = signal_handle(xpc, type, val);
127 /* remove stackframeinfo */
129 stacktrace_remove_stackframeinfo(&sfi);
133 _ss->eax = (intptr_t) p;
134 _ss->ecx = (intptr_t) xpc;
135 _ss->eip = (intptr_t) asm_handle_exception;
139 /* md_signal_handler_sigfpe ****************************************************
141 ArithmeticException signal handler for hardware divide by zero
144 *******************************************************************************/
146 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
152 i386_thread_state_t *_ss;
161 _uc = (ucontext_t *) _p;
162 _mc = _uc->uc_mcontext;
165 pv = NULL; /* is resolved during stackframeinfo creation */
166 sp = (u1 *) _ss->esp;
167 xpc = (u1 *) _ss->eip;
168 ra = xpc; /* return address is equal to xpc */
170 /* this is an ArithmeticException */
172 type = EXCEPTION_HARDWARE_ARITHMETIC;
175 /* create stackframeinfo */
177 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
179 /* Handle the type. */
181 p = signal_handle(xpc, type, val);
183 /* remove stackframeinfo */
185 stacktrace_remove_stackframeinfo(&sfi);
187 _ss->eax = (intptr_t) p;
188 _ss->ecx = (intptr_t) xpc;
189 _ss->eip = (intptr_t) asm_handle_exception;
193 /* md_signal_handler_sigusr2 ***************************************************
195 Signal handler for profiling sampling.
197 *******************************************************************************/
199 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
204 i386_thread_state_t *_ss;
209 _uc = (ucontext_t *) _p;
210 _mc = _uc->uc_mcontext;
213 pc = (u1 *) _ss->eip;
219 /* md_critical_section_restart *************************************************
221 Search the critical sections tree for a matching section and set
222 the PC to the restart point, if necessary.
224 *******************************************************************************/
226 #if defined(ENABLE_THREADS)
227 void thread_restartcriticalsection(ucontext_t *_uc)
230 i386_thread_state_t *_ss;
234 _mc = _uc->uc_mcontext;
237 pc = (u1 *) _ss->eip;
239 rpc = critical_find_restart_point(pc);
242 _ss->eip = (ptrint) rpc;
248 * These are local overrides for various environment variables in Emacs.
249 * Please do not remove this and leave it at the end of the file, where
250 * Emacs will automagically detect them.
251 * ---------------------------------------------------------------------
254 * indent-tabs-mode: t