1 /* src/vm/jit/sparc64/linux/md-os.c - machine dependent SPARC Linux functions
3 Copyright (C) 1996-2005, 2006, 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
34 #include "vm/jit/sparc64/codegen.h"
35 #include "vm/jit/sparc64/md-abi.h"
37 #include "vm/signallocal.hpp"
39 #include "vm/jit/asmpart.h"
40 #include "vm/jit/stacktrace.hpp"
41 #include "vm/jit/trap.hpp"
44 typedef struct sigcontext sigcontext;
46 ptrint md_get_reg_from_context(sigcontext *ctx, u4 rindex)
52 /* return 0 for REG_ZERO */
60 /* register is in global or out range, available in context */
62 val = ctx->sigc_regs.u_regs[rindex];
67 /* register is local or in, need to fetch from regsave area on stack */
69 window = ctx->sigc_regs.u_regs[REG_SP] + BIAS;
70 val = window[rindex - 16];
78 /* md_signal_handler_sigsegv ***************************************************
80 NullPointerException signal handler for hardware null pointer
83 *******************************************************************************/
85 void md_signal_handler_sigsegv(int sig, siginfo_t *info , void *_p)
105 ctx = (sigcontext *) info;
108 pv = (u1 *) md_get_reg_from_context(ctx, REG_PV_CALLEE);
109 sp = (u1 *) md_get_reg_from_context(ctx, REG_SP);
110 ra = (u1 *) md_get_reg_from_context(ctx, REG_RA_CALLEE); /* this is correct for leafs */
111 xpc = (u1 *) ctx->sigc_regs.tpc;
113 /* get exception-throwing instruction */
115 mcode = *((u4 *) xpc);
117 d = M_OP3_GET_RD(mcode);
118 s1 = M_OP3_GET_RS(mcode);
119 disp = M_OP3_GET_IMM(mcode);
121 /* flush register windows? */
123 val = md_get_reg_from_context(ctx, d);
125 /* check for special-load */
127 if (s1 == REG_ZERO) {
128 /* we use the exception type as load displacement */
133 /* This is a normal NPE: addr must be NULL and the NPE-type
136 addr = md_get_reg_from_context(ctx, s1);
140 /* Handle the trap. */
142 p = trap_handle(type, val, pv, sp, ra, xpc, _p);
146 ctx->sigc_regs.u_regs[REG_ITMP2_XPTR] = (uintptr_t) p;
147 ctx->sigc_regs.u_regs[REG_ITMP3_XPC] = (uintptr_t) xpc;
148 ctx->sigc_regs.tpc = (uintptr_t) asm_handle_exception;
149 ctx->sigc_regs.tnpc = (uintptr_t) asm_handle_exception + 4;
153 /* md_icacheflush **************************************************************
155 Calls the system's function to flush the instruction cache.
157 *******************************************************************************/
159 void md_icacheflush(u1 *addr, s4 nbytes)
165 /* zero the least significant 3 bits to align on a 64-bit boundary */
166 addr = (u1 *) (((ptrint) addr) & -8l);
180 * These are local overrides for various environment variables in Emacs.
181 * Please do not remove this and leave it at the end of the file, where
182 * Emacs will automagically detect them.
183 * ---------------------------------------------------------------------
186 * indent-tabs-mode: t
190 * vim:noexpandtab:sw=4:ts=4: