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 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/jit/builtin.hpp"
42 #include "vm/signallocal.h"
45 #include "vm/jit/asmpart.h"
46 #include "vm/jit/disass.h"
47 #include "vm/jit/executionstate.h"
48 #include "vm/jit/trap.h"
51 /* md_signal_handler_sigsegv ***************************************************
53 NullPointerException signal handler for hardware null pointer
56 *******************************************************************************/
58 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
74 _uc = (ucontext_t *) _p;
75 _mc = &_uc->uc_mcontext;
77 pv = (u1 *) _mc->sc_regs[REG_PV];
78 sp = (u1 *) _mc->sc_regs[REG_SP];
79 ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
80 xpc = (u1 *) _mc->sc_pc;
82 /* get exception-throwing instruction */
84 mcode = *((u4 *) xpc);
86 d = M_MEM_GET_Ra(mcode);
87 s1 = M_MEM_GET_Rb(mcode);
88 disp = M_MEM_GET_Memory_disp(mcode);
90 val = _mc->sc_regs[d];
92 /* check for special-load */
95 /* we use the exception type as load displacement */
99 if (type == TRAP_COMPILER) {
100 /* The XPC is the RA minus 1, because the RA points to the
101 instruction after the call. */
107 /* This is a normal NPE: addr must be NULL and the NPE-type
110 addr = _mc->sc_regs[s1];
114 /* Handle the trap. */
116 trap_handle(type, val, pv, sp, ra, xpc, _p);
120 /* md_signal_handler_sigill ****************************************************
122 Illegal Instruction signal handler for hardware exception checks.
124 *******************************************************************************/
126 void md_signal_handler_sigill(int sig, siginfo_t *siginfo, void *_p)
128 ucontext_t* _uc = (ucontext_t*) _p;
129 mcontext_t* _mc = &_uc->uc_mcontext;
131 void* pv = (u1 *) _mc->sc_regs[REG_PV];
132 void* sp = (u1 *) _mc->sc_regs[REG_SP];
133 void* ra = (u1 *) _mc->sc_regs[REG_RA]; // RA is correct for leaf methods.
134 void* xpc = (u1 *) _mc->sc_pc;
136 // The PC points to the instruction after the illegal instruction.
137 xpc = (void*) (((uintptr_t) xpc) - 4);
139 // Get the exception-throwing instruction.
140 uint32_t mcode = *((uint32_t*) xpc);
142 int opcode = M_OP3_GET_Opcode(mcode);
144 // Check for undefined instruction we use.
145 // TODO Check the whole instruction.
147 log_println("md_signal_handler_sigill: Unknown illegal instruction %x at %p", mcode, xpc);
148 #if defined(ENABLE_DISASSEMBLER)
149 (void) disassinstr(xpc);
151 vm_abort("Aborting...");
154 // This signal is always a patcher.
155 int type = TRAP_PATCHER;
159 trap_handle(type, val, pv, sp, ra, xpc, _p);
163 /* md_signal_handler_sigusr1 ***************************************************
165 Signal handler for suspending threads.
167 *******************************************************************************/
169 #if defined(ENABLE_THREADS) && defined(ENABLE_GC_CACAO)
170 void md_signal_handler_sigusr1(int sig, siginfo_t *siginfo, void *_p)
177 _uc = (ucontext_t *) _p;
178 _mc = &_uc->uc_mcontext;
180 /* get the PC and SP for this thread */
181 pc = (u1 *) _mc->sc_pc;
182 sp = (u1 *) _mc->sc_regs[REG_SP];
184 /* now suspend the current thread */
185 threads_suspend_ack(pc, sp);
190 /* md_signal_handler_sigusr2 ***************************************************
192 Signal handler for profiling sampling.
194 *******************************************************************************/
196 #if defined(ENABLE_THREADS)
197 void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
206 _uc = (ucontext_t *) _p;
207 _mc = &_uc->uc_mcontext;
209 pc = (u1 *) _mc->sc_pc;
216 /* md_executionstate_read ******************************************************
218 Read the given context into an executionstate.
220 *******************************************************************************/
222 void md_executionstate_read(executionstate_t *es, void *context)
228 _uc = (ucontext_t *) context;
229 _mc = &_uc->uc_mcontext;
231 /* read special registers */
232 es->pc = (u1 *) _mc->sc_pc;
233 es->sp = (u1 *) _mc->sc_regs[REG_SP];
234 es->pv = (u1 *) _mc->sc_regs[REG_PV];
235 es->ra = (u1 *) _mc->sc_regs[REG_RA];
237 /* read integer registers */
238 for (i = 0; i < INT_REG_CNT; i++)
239 es->intregs[i] = _mc->sc_regs[i];
241 /* read float registers */
242 /* Do not use the assignment operator '=', as the type of
243 * the _mc->sc_fpregs[i] can cause invalid conversions. */
245 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
246 os_memcpy(&es->fltregs, &_mc->sc_fpregs, sizeof(_mc->sc_fpregs));
250 /* md_executionstate_write *****************************************************
252 Write the given executionstate back to the context.
254 *******************************************************************************/
256 void md_executionstate_write(executionstate_t *es, void *context)
262 _uc = (ucontext_t *) context;
263 _mc = &_uc->uc_mcontext;
265 /* write integer registers */
266 for (i = 0; i < INT_REG_CNT; i++)
267 _mc->sc_regs[i] = es->intregs[i];
269 /* write float registers */
270 /* Do not use the assignment operator '=', as the type of
271 * the _mc->sc_fpregs[i] can cause invalid conversions. */
273 assert(sizeof(_mc->sc_fpregs) == sizeof(es->fltregs));
274 os_memcpy(&_mc->sc_fpregs, &es->fltregs, sizeof(_mc->sc_fpregs));
276 /* write special registers */
277 _mc->sc_pc = (ptrint) es->pc;
278 _mc->sc_regs[REG_SP] = (ptrint) es->sp;
279 _mc->sc_regs[REG_PV] = (ptrint) es->pv;
280 _mc->sc_regs[REG_RA] = (ptrint) es->ra;
285 * These are local overrides for various environment variables in Emacs.
286 * Please do not remove this and leave it at the end of the file, where
287 * Emacs will automagically detect them.
288 * ---------------------------------------------------------------------
291 * indent-tabs-mode: t