1 /* src/vm/jit/i386/linux/md-os.c - machine dependent i386 Linux 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 7480 2007-03-08 12:46:19Z michi $
36 #define _GNU_SOURCE /* include REG_ defines from ucontext.h */
44 #if defined(ENABLE_GC_CACAO)
45 # include "mm/cacao-gc/gc.h"
48 #include "vm/exceptions.h"
49 #include "vm/signallocal.h"
50 #include "vm/stringlocal.h"
51 #include "vm/jit/asmpart.h"
52 #include "vm/jit/stacktrace.h"
55 /* md_signal_handler_sigsegv ***************************************************
57 NullPointerException signal handler for hardware null pointer
60 *******************************************************************************/
62 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
70 _uc = (ucontext_t *) _p;
71 _mc = &_uc->uc_mcontext;
73 sp = (u1 *) _mc->gregs[REG_ESP];
74 xpc = (u1 *) _mc->gregs[REG_EIP];
75 ra = xpc; /* return address is equal to xpc */
78 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
80 _mc->gregs[REG_ECX] = (ptrint) xpc; /* REG_ITMP2_XPC */
81 _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
85 /* md_signal_handler_sigfpe ****************************************************
87 ArithmeticException signal handler for hardware divide by zero
90 *******************************************************************************/
92 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
100 _uc = (ucontext_t *) _p;
101 _mc = &_uc->uc_mcontext;
103 sp = (u1 *) _mc->gregs[REG_ESP];
104 xpc = (u1 *) _mc->gregs[REG_EIP];
105 ra = xpc; /* return address is equal to xpc */
107 _mc->gregs[REG_EAX] =
108 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
110 _mc->gregs[REG_ECX] = (ptrint) xpc; /* REG_ITMP2_XPC */
111 _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
115 /* md_signal_handler_sigusr1 ***************************************************
117 Signale handler the exact GC to suspend threads.
119 *******************************************************************************/
121 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
122 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
125 executionstate_t *es;
130 t->es = NEW(executionstate_t); /* TODO: this must be done before!!! */
133 _uc = (ucontext_t *) _p;
134 _mc = &_uc->uc_mcontext;
136 /* assume there is a GC pending */
139 /* fill in the execution state of this thread */
140 es->pc = (u1 *) _mc->gregs[REG_EIP];
141 es->sp = (u1 *) _mc->gregs[REG_ESP];
142 es->pv = (u1 *) NULL;
144 /* TODO: int registers are missing */
146 /* now suspend the current thread for GC */
152 /* md_signal_handler_sigusr2 ***************************************************
154 Signal handler for profiling sampling.
156 *******************************************************************************/
158 #if defined(ENABLE_THREADS)
159 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
168 _uc = (ucontext_t *) _p;
169 _mc = &_uc->uc_mcontext;
171 pc = (u1 *) _mc->gregs[REG_EIP];
178 #if defined(ENABLE_THREADS)
179 void thread_restartcriticalsection(ucontext_t *uc)
183 critical = critical_find_restart_point((void *) uc->uc_mcontext.gregs[REG_EIP]);
186 uc->uc_mcontext.gregs[REG_EIP] = (ptrint) critical;
192 * These are local overrides for various environment variables in Emacs.
193 * Please do not remove this and leave it at the end of the file, where
194 * Emacs will automagically detect them.
195 * ---------------------------------------------------------------------
198 * indent-tabs-mode: t