1 /* src/vm/jit/sparc64/linux/md-os.c - machine dependent SPARC Linux functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
36 #include "vm/jit/sparc64/codegen.h"
37 #include "vm/jit/sparc64/md-abi.h"
39 #include "vm/signallocal.h"
40 #include "vm/stringlocal.h"
41 #include "vm/jit/asmpart.h"
42 #include "vm/jit/stacktrace.h"
45 typedef struct sigcontext sigcontext;
47 ptrint md_get_reg_from_context(sigcontext *ctx, u4 rindex)
53 /* return 0 for REG_ZERO */
61 /* register is in global or out range, available in context */
63 val = ctx->sigc_regs.u_regs[rindex];
68 /* register is local or in, need to fetch from regsave area on stack */
70 window = ctx->sigc_regs.u_regs[REG_SP] + BIAS;
71 val = window[rindex - 16];
79 /* md_signal_handler_sigsegv ***************************************************
81 NullPointerException signal handler for hardware null pointer
84 *******************************************************************************/
86 void md_signal_handler_sigsegv(int sig, siginfo_t *info , void *_p)
107 ctx = (sigcontext *) info;
110 pv = (u1 *) md_get_reg_from_context(ctx, REG_PV_CALLEE);
111 sp = (u1 *) md_get_reg_from_context(ctx, REG_SP);
112 ra = (u1 *) md_get_reg_from_context(ctx, REG_RA_CALLEE); /* this is correct for leafs */
113 xpc = (u1 *) ctx->sigc_regs.tpc;
115 /* get exception-throwing instruction */
117 mcode = *((u4 *) xpc);
119 d = M_OP3_GET_RD(mcode);
120 s1 = M_OP3_GET_RS(mcode);
121 disp = M_OP3_GET_IMM(mcode);
123 /* flush register windows? */
125 val = md_get_reg_from_context(ctx, d);
127 /* check for special-load */
129 if (s1 == REG_ZERO) {
130 /* we use the exception type as load displacement */
135 /* This is a normal NPE: addr must be NULL and the NPE-type
138 addr = md_get_reg_from_context(ctx, s1);
142 /* create stackframeinfo */
144 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
146 /* Handle the type. */
148 p = signal_handle(xpc, type, val);
150 /* remove stackframeinfo */
152 stacktrace_remove_stackframeinfo(&sfi);
156 ctx->sigc_regs.u_regs[REG_ITMP2_XPTR] = (intptr_t) p;
157 ctx->sigc_regs.u_regs[REG_ITMP3_XPC] = (intptr_t) xpc;
158 ctx->sigc_regs.tpc = (intptr_t) asm_handle_exception;
159 ctx->sigc_regs.tnpc = (intptr_t) asm_handle_exception + 4;
163 /* md_icacheflush **************************************************************
165 Calls the system's function to flush the instruction cache.
167 *******************************************************************************/
169 void md_icacheflush(u1 *addr, s4 nbytes)
175 /* zero the least significant 3 bits to align on a 64-bit boundary */
176 addr = (u1 *) (((ptrint) addr) & -8l);
188 #if defined(ENABLE_THREADS)
189 /* md_critical_section_restart ************************************************
191 Search the critical sections tree for a matching section and set
192 the NPC to the restart point, if necessary.
194 Reads PC and modifies NPC.
196 ******************************************************************************/
198 void md_critical_section_restart(ucontext_t *_uc)
200 /* mcontext_t *_mc; */
205 printf("ignoring md_critical_section_restart\n");
208 /* again, we are getting sigcontext instead of ucontext */
209 ctx = (sigcontext *) _uc;
211 pc = (u1 *) ctx->sigc_regs.tpc;
213 npc = critical_find_restart_point(pc);
216 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
217 ctx->sigc_regs.tnpc = (ptrint) npc;
224 * These are local overrides for various environment variables in Emacs.
225 * Please do not remove this and leave it at the end of the file, where
226 * Emacs will automagically detect them.
227 * ---------------------------------------------------------------------
230 * indent-tabs-mode: t
234 * vim:noexpandtab:sw=4:ts=4: