* Removed all Id tags.
[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 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 */
26
27
28 #include "config.h"
29
30 #include <assert.h>
31 #include <stdlib.h>
32 #include <ucontext.h>
33
34 #if defined(ENABLE_THREADS)
35 # include "threads/native/threads.h"
36 #endif
37
38 #include "vm/signallocal.h"
39
40 #include "vm/jit/asmpart.h"
41 #include "vm/jit/stacktrace.h"
42
43
44 /* md_signal_handler_sigsegv ***************************************************
45
46    NullPointerException signal handler for hardware null pointer
47    check.
48
49 *******************************************************************************/
50
51 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
52 {
53         ucontext_t *_uc;
54         mcontext_t *_mc;
55         u1         *sp;
56         u1         *ra;
57         u1         *xpc;
58
59         _uc = (ucontext_t *) _p;
60         _mc = &_uc->uc_mcontext;
61
62         sp  = (u1 *) _mc->mc_rsp;
63         xpc = (u1 *) _mc->mc_rip;
64         ra  = xpc;                          /* return address is equal to xpc     */
65
66 #if 0
67         /* check for StackOverflowException */
68
69         threads_check_stackoverflow(sp);
70 #endif
71
72         _mc->mc_rax =
73                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
74
75         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
76         _mc->mc_rip = (ptrint) asm_handle_exception;
77 }
78
79
80 /* md_signal_handler_sigfpe ****************************************************
81
82    ArithmeticException signal handler for hardware divide by zero
83    check.
84
85 *******************************************************************************/
86
87 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
88 {
89         ucontext_t  *_uc;
90         mcontext_t  *_mc;
91         u1          *sp;
92         u1          *ra;
93         u1          *xpc;
94
95         _uc = (ucontext_t *) _p;
96         _mc = &_uc->uc_mcontext;
97
98         sp  = (u1 *) _mc->mc_rsp;
99         xpc = (u1 *) _mc->mc_rip;
100         ra  = xpc;                          /* return address is equal to xpc     */
101
102         _mc->mc_rax =
103                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
104
105         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
106         _mc->mc_rip = (ptrint) asm_handle_exception;
107 }
108
109
110 /* md_signal_handler_sigusr2 ***************************************************
111
112    Signal handler for profiling sampling.
113
114 *******************************************************************************/
115
116 #if defined(ENABLE_THREADS)
117 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
118 {
119         threadobject *t;
120         ucontext_t   *_uc;
121         mcontext_t   *_mc;
122         u1           *pc;
123
124         t = THREADOBJECT;
125
126         _uc = (ucontext_t *) _p;
127         _mc = &_uc->uc_mcontext;
128
129         pc = (u1 *) _mc->mc_rip;
130
131         t->pc = pc;
132 }
133 #endif
134
135
136 #if defined(ENABLE_THREADS)
137 void thread_restartcriticalsection(ucontext_t *_uc)
138 {
139         mcontext_t *_mc;
140         u1         *pc;
141         void       *critical;
142
143         _mc = &_uc->uc_mcontext;
144
145         pc = (u1 *) _mc->mc_rip;
146
147         critical = critical_find_restart_point(pc);
148
149         if (critical != NULL)
150                 _mc->mc_rip = (ptrint) critical;
151 }
152 #endif
153
154
155 /*
156  * These are local overrides for various environment variables in Emacs.
157  * Please do not remove this and leave it at the end of the file, where
158  * Emacs will automagically detect them.
159  * ---------------------------------------------------------------------
160  * Local variables:
161  * mode: c
162  * indent-tabs-mode: t
163  * c-basic-offset: 4
164  * tab-width: 4
165  * End:
166  * vim:noexpandtab:sw=4:ts=4:
167  */