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
37 #include "vm/jit/mips/codegen.h"
38 #include "vm/jit/mips/md-abi.h"
40 #include "mm/gc-common.h"
42 #include "vm/global.h"
43 #include "vm/signallocal.h"
44 #include "vm/stringlocal.h"
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/codegen-common.h"
48 #include "vm/jit/stacktrace.h"
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
59 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
60 /* dummy allocation here to ensure that the GC is initialized. */
62 #if defined(ENABLE_GC_BOEHM)
63 heap_allocate(1, 0, NULL);
67 /* Turn off flush-to-zero */
71 n.fc_word = get_fpc_csr();
72 n.fc_struct.flush = 0;
73 set_fpc_csr(n.fc_word);
78 /* md_signal_handler_sigsegv ***************************************************
80 Signal handler for hardware-exceptions.
82 *******************************************************************************/
84 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
102 _uc = (struct ucontext *) _p;
103 _mc = &_uc->uc_mcontext;
105 pv = (u1 *) _mc->gregs[REG_PV];
106 sp = (u1 *) _mc->gregs[REG_SP];
107 ra = (u1 *) _mc->gregs[REG_RA]; /* this is correct for leafs */
108 xpc = (u1 *) _mc->gregs[CTX_EPC];
110 /* get exception-throwing instruction */
112 mcode = *((u4 *) xpc);
114 d = M_ITYPE_GET_RT(mcode);
115 s1 = M_ITYPE_GET_RS(mcode);
116 disp = M_ITYPE_GET_IMM(mcode);
118 /* check for special-load */
120 if (s1 == REG_ZERO) {
121 /* we use the exception type as load displacement */
127 /* This is a normal NPE: addr must be NULL and the NPE-type
130 addr = _mc->gregs[s1];
135 /* create stackframeinfo */
137 stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
139 /* Handle the type. */
141 p = signal_handle(xpc, type, val);
143 /* remove stackframeinfo */
145 stacktrace_remove_stackframeinfo(&sfi);
147 /* set registers (only if exception object ready) */
150 _mc->gregs[REG_ITMP1_XPTR] = (intptr_t) p;
151 _mc->gregs[REG_ITMP2_XPC] = (intptr_t) xpc;
152 _mc->gregs[CTX_EPC] = (intptr_t) asm_handle_exception;
157 /* md_critical_section_restart *************************************************
159 Search the critical sections tree for a matching section and set
160 the PC to the restart point, if necessary.
162 *******************************************************************************/
164 #if defined(ENABLE_THREADS)
165 void md_critical_section_restart(ucontext_t *_uc)
171 _mc = &_uc->uc_mcontext;
173 pc = (u1 *) _mc->gregs[CTX_EPC];
175 npc = critical_find_restart_point(pc);
178 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
179 _mc->gregs[CTX_EPC] = (ptrint) npc;
186 * These are local overrides for various environment variables in Emacs.
187 * Please do not remove this and leave it at the end of the file, where
188 * Emacs will automagically detect them.
189 * ---------------------------------------------------------------------
192 * indent-tabs-mode: t