1 /* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 Copyright (C) 2008, 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
35 #include "vm/jit/alpha/codegen.h"
36 #include "vm/jit/alpha/md.h"
37 #include "vm/jit/alpha/md-abi.h"
39 #include "threads/thread.hpp"
41 #include "vm/signallocal.hpp"
43 #include "vm/jit/executionstate.h"
44 #include "vm/jit/trap.hpp"
48 * NullPointerException signal handler for hardware null pointer check.
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->sc_pc;
58 trap_handle(TRAP_SIGSEGV, xpc, _p);
63 * Illegal Instruction signal handler for hardware exception checks.
65 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
67 ucontext_t* _uc = (ucontext_t*) _p;
68 mcontext_t* _mc = &_uc->uc_mcontext;
70 void* xpc = (void*) _mc->sc_pc;
72 // The PC points to the instruction after the illegal instruction.
73 xpc = (void*) (((uintptr_t) xpc) - 4);
76 trap_handle(TRAP_SIGILL, xpc, _p);
80 /* md_signal_handler_sigusr1 ***************************************************
82 Signal handler for suspending threads.
84 *******************************************************************************/
86 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
87 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
94 _uc = (ucontext_t *) _p;
95 _mc = &_uc->uc_mcontext;
97 /* get the PC and SP for this thread */
98 pc = (u1 *) _mc->sc_pc;
99 sp = (u1 *) _mc->sc_regs[REG_SP];
101 /* now suspend the current thread */
102 threads_suspend_ack(pc, sp);
107 /* md_signal_handler_sigusr2 ***************************************************
109 Signal handler for profiling sampling.
111 *******************************************************************************/
113 #if defined(ENABLE_THREADS)
114 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
123 _uc = (ucontext_t *) _p;
124 _mc = &_uc->uc_mcontext;
126 pc = (u1 *) _mc->sc_pc;
133 /* md_executionstate_read ******************************************************
135 Read the given context into an executionstate.
137 *******************************************************************************/
139 void md_executionstate_read(executionstate_t *es, void *context)
145 _uc = (ucontext_t *) context;
146 _mc = &_uc->uc_mcontext;
148 /* read special registers */
149 es->pc = (u1 *) _mc->sc_pc;
150 es->sp = (u1 *) _mc->sc_regs[REG_SP];
151 es->pv = (u1 *) _mc->sc_regs[REG_PV];
152 es->ra = (u1 *) _mc->sc_regs[REG_RA];
154 /* read integer registers */
155 for (i = 0; i < INT_REG_CNT; i++)
156 es->intregs[i] = _mc->sc_regs[i];
158 /* read float registers */
159 /* Do not use the assignment operator '=', as the type of
160 * the _mc->sc_fpregs[i] can cause invalid conversions. */
162 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
163 os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
167 /* md_executionstate_write *****************************************************
169 Write the given executionstate back to the context.
171 *******************************************************************************/
173 void md_executionstate_write(executionstate_t *es, void *context)
179 _uc = (ucontext_t *) context;
180 _mc = &_uc->uc_mcontext;
182 /* write integer registers */
183 for (i = 0; i < INT_REG_CNT; i++)
184 _mc->sc_regs[i] = es->intregs[i];
186 /* write float registers */
187 /* Do not use the assignment operator '=', as the type of
188 * the _mc->sc_fpregs[i] can cause invalid conversions. */
190 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
191 os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
193 /* write special registers */
194 _mc->sc_pc = (ptrint) es->pc;
195 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
196 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
197 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
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