Merged trunk and subtype.
[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, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <ucontext.h>
29
30 #include "vm/jit/i386/md-abi.h"
31
32 #include "vm/signallocal.h"
33 #include "vm/jit/asmpart.h"
34 #include "vm/jit/stacktrace.hpp"
35
36
37 /* md_signal_handler_sigsegv ***************************************************
38
39    NullPointerException signal handler for hardware null pointer
40    check.
41
42 *******************************************************************************/
43
44 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
45 {
46         ucontext_t *_uc;
47         mcontext_t *_mc;
48         u1         *sp;
49         u1         *ra;
50         u1         *xpc;
51
52         _uc = (ucontext_t *) _p;
53         _mc = &_uc->uc_mcontext;
54         
55         sp  = (u1 *) _mc->mc_esp;
56         xpc = (u1 *) _mc->mc_eip;
57         ra  = xpc;                          /* return address is equal to xpc     */
58
59         _mc->mc_eax =
60                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
61         
62         _mc->mc_ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
63         _mc->mc_eip = (ptrint) asm_handle_exception;
64 }
65
66
67 /* md_signal_handler_sigfpe ****************************************************
68
69    ArithmeticException signal handler for hardware divide by zero
70    check.
71
72 *******************************************************************************/
73
74 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
75 {
76         ucontext_t *_uc;
77         mcontext_t *_mc;
78         u1         *sp;
79         u1         *ra;
80         u1         *xpc;
81
82         _uc = (ucontext_t *) _p;
83         _mc = &_uc->uc_mcontext;
84
85         sp  = (u1 *) _mc->mc_esp;
86         xpc = (u1 *) _mc->mc_eip;
87         ra  = xpc;                          /* return address is equal to xpc     */
88
89         _mc->mc_eax =
90                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
91         
92         _mc->mc_ecx = (ptrint) xpc;                              /* REG_ITMP2_XPC */
93         _mc->mc_eip = (ptrint) asm_handle_exception;
94 }
95
96
97 /*
98  * These are local overrides for various environment variables in Emacs.
99  * Please do not remove this and leave it at the end of the file, where
100  * Emacs will automagically detect them.
101  * ---------------------------------------------------------------------
102  * Local variables:
103  * mode: c
104  * indent-tabs-mode: t
105  * c-basic-offset: 4
106  * tab-width: 4
107  * End:
108  */