1 /* src/vm/jit/i386/linux/md-os.c - machine dependent i386 Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2009 Theobroma Systems Ltd.
7 This file is part of CACAO.
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #define _GNU_SOURCE /* include REG_ defines from ucontext.h */
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[REG_EIP];
58 trap_handle(TRAP_SIGSEGV, xpc, _p);
63 * Signal handler for hardware divide by zero (ArithmeticException)
66 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
68 ucontext_t* _uc = (ucontext_t *) _p;
69 mcontext_t* _mc = &_uc->uc_mcontext;
71 void* xpc = (void*) _mc->gregs[REG_EIP];
74 trap_handle(TRAP_SIGFPE, xpc, _p);
79 * Signal handler for hardware patcher traps (ud2).
81 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
83 ucontext_t* _uc = (ucontext_t *) _p;
84 mcontext_t* _mc = &_uc->uc_mcontext;
86 void* xpc = (void*) _mc->gregs[REG_EIP];
89 trap_handle(TRAP_SIGILL, xpc, _p);
93 /* md_signal_handler_sigusr1 ***************************************************
95 Signal handler for suspending threads.
97 *******************************************************************************/
99 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
100 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
107 _uc = (ucontext_t *) _p;
108 _mc = &_uc->uc_mcontext;
110 /* get the PC and SP for this thread */
111 pc = (u1 *) _mc->gregs[REG_EIP];
112 sp = (u1 *) _mc->gregs[REG_ESP];
114 /* now suspend the current thread */
115 threads_suspend_ack(pc, sp);
120 /* md_signal_handler_sigusr2 ***************************************************
122 Signal handler for profiling sampling.
124 *******************************************************************************/
126 #if defined(ENABLE_THREADS)
127 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
136 _uc = (ucontext_t *) _p;
137 _mc = &_uc->uc_mcontext;
139 pc = (u1 *) _mc->gregs[REG_EIP];
146 /* md_executionstate_read ******************************************************
148 Read the given context into an executionstate for Replacement.
150 *******************************************************************************/
152 void md_executionstate_read(executionstate_t *es, void *context)
158 _uc = (ucontext_t *) context;
159 _mc = &_uc->uc_mcontext;
161 /* read special registers */
162 es->pc = (u1 *) _mc->gregs[REG_EIP];
163 es->sp = (u1 *) _mc->gregs[REG_ESP];
164 es->pv = NULL; /* pv must be looked up via AVL tree */
166 /* read integer registers */
167 for (i = 0; i < INT_REG_CNT; i++)
168 es->intregs[i] = _mc->gregs[REG_EAX - i];
170 /* read float registers */
171 for (i = 0; i < FLT_REG_CNT; i++)
172 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
176 /* md_executionstate_write *****************************************************
178 Write the given executionstate back to the context for Replacement.
180 *******************************************************************************/
182 void md_executionstate_write(executionstate_t *es, void *context)
188 _uc = (ucontext_t *) context;
189 _mc = &_uc->uc_mcontext;
191 /* write integer registers */
192 for (i = 0; i < INT_REG_CNT; i++)
193 _mc->gregs[REG_EAX - i] = es->intregs[i];
195 /* write special registers */
196 _mc->gregs[REG_EIP] = (ptrint) es->pc;
197 _mc->gregs[REG_ESP] = (ptrint) es->sp;
202 * These are local overrides for various environment variables in Emacs.
203 * Please do not remove this and leave it at the end of the file, where
204 * Emacs will automagically detect them.
205 * ---------------------------------------------------------------------
208 * indent-tabs-mode: t