* Removed all Id tags.
[cacao.git] / src / vm / jit / i386 / freebsd / md-os.c
1 /* src/vm/jit/i386/freebsd/md-os.c - machine dependent i386 FreeBSD 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 */
32
33
34 #include "config.h"
35
36 #include <ucontext.h>
37
38 #include "vm/jit/i386/md-abi.h"
39
40 #include "vm/exceptions.h"
41 #include "vm/signallocal.h"
42 #include "vm/jit/asmpart.h"
43 #include "vm/jit/stacktrace.h"
44
45
46 /* md_signal_handler_sigsegv ***************************************************
47
48    NullPointerException signal handler for hardware null pointer
49    check.
50
51 *******************************************************************************/
52
53 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
54 {
55         ucontext_t *_uc;
56         mcontext_t *_mc;
57         u1         *sp;
58         u1         *ra;
59         u1         *xpc;
60
61         _uc = (ucontext_t *) _p;
62         _mc = &_uc->uc_mcontext;
63         
64         sp  = (u1 *) _mc->mc_esp;
65         xpc = (u1 *) _mc->mc_eip;
66         ra  = xpc;                          /* return address is equal to xpc     */
67
68         _mc->mc_eax =
69                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
70         
71         _mc->mc_ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
72         _mc->mc_eip = (ptrint) asm_handle_exception;
73 }
74
75
76 /* md_signal_handler_sigfpe ****************************************************
77
78    ArithmeticException signal handler for hardware divide by zero
79    check.
80
81 *******************************************************************************/
82
83 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
84 {
85         ucontext_t *_uc;
86         mcontext_t *_mc;
87         u1         *sp;
88         u1         *ra;
89         u1         *xpc;
90
91         _uc = (ucontext_t *) _p;
92         _mc = &_uc->uc_mcontext;
93
94         sp  = (u1 *) _mc->mc_esp;
95         xpc = (u1 *) _mc->mc_eip;
96         ra  = xpc;                          /* return address is equal to xpc     */
97
98         _mc->mc_eax =
99                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
100         
101         _mc->mc_ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
102         _mc->mc_eip = (ptrint) asm_handle_exception;
103 }
104
105
106 #if defined(ENABLE_THREADS)
107 void thread_restartcriticalsection(ucontext_t *uc)
108 {
109         void *critical;
110
111         critical = critical_find_restart_point((void *) uc->uc_mcontext.mc_eip);
112
113         if (critical)
114                 uc->uc_mcontext.mc_eip = (ptrint) critical;
115 }
116 #endif
117
118
119 /*
120  * These are local overrides for various environment variables in Emacs.
121  * Please do not remove this and leave it at the end of the file, where
122  * Emacs will automagically detect them.
123  * ---------------------------------------------------------------------
124  * Local variables:
125  * mode: c
126  * indent-tabs-mode: t
127  * c-basic-offset: 4
128  * tab-width: 4
129  * End:
130  */