1 /* src/vm/jit/i386/linux/md-os.c - machine dependent i386 Linux 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 7865 2007-05-03 21:29:40Z twisti $
30 #define _GNU_SOURCE /* include REG_ defines from ucontext.h */
38 #include "vm/jit/i386/codegen.h"
40 #include "threads/threads-common.h"
42 #include "vm/exceptions.h"
43 #include "vm/signallocal.h"
44 #include "vm/stringlocal.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/stacktrace.h"
50 /* md_signal_handler_sigsegv ***************************************************
52 Signal handler for hardware exceptions.
54 *******************************************************************************/
56 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
73 _uc = (ucontext_t *) _p;
74 _mc = &_uc->uc_mcontext;
76 pv = NULL; /* is resolved during stackframeinfo creation */
77 sp = (u1 *) _mc->gregs[REG_ESP];
78 xpc = (u1 *) _mc->gregs[REG_EIP];
79 ra = xpc; /* return address is equal to XPC */
81 /* get exception-throwing instruction */
83 opc = M_ALD_MEM_GET_OPC(xpc);
84 mod = M_ALD_MEM_GET_MOD(xpc);
85 rm = M_ALD_MEM_GET_RM(xpc);
87 /* for values see emit_mov_mem_reg and emit_mem */
89 if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
90 /* this was a hardware-exception */
92 d = M_ALD_MEM_GET_REG(xpc);
93 disp = M_ALD_MEM_GET_DISP(xpc);
95 /* we use the exception type as load displacement */
99 /* ATTENTION: The _mc->gregs layout is completely crazy! The
100 registers are reversed starting with number 4 for REG_EDI
101 (see /usr/include/sys/ucontext.h). We have to convert that
104 val = _mc->gregs[REG_EAX - d];
107 /* this was a normal NPE */
109 type = EXCEPTION_HARDWARE_NULLPOINTER;
112 /* generate appropriate exception */
114 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
118 _mc->gregs[REG_EAX] = (ptrint) o;
119 _mc->gregs[REG_ECX] = (ptrint) xpc; /* REG_ITMP2_XPC */
120 _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
124 /* md_signal_handler_sigfpe ****************************************************
126 ArithmeticException signal handler for hardware divide by zero
129 *******************************************************************************/
131 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
141 java_objectheader *o;
143 _uc = (ucontext_t *) _p;
144 _mc = &_uc->uc_mcontext;
146 pv = NULL; /* is resolved during stackframeinfo creation */
147 sp = (u1 *) _mc->gregs[REG_ESP];
148 xpc = (u1 *) _mc->gregs[REG_EIP];
149 ra = xpc; /* return address is equal to xpc */
151 /* this is an ArithmeticException */
153 type = EXCEPTION_HARDWARE_ARITHMETIC;
156 /* generate appropriate exception */
158 o = exceptions_new_hardware_exception(pv, sp, ra, xpc, type, val);
160 _mc->gregs[REG_EAX] = (ptrint) o;
161 _mc->gregs[REG_ECX] = (ptrint) xpc; /* REG_ITMP2_XPC */
162 _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
166 /* md_signal_handler_sigusr2 ***************************************************
168 Signal handler for profiling sampling.
170 *******************************************************************************/
172 #if defined(ENABLE_THREADS)
173 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
182 _uc = (ucontext_t *) _p;
183 _mc = &_uc->uc_mcontext;
185 pc = (u1 *) _mc->gregs[REG_EIP];
192 /* md_critical_section_restart *************************************************
194 Search the critical sections tree for a matching section and set
195 the PC to the restart point, if necessary.
197 *******************************************************************************/
199 #if defined(ENABLE_THREADS)
200 void md_critical_section_restart(ucontext_t *_uc)
206 _mc = &_uc->uc_mcontext;
208 pc = (u1 *) _mc->gregs[REG_EIP];
210 npc = critical_find_restart_point(pc);
213 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
214 _mc->gregs[REG_EIP] = (ptrint) npc;
221 * These are local overrides for various environment variables in Emacs.
222 * Please do not remove this and leave it at the end of the file, where
223 * Emacs will automagically detect them.
224 * ---------------------------------------------------------------------
227 * indent-tabs-mode: t