1 /* src/vm/jit/mips/irix/md-os.c - machine dependent MIPS IRIX functions
3 Copyright (C) 1996-2005, 2006, 2007 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 8283 2007-08-09 15:10:05Z twisti $
39 #include "vm/jit/mips/codegen.h"
40 #include "vm/jit/mips/md-abi.h"
42 #include "mm/gc-common.h"
44 #include "vm/global.h"
45 #include "vm/signallocal.h"
46 #include "vm/stringlocal.h"
48 #include "vm/jit/asmpart.h"
49 #include "vm/jit/codegen-common.h"
50 #include "vm/jit/stacktrace.h"
53 /* md_init *********************************************************************
55 Do some machine dependent initialization.
57 *******************************************************************************/
61 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
62 /* dummy allocation here to ensure that the GC is initialized. */
64 #if defined(ENABLE_GC_BOEHM)
65 heap_allocate(1, 0, NULL);
69 /* Turn off flush-to-zero */
73 n.fc_word = get_fpc_csr();
74 n.fc_struct.flush = 0;
75 set_fpc_csr(n.fc_word);
80 /* md_signal_handler_sigsegv ***************************************************
82 Signal handler for hardware-exceptions.
84 *******************************************************************************/
86 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
104 _uc = (struct ucontext *) _p;
105 _mc = &_uc->uc_mcontext;
107 pv = (u1 *) _mc->gregs[REG_PV];
108 sp = (u1 *) _mc->gregs[REG_SP];
109 ra = (u1 *) _mc->gregs[REG_RA]; /* this is correct for leafs */
110 xpc = (u1 *) _mc->gregs[CTX_EPC];
112 /* get exception-throwing instruction */
114 mcode = *((u4 *) xpc);
116 d = M_ITYPE_GET_RT(mcode);
117 s1 = M_ITYPE_GET_RS(mcode);
118 disp = M_ITYPE_GET_IMM(mcode);
120 /* check for special-load */
122 if (s1 == REG_ZERO) {
123 /* we use the exception type as load displacement */
129 /* This is a normal NPE: addr must be NULL and the NPE-type
132 addr = _mc->gregs[s1];
137 /* create stackframeinfo */
139 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
141 /* Handle the type. */
143 p = signal_handle(xpc, type, val);
145 /* remove stackframeinfo */
147 stacktrace_remove_stackframeinfo(&sfi);
149 /* set registers (only if exception object ready) */
152 _mc->gregs[REG_ITMP1_XPTR] = (intptr_t) p;
153 _mc->gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
154 _mc->gregs[CTX_EPC] = (intptr_t) asm_handle_exception;
159 /* md_critical_section_restart *************************************************
161 Search the critical sections tree for a matching section and set
162 the PC to the restart point, if necessary.
164 *******************************************************************************/
166 #if defined(ENABLE_THREADS)
167 void md_critical_section_restart(ucontext_t *_uc)
173 _mc = &_uc->uc_mcontext;
175 pc = (u1 *) _mc->gregs[CTX_EPC];
177 npc = critical_find_restart_point(pc);
180 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
181 _mc->gregs[CTX_EPC] = (ptrint) npc;
188 * These are local overrides for various environment variables in Emacs.
189 * Please do not remove this and leave it at the end of the file, where
190 * Emacs will automagically detect them.
191 * ---------------------------------------------------------------------
194 * indent-tabs-mode: t