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
25 $Id: md-os.c 7363 2007-02-15 14:57:04Z twisti $
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"
43 #include "vm/jit/asmpart.h"
44 #include "vm/jit/stacktrace.h"
47 typedef struct sigcontext sigcontext;
49 ptrint md_get_reg_from_context(sigcontext *ctx, u4 rindex)
55 /* return 0 for REG_ZERO */
63 /* register is in global or out range, available in context */
65 val = ctx->sigc_regs.u_regs[rindex];
70 /* register is local or in, need to fetch from regsave area on stack */
72 window = ctx->sigc_regs.u_regs[REG_SP] + 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 *info , void *_p)
107 java_objectheader *e;
109 ctx = (sigcontext *) info;
112 pv = (u1 *) md_get_reg_from_context(ctx, REG_PV_CALLEE);
113 sp = (u1 *) md_get_reg_from_context(ctx, REG_SP);
114 ra = (u1 *) md_get_reg_from_context(ctx, REG_RA_CALLEE); /* this is correct for leafs */
115 xpc = (u1 *) ctx->sigc_regs.tpc;
117 /* get exception-throwing instruction */
119 mcode = *((u4 *) xpc);
121 d = M_OP3_GET_RD(mcode);
122 s1 = M_OP3_GET_RS(mcode);
123 disp = M_OP3_GET_IMM(mcode);
125 /* flush register windows? */
127 val = md_get_reg_from_context(ctx, d);
129 /* check for special-load */
131 if (s1 == REG_ZERO) {
132 /* we use the exception type as load displacement */
137 /* This is a normal NPE: addr must be NULL and the NPE-type
140 addr = md_get_reg_from_context(ctx, s1);
144 /* create stackframeinfo */
146 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
148 /* generate appropriate exception */
150 e = exceptions_new_hardware_exception(xpc, type, val);
152 /* remove stackframeinfo */
154 stacktrace_remove_stackframeinfo(&sfi);
158 ctx->sigc_regs.u_regs[REG_ITMP2_XPTR] = (ptrint) e;
159 ctx->sigc_regs.u_regs[REG_ITMP3_XPC] = (ptrint) xpc;
160 ctx->sigc_regs.tpc = (ptrint) asm_handle_exception;
161 ctx->sigc_regs.tnpc = (ptrint) asm_handle_exception + 4;
166 /* md_icacheflush **************************************************************
168 Calls the system's function to flush the instruction cache.
170 *******************************************************************************/
172 void md_icacheflush(u1 *addr, s4 nbytes)
178 /* zero the least significant 3 bits to align on a 64-bit boundary */
179 addr = (u1 *) (((ptrint) addr) & -8l);
191 #if defined(ENABLE_THREADS)
192 /* md_critical_section_restart ************************************************
194 Search the critical sections tree for a matching section and set
195 the NPC to the restart point, if necessary.
197 Reads PC and modifies NPC.
199 ******************************************************************************/
201 void md_critical_section_restart(ucontext_t *_uc)
203 /* mcontext_t *_mc; */
208 printf("ignoring md_critical_section_restart\n");
211 /* again, we are getting sigcontext instead of ucontext */
212 ctx = (sigcontext *) _uc;
214 pc = (u1 *) ctx->sigc_regs.tpc;
216 npc = critical_find_restart_point(pc);
219 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
220 ctx->sigc_regs.tnpc = (ptrint) npc;
227 * These are local overrides for various environment variables in Emacs.
228 * Please do not remove this and leave it at the end of the file, where
229 * Emacs will automagically detect them.
230 * ---------------------------------------------------------------------
233 * indent-tabs-mode: t
237 * vim:noexpandtab:sw=4:ts=4: