1 /* src/vm/jit/x86_64/solaris/md-os.c - machine dependent x86_64 Solaris functions
3 Copyright (C) 2008, 2009
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
35 #include "vm/jit/x86_64/codegen.h"
36 #include "vm/jit/x86_64/md.h"
38 #include "threads/thread.hpp"
40 #include "vm/signallocal.hpp"
42 #include "vm/jit/asmpart.h"
43 #include "vm/jit/executionstate.h"
44 #include "vm/jit/trap.hpp"
48 * Signal handler for hardware exceptions.
50 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
52 ucontext_t *_uc = (ucontext_t *) _p;
53 mcontext_t *_mc = &_uc->uc_mcontext;
55 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
56 different to the ones in <ucontext.h>. */
58 void* xpc = (void *) _mc->gregs[REG_RIP];
61 trap_handle(TRAP_SIGSEGV, xpc, _p);
66 * Signal handler for hardware divide by zero (ArithmeticException)
69 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
71 ucontext_t *_uc = (ucontext_t *) _p;
72 mcontext_t *_mc = &_uc->uc_mcontext;
74 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
75 different to the ones in <ucontext.h>. */
77 void* xpc = (void *) _mc->gregs[REG_RIP];
80 trap_handle(TRAP_SIGFPE, xpc, _p);
85 * Signal handler for hardware patcher traps (ud2).
87 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
89 ucontext_t *_uc = (ucontext_t *) _p;
90 mcontext_t *_mc = &_uc->uc_mcontext;
92 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
93 different to the ones in <ucontext.h>. */
95 void* xpc = (void *) _mc->gregs[REG_RIP];
98 trap_handle(TRAP_SIGILL, xpc, _p);
102 /* md_signal_handler_sigusr2 ***************************************************
104 Signal handler for profiling sampling.
106 *******************************************************************************/
108 #if defined(ENABLE_THREADS)
109 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
118 _uc = (ucontext_t *) _p;
119 _mc = &_uc->uc_mcontext;
121 /* ATTENTION: Don't use CACAO's internal REG_* defines as they are
122 different to the ones in <ucontext.h>. */
124 pc = (u1 *) _mc->gregs[REG_RIP];
131 /* md_executionstate_read ******************************************************
133 Read the given context into an executionstate.
135 *******************************************************************************/
137 void md_executionstate_read(executionstate_t *es, void *context)
144 _uc = (ucontext_t *) context;
145 _mc = &_uc->uc_mcontext;
147 /* read special registers */
148 es->pc = (u1 *) _mc->gregs[REG_RIP];
149 es->sp = (u1 *) _mc->gregs[REG_RSP];
152 /* read integer registers */
153 for (i = 0; i < INT_REG_CNT; i++) {
155 case 0: /* REG_RAX */
158 case 1: /* REG_RCX */
161 case 2: /* REG_RDX */
164 case 3: /* REG_RBX */
167 case 4: /* REG_RSP */
170 case 5: /* REG_RBP */
173 case 6: /* REG_RSI */
176 case 7: /* REG_RDI */
179 case 8: /* REG_R8 == 7 */
180 case 9: /* REG_R9 == 6 */
181 case 10: /* REG_R10 == 5 */
182 case 11: /* REG_R11 == 4 */
183 case 12: /* REG_R12 == 3 */
184 case 13: /* REG_R13 == 2 */
185 case 14: /* REG_R14 == 1 */
186 case 15: /* REG_R15 == 0 */
191 es->intregs[i] = _mc->gregs[d];
194 /* read float registers */
195 for (i = 0; i < FLT_REG_CNT; i++)
196 es->fltregs[i] = 0xdeadbeefdeadbeefL;
200 /* md_executionstate_write *****************************************************
202 Write the given executionstate back to the context.
204 *******************************************************************************/
206 void md_executionstate_write(executionstate_t *es, void *context)
213 _uc = (ucontext_t *) context;
214 _mc = &_uc->uc_mcontext;
216 /* write integer registers */
217 for (i = 0; i < INT_REG_CNT; i++) {
219 case 0: /* REG_RAX */
222 case 1: /* REG_RCX */
225 case 2: /* REG_RDX */
228 case 3: /* REG_RBX */
231 case 4: /* REG_RSP */
234 case 5: /* REG_RBP */
237 case 6: /* REG_RSI */
240 case 7: /* REG_RDI */
243 case 8: /* REG_R8 == 7 */
244 case 9: /* REG_R9 == 6 */
245 case 10: /* REG_R10 == 5 */
246 case 11: /* REG_R11 == 4 */
247 case 12: /* REG_R12 == 3 */
248 case 13: /* REG_R13 == 2 */
249 case 14: /* REG_R14 == 1 */
250 case 15: /* REG_R15 == 0 */
255 _mc->gregs[d] = es->intregs[i];
258 /* write special registers */
259 _mc->gregs[REG_RIP] = (ptrint) es->pc;
260 _mc->gregs[REG_RSP] = (ptrint) es->sp;
265 * These are local overrides for various environment variables in Emacs.
266 * Please do not remove this and leave it at the end of the file, where
267 * Emacs will automagically detect them.
268 * ---------------------------------------------------------------------
271 * indent-tabs-mode: t
275 * vim:noexpandtab:sw=4:ts=4: