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