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
37 #include "vm/jit/i386/codegen.h"
39 #include "threads/threads-common.h"
41 #include "vm/exceptions.h"
42 #include "vm/global.h"
43 #include "vm/signallocal.h"
44 #include "vm/stringlocal.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/stacktrace.h"
48 #include "vm/jit/i386/codegen.h"
51 /* md_signal_handler_sigsegv ***************************************************
53 Signal handler for hardware exceptions.
55 *******************************************************************************/
57 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
63 i386_thread_state_t *_ss;
76 _uc = (ucontext_t *) _p;
77 _mc = _uc->uc_mcontext;
80 pv = NULL; /* is resolved during stackframeinfo creation */
82 xpc = (u1 *) _ss->eip;
83 ra = xpc; /* return address is equal to XPC */
85 /* get exception-throwing instruction */
87 opc = M_ALD_MEM_GET_OPC(xpc);
88 mod = M_ALD_MEM_GET_MOD(xpc);
89 rm = M_ALD_MEM_GET_RM(xpc);
91 /* for values see emit_mov_mem_reg and emit_mem */
93 if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
94 /* this was a hardware-exception */
96 d = M_ALD_MEM_GET_REG(xpc);
97 disp = M_ALD_MEM_GET_DISP(xpc);
99 /* we use the exception type as load displacement */
103 val = (d == 0) ? _ss->eax :
104 ((d == 1) ? _ss->ecx :
105 ((d == 2) ? _ss->edx :
106 ((d == 3) ? _ss->ebx :
107 ((d == 4) ? _ss->esp :
108 ((d == 5) ? _ss->ebp :
109 ((d == 6) ? _ss->esi : _ss->edi))))));
112 /* this was a normal NPE */
114 type = EXCEPTION_HARDWARE_NULLPOINTER;
117 /* create stackframeinfo */
119 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
121 /* Handle the type. */
123 p = signal_handle(xpc, type, val);
125 /* remove stackframeinfo */
127 stacktrace_remove_stackframeinfo(&sfi);
131 _ss->eax = (intptr_t) p;
132 _ss->ecx = (intptr_t) xpc;
133 _ss->eip = (intptr_t) asm_handle_exception;
137 /* md_signal_handler_sigfpe ****************************************************
139 ArithmeticException signal handler for hardware divide by zero
142 *******************************************************************************/
144 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
150 i386_thread_state_t *_ss;
159 _uc = (ucontext_t *) _p;
160 _mc = _uc->uc_mcontext;
163 pv = NULL; /* is resolved during stackframeinfo creation */
164 sp = (u1 *) _ss->esp;
165 xpc = (u1 *) _ss->eip;
166 ra = xpc; /* return address is equal to xpc */
168 /* this is an ArithmeticException */
170 type = EXCEPTION_HARDWARE_ARITHMETIC;
173 /* create stackframeinfo */
175 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
177 /* Handle the type. */
179 p = signal_handle(xpc, type, val);
181 /* remove stackframeinfo */
183 stacktrace_remove_stackframeinfo(&sfi);
185 _ss->eax = (intptr_t) p;
186 _ss->ecx = (intptr_t) xpc;
187 _ss->eip = (intptr_t) asm_handle_exception;
191 /* md_signal_handler_sigusr2 ***************************************************
193 Signal handler for profiling sampling.
195 *******************************************************************************/
197 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
202 i386_thread_state_t *_ss;
207 _uc = (ucontext_t *) _p;
208 _mc = _uc->uc_mcontext;
211 pc = (u1 *) _ss->eip;
217 /* md_critical_section_restart *************************************************
219 Search the critical sections tree for a matching section and set
220 the PC to the restart point, if necessary.
222 *******************************************************************************/
224 #if defined(ENABLE_THREADS)
225 void thread_restartcriticalsection(ucontext_t *_uc)
228 i386_thread_state_t *_ss;
232 _mc = _uc->uc_mcontext;
235 pc = (u1 *) _ss->eip;
237 rpc = critical_find_restart_point(pc);
240 _ss->eip = (ptrint) rpc;
246 * These are local overrides for various environment variables in Emacs.
247 * Please do not remove this and leave it at the end of the file, where
248 * Emacs will automagically detect them.
249 * ---------------------------------------------------------------------
252 * indent-tabs-mode: t