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_sigusr2 ***************************************************
82 Signal handler for profiling sampling.
84 *******************************************************************************/
86 #if defined(ENABLE_THREADS)
87 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
96 _uc = (ucontext_t *) _p;
97 _mc = &_uc->uc_mcontext;
99 pc = (u1 *) _mc->sc_pc;
106 /* md_executionstate_read ******************************************************
108 Read the given context into an executionstate.
110 *******************************************************************************/
112 void md_executionstate_read(executionstate_t *es, void *context)
118 _uc = (ucontext_t *) context;
119 _mc = &_uc->uc_mcontext;
121 /* read special registers */
122 es->pc = (u1 *) _mc->sc_pc;
123 es->sp = (u1 *) _mc->sc_regs[REG_SP];
124 es->pv = (u1 *) _mc->sc_regs[REG_PV];
125 es->ra = (u1 *) _mc->sc_regs[REG_RA];
127 /* read integer registers */
128 for (i = 0; i < INT_REG_CNT; i++)
129 es->intregs[i] = _mc->sc_regs[i];
131 /* read float registers */
132 /* Do not use the assignment operator '=', as the type of
133 * the _mc->sc_fpregs[i] can cause invalid conversions. */
135 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
136 os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
140 /* md_executionstate_write *****************************************************
142 Write the given executionstate back to the context.
144 *******************************************************************************/
146 void md_executionstate_write(executionstate_t *es, void *context)
152 _uc = (ucontext_t *) context;
153 _mc = &_uc->uc_mcontext;
155 /* write integer registers */
156 for (i = 0; i < INT_REG_CNT; i++)
157 _mc->sc_regs[i] = es->intregs[i];
159 /* write float registers */
160 /* Do not use the assignment operator '=', as the type of
161 * the _mc->sc_fpregs[i] can cause invalid conversions. */
163 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
164 os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
166 /* write special registers */
167 _mc->sc_pc = (ptrint) es->pc;
168 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
169 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
170 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
175 * These are local overrides for various environment variables in Emacs.
176 * Please do not remove this and leave it at the end of the file, where
177 * Emacs will automagically detect them.
178 * ---------------------------------------------------------------------
181 * indent-tabs-mode: t