* src/native/vm/openjdk/jvm.cpp (JVM_CurrentClassLoader): Implemented.
[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
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 <assert.h>
29 #include <stdlib.h>
30 #include <ucontext.h>
31
32 #include "threads/thread.hpp"
33
34 #include "vm/signallocal.hpp"
35
36 #include "vm/jit/asmpart.h"
37 #include "vm/jit/stacktrace.hpp"
38
39
40 /* md_signal_handler_sigsegv ***************************************************
41
42    NullPointerException signal handler for hardware null pointer
43    check.
44
45 *******************************************************************************/
46
47 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
48 {
49         ucontext_t *_uc;
50         mcontext_t *_mc;
51         u1         *sp;
52         u1         *ra;
53         u1         *xpc;
54
55         _uc = (ucontext_t *) _p;
56         _mc = &_uc->uc_mcontext;
57
58         sp  = (u1 *) _mc->mc_rsp;
59         xpc = (u1 *) _mc->mc_rip;
60         ra  = xpc;                          /* return address is equal to xpc     */
61
62 #if 0
63         /* check for StackOverflowException */
64
65         threads_check_stackoverflow(sp);
66 #endif
67
68         _mc->mc_rax =
69                 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
70
71         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
72         _mc->mc_rip = (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_rsp;
95         xpc = (u1 *) _mc->mc_rip;
96         ra  = xpc;                          /* return address is equal to xpc     */
97
98         _mc->mc_rax =
99                 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
100
101         _mc->mc_r10 = (ptrint) xpc;                              /* REG_ITMP2_XPC */
102         _mc->mc_rip = (ptrint) asm_handle_exception;
103 }
104
105
106 /* md_signal_handler_sigusr2 ***************************************************
107
108    Signal handler for profiling sampling.
109
110 *******************************************************************************/
111
112 #if defined(ENABLE_THREADS)
113 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
114 {
115         threadobject *t;
116         ucontext_t   *_uc;
117         mcontext_t   *_mc;
118         u1           *pc;
119
120         t = THREADOBJECT;
121
122         _uc = (ucontext_t *) _p;
123         _mc = &_uc->uc_mcontext;
124
125         pc = (u1 *) _mc->mc_rip;
126
127         t->pc = pc;
128 }
129 #endif
130
131
132 /*
133  * These are local overrides for various environment variables in Emacs.
134  * Please do not remove this and leave it at the end of the file, where
135  * Emacs will automagically detect them.
136  * ---------------------------------------------------------------------
137  * Local variables:
138  * mode: c
139  * indent-tabs-mode: t
140  * c-basic-offset: 4
141  * tab-width: 4
142  * End:
143  * vim:noexpandtab:sw=4:ts=4:
144  */