1 /* src/vm/jit/sparc64/solaris/md-os.c - machine dependent SPARC Solaris functions
3 Copyright (C) 1996-2005, 2006, 2007, 2008
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
32 /* work around name clash */
37 #include "vm/jit/sparc64/codegen.h"
38 #include "vm/jit/sparc64/md-abi.h"
40 #include "vm/exceptions.h"
41 #include "vm/signallocal.h"
42 #include "vm/stringlocal.h"
44 #include "vm/jit/asmpart.h"
45 #include "vm/jit/stacktrace.h"
46 #include "vm/jit/trap.h"
49 ptrint md_get_reg_from_context(mcontext_t *_mc, u4 rindex)
55 /* return 0 for REG_ZERO */
63 /* register is in global or out range, available in context */
64 val = _mc->gregs[rindex + 3];
70 /* register is local or in, need to fetch from regsave area on stack */
72 window = (s8 *) (_mc->gregs[REG_O6] + BIAS);
73 val = window[rindex - 16];
81 /* md_signal_handler_sigsegv ***************************************************
83 NullPointerException signal handler for hardware null pointer
86 *******************************************************************************/
88 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
105 _uc = (ucontext_t *) _p;
106 _mc = &_uc->uc_mcontext;
108 pv = (u1 *) md_get_reg_from_context(_mc, REG_PV_CALLEE);
109 sp = (u1 *) _mc->gregs[REG_O6];
110 ra = (u1 *) md_get_reg_from_context(_mc, REG_RA_CALLEE);
111 xpc = (u1 *) _mc->gregs[REG_PC];
114 /* get exception-throwing instruction */
116 mcode = *((u4 *) xpc);
118 d = M_OP3_GET_RD(mcode);
119 s1 = M_OP3_GET_RS(mcode);
120 disp = M_OP3_GET_IMM(mcode);
122 /* flush register windows? */
124 val = md_get_reg_from_context(_mc, d);
126 /* check for special-load */
128 if (s1 == REG_ZERO) {
129 /* we use the exception type as load displacement */
134 /* This is a normal NPE: addr must be NULL and the NPE-type
137 addr = md_get_reg_from_context(_mc, s1);
141 /* Handle the trap. */
143 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
147 _mc->gregs[REG_G2] = (uintptr_t) p; /* REG_ITMP2_XPTR */
148 _mc->gregs[REG_G3] = (uintptr_t) xpc; /* REG_ITMP3_XPC */
149 _mc->gregs[REG_PC] = (uintptr_t) asm_handle_exception;
150 _mc->gregs[REG_nPC] = (uintptr_t) asm_handle_exception + 4;
154 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
155 void thread_restartcriticalsection(ucontext_t *_uc)
160 _mc = &_uc->uc_mcontext;
162 critical = thread_checkcritical((void *) _mc->sc_pc);
165 _mc->sc_pc = (ptrint) critical;
170 /* md_icacheflush **************************************************************
172 Calls the system's function to flush the instruction cache.
174 *******************************************************************************/
176 void md_icacheflush(u1 *addr, s4 nbytes)
182 /* zero the least significant 3 bits to align on a 64-bit boundary */
183 addr = (u1 *) (((ptrint) addr) & -8l);
199 * These are local overrides for various environment variables in Emacs.
200 * Please do not remove this and leave it at the end of the file, where
201 * Emacs will automagically detect them.
202 * ---------------------------------------------------------------------
205 * indent-tabs-mode: t