* configure.ac: New switch for disabling -O2 (--disable-optimizations).
[cacao.git] / src / vm / jit / x86_64 / freebsd / md-os.c
1 /* src/vm/jit/x86_64/freebsd/md-os.c - machine dependent x86_64 FreeBSD functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5    Copyright (C) 2009 Theobroma Systems Ltd.
6
7    This file is part of CACAO.
8
9    This program is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License as
11    published by the Free Software Foundation; either version 2, or (at
12    your option) any later version.
13
14    This program is distributed in the hope that it will be useful, but
15    WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17    General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22    02110-1301, USA.
23
24 */
25
26
27 #include "config.h"
28
29 #include <assert.h>
30 #include <stdlib.h>
31 #include <ucontext.h>
32
33 #include "threads/thread.hpp"
34
35 #include "vm/signallocal.hpp"
36
37 #include "vm/jit/asmpart.h"
38 #include "vm/jit/stacktrace.hpp"
39
40
41 /* md_signal_handler_sigsegv ***************************************************
42
43    NullPointerException signal handler for hardware null pointer
44    check.
45
46 *******************************************************************************/
47
48 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
49 {
50         ucontext_t *_uc;
51         mcontext_t *_mc;
52         u1         *sp;
53         u1         *ra;
54         u1         *xpc;
55
56         _uc = (ucontext_t *) _p;
57         _mc = &_uc->uc_mcontext;
58
59         sp  = (u1 *) _mc->mc_rsp;
60         xpc = (u1 *) _mc->mc_rip;
61         ra  = xpc;                          /* return address is equal to xpc     */
62
63 #if 0
64         /* check for StackOverflowException */
65
66         threads_check_stackoverflow(sp);
67 #endif
68
69         _mc->mc_rax =
70                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
71
72         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
73         _mc->mc_rip = (ptrint) asm_handle_exception;
74 }
75
76
77 /* md_signal_handler_sigfpe ****************************************************
78
79    ArithmeticException signal handler for hardware divide by zero
80    check.
81
82 *******************************************************************************/
83
84 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
85 {
86         ucontext_t  *_uc;
87         mcontext_t  *_mc;
88         u1          *sp;
89         u1          *ra;
90         u1          *xpc;
91
92         _uc = (ucontext_t *) _p;
93         _mc = &_uc->uc_mcontext;
94
95         sp  = (u1 *) _mc->mc_rsp;
96         xpc = (u1 *) _mc->mc_rip;
97         ra  = xpc;                          /* return address is equal to xpc     */
98
99         _mc->mc_rax =
100                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
101
102         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
103         _mc->mc_rip = (ptrint) asm_handle_exception;
104 }
105
106
107 /* md_signal_handler_sigusr2 ***************************************************
108
109    Signal handler for profiling sampling.
110
111 *******************************************************************************/
112
113 #if defined(ENABLE_THREADS)
114 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
115 {
116         threadobject *t;
117         ucontext_t   *_uc;
118         mcontext_t   *_mc;
119         u1           *pc;
120
121         t = THREADOBJECT;
122
123         _uc = (ucontext_t *) _p;
124         _mc = &_uc->uc_mcontext;
125
126         pc = (u1 *) _mc->mc_rip;
127
128         t->pc = pc;
129 }
130 #endif
131
132
133 /*
134  * These are local overrides for various environment variables in Emacs.
135  * Please do not remove this and leave it at the end of the file, where
136  * Emacs will automagically detect them.
137  * ---------------------------------------------------------------------
138  * Local variables:
139  * mode: c
140  * indent-tabs-mode: t
141  * c-basic-offset: 4
142  * tab-width: 4
143  * End:
144  * vim:noexpandtab:sw=4:ts=4:
145  */