* Updated header: Added 2006. Changed address of FSF. Changed email
[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, 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
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., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: md-os.c 4357 2006-01-22 23:33:38Z twisti $
32
33 */
34
35
36 #define _GNU_SOURCE                   /* include REG_ defines from ucontext.h */
37
38 #include "config.h"
39
40 #include <ucontext.h>
41
42 #include "vm/types.h"
43
44 #include "vm/exceptions.h"
45 #include "vm/signallocal.h"
46 #include "vm/stringlocal.h"
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.h"
49
50
51 /* md_signal_handler_sigsegv ***************************************************
52
53    NullPointerException signal handler for hardware null pointer
54    check.
55
56 *******************************************************************************/
57
58 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
59 {
60         ucontext_t *_uc;
61         mcontext_t *_mc;
62         u1         *sp;
63         u1         *ra;
64         u1         *xpc;
65
66         _uc = (ucontext_t *) _p;
67         _mc = &_uc->uc_mcontext;
68
69         sp  = (u1 *) _mc->gregs[REG_ESP];
70         xpc = (u1 *) _mc->gregs[REG_EIP];
71         ra  = xpc;                          /* return address is equal to xpc     */
72
73         _mc->gregs[REG_EAX] =
74                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
75
76         _mc->gregs[REG_ECX] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
77         _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
78 }
79
80
81 /* md_signal_handler_sigfpe ****************************************************
82
83    ArithmeticException signal handler for hardware divide by zero
84    check.
85
86 *******************************************************************************/
87
88 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
89 {
90         ucontext_t *_uc;
91         mcontext_t *_mc;
92         u1         *sp;
93         u1         *ra;
94         u1         *xpc;
95
96         _uc = (ucontext_t *) _p;
97         _mc = &_uc->uc_mcontext;
98
99         sp  = (u1 *) _mc->gregs[REG_ESP];
100         xpc = (u1 *) _mc->gregs[REG_EIP];
101         ra  = xpc;                          /* return address is equal to xpc     */
102
103         _mc->gregs[REG_EAX] =
104                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
105
106         _mc->gregs[REG_ECX] = (ptrint) xpc;                      /* REG_ITMP2_XPC */
107         _mc->gregs[REG_EIP] = (ptrint) asm_handle_exception;
108 }
109
110
111 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
112 void thread_restartcriticalsection(ucontext_t *uc)
113 {
114         void *critical;
115
116         critical = thread_checkcritical((void *) uc->uc_mcontext.gregs[REG_EIP]);
117
118         if (critical)
119                 uc->uc_mcontext.gregs[REG_EIP] = (ptrint) critical;
120 }
121 #endif
122
123
124 /*
125  * These are local overrides for various environment variables in Emacs.
126  * Please do not remove this and leave it at the end of the file, where
127  * Emacs will automagically detect them.
128  * ---------------------------------------------------------------------
129  * Local variables:
130  * mode: c
131  * indent-tabs-mode: t
132  * c-basic-offset: 4
133  * tab-width: 4
134  * End:
135  */