merged volatile memory barriers
[cacao.git] / src / vm / jit / i386 / solaris / md-os.c
1 /* src/vm/jit/i386/solaris/md-os.c - machine dependent i386 Solaris functions
2
3    Copyright (C) 2008, 2009
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 <stdint.h>
29 #include <ucontext.h>
30
31 #include "vm/types.h"
32 #include "vm/os.hpp"
33
34 #define SKIP_REG_DEFS 1
35
36 #include "vm/jit/i386/codegen.h"
37 #include "vm/jit/i386/md.h"
38
39 #include "threads/thread.hpp"
40
41 #include "vm/signallocal.hpp"
42
43 #include "vm/jit/executionstate.h"
44 #include "vm/jit/trap.hpp"
45
46
47 /**
48  * Signal handler for hardware exceptions.
49  */
50 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
51 {
52         ucontext_t *_uc = (ucontext_t *) _p;
53         mcontext_t *_mc = &_uc->uc_mcontext;
54
55         void* xpc = (void*) _mc->gregs[EIP];
56
57     // Handle the trap.
58     trap_handle(TRAP_SIGSEGV, xpc, _p);
59 }
60
61
62 /**
63  * Signal handler for hardware divide by zero (ArithmeticException)
64  * check.
65  */
66 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
67 {
68         ucontext_t *_uc = (ucontext_t *) _p;
69         mcontext_t *_mc = &_uc->uc_mcontext;
70
71         void* xpc = (void*) _mc->gregs[EIP];
72
73     // Handle the trap.
74     trap_handle(TRAP_SIGFPE, xpc, _p);
75 }
76
77
78 /**
79  * Signal handler for hardware patcher traps (ud2).
80  */
81 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
82 {
83         ucontext_t *_uc = (ucontext_t *) _p;
84         mcontext_t *_mc = &_uc->uc_mcontext;
85
86         void* xpc = (void*) _mc->gregs[EIP];
87
88     // Handle the trap.
89     trap_handle(TRAP_SIGILL, xpc, _p);
90 }
91
92
93 /* md_signal_handler_sigusr2 ***************************************************
94
95    Signal handler for profiling sampling.
96
97 *******************************************************************************/
98
99 #if defined(ENABLE_THREADS)
100 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
101 {
102         threadobject *t;
103         ucontext_t   *_uc;
104         mcontext_t   *_mc;
105         u1           *pc;
106
107         t = THREADOBJECT;
108
109         _uc = (ucontext_t *) _p;
110         _mc = &_uc->uc_mcontext;
111
112         pc = (u1 *) _mc->gregs[EIP];
113
114         t->pc = pc;
115 }
116 #endif
117
118
119 /* md_executionstate_read ******************************************************
120
121    Read the given context into an executionstate for Replacement.
122
123 *******************************************************************************/
124
125 void md_executionstate_read(executionstate_t *es, void *context)
126 {
127         ucontext_t *_uc;
128         mcontext_t *_mc;
129         s4          i;
130
131         _uc = (ucontext_t *) context;
132         _mc = &_uc->uc_mcontext;
133
134         /* read special registers */
135         es->pc = (u1 *) _mc->gregs[EIP];
136         es->sp = (u1 *) _mc->gregs[UESP];
137         es->pv = NULL;                   /* pv must be looked up via AVL tree */
138
139         /* read integer registers */
140         for (i = 0; i < INT_REG_CNT; i++)
141                 es->intregs[i] = _mc->gregs[EAX - i];
142
143         /* read float registers */
144         for (i = 0; i < FLT_REG_CNT; i++)
145                 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
146 }
147
148
149 /* md_executionstate_write *****************************************************
150
151    Write the given executionstate back to the context for Replacement.
152
153 *******************************************************************************/
154
155 void md_executionstate_write(executionstate_t *es, void *context)
156 {
157         ucontext_t *_uc;
158         mcontext_t *_mc;
159         s4          i;
160
161         _uc = (ucontext_t *) context;
162         _mc = &_uc->uc_mcontext;
163
164         /* write integer registers */
165         for (i = 0; i < INT_REG_CNT; i++)
166                 _mc->gregs[EAX - i] = es->intregs[i];
167
168         /* write special registers */
169         _mc->gregs[EIP] = (ptrint) es->pc;
170         _mc->gregs[UESP] = (ptrint) es->sp;
171 }
172
173
174 /*
175  * These are local overrides for various environment variables in Emacs.
176  * Please do not remove this and leave it at the end of the file, where
177  * Emacs will automagically detect them.
178  * ---------------------------------------------------------------------
179  * Local variables:
180  * mode: c
181  * indent-tabs-mode: t
182  * c-basic-offset: 4
183  * tab-width: 4
184  * End:
185  */