1 /* src/vm/jit/i386/solaris/md-os.c - machine dependent i386 Solaris functions
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
33 #include "vm/jit/i386/codegen.h"
34 #include "vm/jit/i386/md.h"
36 #include "threads/thread.hpp"
38 #include "vm/jit/builtin.hpp"
39 #include "vm/signallocal.h"
41 #include "vm/jit/asmpart.h"
42 #include "vm/jit/executionstate.h"
43 #include "vm/jit/stacktrace.hpp"
44 #include "vm/jit/trap.h"
47 /* md_signal_handler_sigsegv ***************************************************
49 Signal handler for hardware exceptions.
51 *******************************************************************************/
53 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
70 _uc = (ucontext_t *) _p;
71 _mc = &_uc->uc_mcontext;
73 pv = NULL; /* is resolved during stackframeinfo creation */
74 sp = (u1 *) _mc->gregs[ESP];
75 xpc = (u1 *) _mc->gregs[EIP];
76 ra = xpc; /* return address is equal to XPC */
78 /* get exception-throwing instruction */
80 opc = M_ALD_MEM_GET_OPC(xpc);
81 mod = M_ALD_MEM_GET_MOD(xpc);
82 rm = M_ALD_MEM_GET_RM(xpc);
84 /* for values see emit_mov_mem_reg and emit_mem */
86 if ((opc == 0x8b) && (mod == 0) && (rm == 5)) {
87 /* this was a hardware-exception */
89 d = M_ALD_MEM_GET_REG(xpc);
90 disp = M_ALD_MEM_GET_DISP(xpc);
92 /* we use the exception type as load displacement */
96 /* ATTENTION: The _mc->gregs layout is completely crazy! The
97 registers are reversed starting with number 4 for REG_EDI
98 (see /usr/include/sys/ucontext.h). We have to convert that
101 val = _mc->gregs[EAX - d];
103 if (type == TRAP_COMPILER) {
104 /* The PV from the compiler stub is equal to the XPC. */
108 /* We use a framesize of zero here because the call pushed
109 the return addres onto the stack. */
111 ra = md_stacktrace_get_returnaddress(sp, 0);
113 /* Skip the RA on the stack. */
115 sp = sp + 1 * SIZEOF_VOID_P;
117 /* The XPC is the RA minus 2, because the RA points to the
118 instruction after the call. */
124 /* this was a normal NPE */
126 type = TRAP_NullPointerException;
130 /* Handle the trap. */
132 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
136 if (type == TRAP_COMPILER) {
138 _mc->gregs[ESP] = (uintptr_t) sp; /* Remove RA from stack. */
144 /* md_signal_handler_sigfpe ****************************************************
146 ArithmeticException signal handler for hardware divide by zero
149 *******************************************************************************/
151 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
162 _uc = (ucontext_t *) _p;
163 _mc = &_uc->uc_mcontext;
165 pv = NULL; /* is resolved during stackframeinfo creation */
166 sp = (u1 *) _mc->gregs[ESP];
167 xpc = (u1 *) _mc->gregs[EIP];
168 ra = xpc; /* return address is equal to xpc */
170 /* This is an ArithmeticException. */
172 type = TRAP_ArithmeticException;
175 /* Handle the trap. */
177 trap_handle(type, val, pv, sp, ra, xpc, _p);
181 /* md_signal_handler_sigill ****************************************************
183 Signal handler for hardware patcher traps (ud2).
185 *******************************************************************************/
187 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
198 _uc = (ucontext_t *) _p;
199 _mc = &_uc->uc_mcontext;
201 pv = NULL; /* is resolved during stackframeinfo creation */
202 sp = (u1 *) _mc->gregs[ESP];
203 xpc = (u1 *) _mc->gregs[EIP];
204 ra = xpc; /* return address is equal to xpc */
209 /* Handle the trap. */
211 trap_handle(type, val, pv, sp, ra, xpc, _p);
215 /* md_signal_handler_sigusr1 ***************************************************
217 Signal handler for suspending threads.
219 *******************************************************************************/
221 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
222 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
229 _uc = (ucontext_t *) _p;
230 _mc = &_uc->uc_mcontext;
232 /* get the PC and SP for this thread */
233 pc = (u1 *) _mc->gregs[EIP];
234 sp = (u1 *) _mc->gregs[ESP];
236 /* now suspend the current thread */
237 threads_suspend_ack(pc, sp);
242 /* md_signal_handler_sigusr2 ***************************************************
244 Signal handler for profiling sampling.
246 *******************************************************************************/
248 #if defined(ENABLE_THREADS)
249 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
258 _uc = (ucontext_t *) _p;
259 _mc = &_uc->uc_mcontext;
261 pc = (u1 *) _mc->gregs[EIP];
268 /* md_executionstate_read ******************************************************
270 Read the given context into an executionstate for Replacement.
272 *******************************************************************************/
274 void md_executionstate_read(executionstate_t *es, void *context)
280 _uc = (ucontext_t *) context;
281 _mc = &_uc->uc_mcontext;
283 /* read special registers */
284 es->pc = (u1 *) _mc->gregs[EIP];
285 es->sp = (u1 *) _mc->gregs[ESP];
286 es->pv = NULL; /* pv must be looked up via AVL tree */
288 /* read integer registers */
289 for (i = 0; i < INT_REG_CNT; i++)
290 es->intregs[i] = _mc->gregs[EAX - i];
292 /* read float registers */
293 for (i = 0; i < FLT_REG_CNT; i++)
294 es->fltregs[i] = 0xdeadbeefdeadbeefULL;
298 /* md_executionstate_write *****************************************************
300 Write the given executionstate back to the context for Replacement.
302 *******************************************************************************/
304 void md_executionstate_write(executionstate_t *es, void *context)
310 _uc = (ucontext_t *) context;
311 _mc = &_uc->uc_mcontext;
313 /* write integer registers */
314 for (i = 0; i < INT_REG_CNT; i++)
315 _mc->gregs[EAX - i] = es->intregs[i];
317 /* write special registers */
318 _mc->gregs[EIP] = (ptrint) es->pc;
319 _mc->gregs[ESP] = (ptrint) es->sp;
324 * These are local overrides for various environment variables in Emacs.
325 * Please do not remove this and leave it at the end of the file, where
326 * Emacs will automagically detect them.
327 * ---------------------------------------------------------------------
330 * indent-tabs-mode: t