* Renamed md.c to md-os.c
[cacao.git] / src / vm / jit / i386 / linux / md-os.c
1 /* src/vm/jit/i386/linux/md-os.c - machine dependent i386 Linux functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
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.
14
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.
19
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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: md-os.c 2916 2005-07-05 13:59:43Z twisti $
32
33 */
34
35
36 #define _GNU_SOURCE                   /* include REG_ defines from ucontext.h */
37
38 #include <ucontext.h>
39
40 #include "vm/options.h"
41 #include "vm/stringlocal.h"
42 #include "vm/jit/asmpart.h"
43
44
45 /* signal_handler_sigsegv ******************************************************
46
47    NullPointerException signal handler for hardware null pointer check.
48
49 *******************************************************************************/
50
51 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
52 {
53         ucontext_t *_uc;
54         mcontext_t *_mc;
55
56         _uc = (ucontext_t *) _p;
57         _mc = &_uc->uc_mcontext;
58
59         _mc->gregs[REG_ECX] = _mc->gregs[REG_EIP];           /* REG_ITMP2_XPC     */
60         _mc->gregs[REG_EAX] = (ptrint) string_java_lang_NullPointerException;
61         _mc->gregs[REG_EIP] = (ptrint) asm_throw_and_handle_exception;
62 }
63
64
65 /* signal_handler_sigfpe *******************************************************
66
67    ArithmeticException signal handler for hardware divide by zero check.
68
69 *******************************************************************************/
70
71 void signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
72 {
73         ucontext_t *_uc;
74         mcontext_t *_mc;
75
76         _uc = (ucontext_t *) _p;
77         _mc = &_uc->uc_mcontext;
78
79         _mc->gregs[REG_ECX] = _mc->gregs[REG_EIP];           /* REG_ITMP2_XPC     */
80         _mc->gregs[REG_EIP] =
81                 (ptrint) asm_throw_and_handle_hardware_arithmetic_exception;
82 }
83
84
85 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
86 void thread_restartcriticalsection(ucontext_t *uc)
87 {
88         void *critical;
89
90         critical = thread_checkcritical((void *) uc->uc_mcontext.gregs[REG_EIP]);
91
92         if (critical)
93                 uc->uc_mcontext.gregs[REG_EIP] = (ptrint) critical;
94 }
95 #endif
96
97
98 /*
99  * These are local overrides for various environment variables in Emacs.
100  * Please do not remove this and leave it at the end of the file, where
101  * Emacs will automagically detect them.
102  * ---------------------------------------------------------------------
103  * Local variables:
104  * mode: c
105  * indent-tabs-mode: t
106  * c-basic-offset: 4
107  * tab-width: 4
108  * End:
109  */