1 /* src/vm/jit/i386/solaris/md-os.c - machine dependent i386 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
34 #define SKIP_REG_DEFS 1
36 #include "vm/jit/i386/codegen.h"
37 #include "vm/jit/i386/md.h"
39 #include "threads/thread.hpp"
41 #include "vm/signallocal.hpp"
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 void* xpc = (void*) _mc->gregs[EIP];
58 trap_handle(TRAP_SIGSEGV, xpc, _p);
62 /* md_signal_handler_sigfpe ****************************************************
64 ArithmeticException signal handler for hardware divide by zero
67 *******************************************************************************/
70 * Signal handler for hardware divide by zero (ArithmeticException)
73 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
75 ucontext_t *_uc = (ucontext_t *) _p;
76 mcontext_t *_mc = &_uc->uc_mcontext;
78 void* xpc = (void*) _mc->gregs[EIP];
81 trap_handle(TRAP_SIGFPE, xpc, _p);
86 * Signal handler for hardware patcher traps (ud2).
88 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
90 ucontext_t *_uc = (ucontext_t *) _p;
91 mcontext_t *_mc = &_uc->uc_mcontext;
93 void* xpc = (void*) _mc->gregs[EIP];
96 trap_handle(TRAP_SIGILL, xpc, _p);
100 /* md_signal_handler_sigusr1 ***************************************************
102 Signal handler for suspending threads.
104 *******************************************************************************/
106 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
107 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
114 _uc = (ucontext_t *) _p;
115 _mc = &_uc->uc_mcontext;
117 /* get the PC and SP for this thread */
118 pc = (u1 *) _mc->gregs[EIP];
119 sp = (u1 *) _mc->gregs[UESP];
121 /* now suspend the current thread */
122 threads_suspend_ack(pc, sp);
127 /* md_signal_handler_sigusr2 ***************************************************
129 Signal handler for profiling sampling.
131 *******************************************************************************/
133 #if defined(ENABLE_THREADS)
134 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
143 _uc = (ucontext_t *) _p;
144 _mc = &_uc->uc_mcontext;
146 pc = (u1 *) _mc->gregs[EIP];
153 /* md_executionstate_read ******************************************************
155 Read the given context into an executionstate for Replacement.
157 *******************************************************************************/
159 void md_executionstate_read(executionstate_t *es, void *context)
165 _uc = (ucontext_t *) context;
166 _mc = &_uc->uc_mcontext;
168 /* read special registers */
169 es->pc = (u1 *) _mc->gregs[EIP];
170 es->sp = (u1 *) _mc->gregs[UESP];
171 es->pv = NULL; /* pv must be looked up via AVL tree */
173 /* read integer registers */
174 for (i = 0; i < INT_REG_CNT; i++)
175 es->intregs[i] = _mc->gregs[EAX - i];
177 /* read float registers */
178 for (i = 0; i < FLT_REG_CNT; i++)
179 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
183 /* md_executionstate_write *****************************************************
185 Write the given executionstate back to the context for Replacement.
187 *******************************************************************************/
189 void md_executionstate_write(executionstate_t *es, void *context)
195 _uc = (ucontext_t *) context;
196 _mc = &_uc->uc_mcontext;
198 /* write integer registers */
199 for (i = 0; i < INT_REG_CNT; i++)
200 _mc->gregs[EAX - i] = es->intregs[i];
202 /* write special registers */
203 _mc->gregs[EIP] = (ptrint) es->pc;
204 _mc->gregs[UESP] = (ptrint) es->sp;
209 * These are local overrides for various environment variables in Emacs.
210 * Please do not remove this and leave it at the end of the file, where
211 * Emacs will automagically detect them.
212 * ---------------------------------------------------------------------
215 * indent-tabs-mode: t