37b1e7e3d7f4a41ee268ef2a6b08d4d082603dde
[cacao.git] / src / vm / jit / mips / irix / md-os.c
1 /* src/vm/jit/mips/irix/md-os.c - machine dependent MIPS IRIX functions
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Andreas Krall
28             Reinhard Grafl
29             Christian Thalinger
30
31    $Id: md-os.c 7615 2007-03-29 23:10:59Z michi $
32
33 */
34
35
36 #include "config.h"
37
38 #include <assert.h>
39 #include <signal.h>
40 #include <sys/fpu.h>
41
42 #include "vm/types.h"
43
44 #include "vm/jit/mips/md-abi.h"
45
46 #include "mm/gc-common.h"
47 #include "vm/exceptions.h"
48 #include "vm/global.h"
49 #include "vm/signallocal.h"
50 #include "vm/stringlocal.h"
51 #include "vm/jit/asmpart.h"
52 #include "vm/jit/codegen-common.h"
53 #include "vm/jit/stacktrace.h"
54
55
56 /* md_init *********************************************************************
57
58    Do some machine dependent initialization.
59
60 *******************************************************************************/
61
62 void md_init(void)
63 {
64         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a      */
65         /* dummy allocation here to ensure that the GC is initialized.            */
66
67 #if defined(ENABLE_GC_BOEHM)
68         (void) GCNEW(u1);
69 #endif
70
71
72         /* Turn off flush-to-zero */
73
74         {
75                 union fpc_csr n;
76                 n.fc_word = get_fpc_csr();
77                 n.fc_struct.flush = 0;
78                 set_fpc_csr(n.fc_word);
79         }
80 }
81
82
83 /* md_signal_handler_sigsegv ***************************************************
84
85    NullPointerException signal handler for hardware null pointer
86    check.
87
88 *******************************************************************************/
89
90 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
91 {
92         ucontext_t  *_uc;
93         mcontext_t  *_mc;
94         u4           instr;
95         ptrint       addr;
96         u1          *pv;
97         u1          *sp;
98         u1          *ra;
99         u1          *xpc;
100
101         _uc = (struct ucontext *) _p;
102         _mc = &_uc->uc_mcontext;
103
104         pv  = (u1 *) _mc->gregs[REG_PV];
105         sp  = (u1 *) _mc->gregs[REG_SP];
106         ra  = (u1 *) _mc->gregs[REG_RA];             /* this is correct for leafs */
107         xpc = (u1 *) _mc->gregs[CTX_EPC];
108
109         instr = *((u4 *) (_mc->gregs[CTX_EPC]));
110         addr = _mc->gregs[(instr >> 21) & 0x1f];
111
112         if (addr == 0) {
113                 _mc->gregs[REG_ITMP1_XPTR] =
114                         (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
115
116                 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
117                 _mc->gregs[CTX_EPC] = (ptrint) asm_handle_exception;
118         }
119         else {
120                 codegen_get_pv_from_pc(xpc);
121
122                 /* this should not happen */
123
124                 assert(0);
125         }
126 }
127
128
129 #if defined(ENABLE_THREADS)
130 void thread_restartcriticalsection(ucontext_t *uc)
131 {
132         void *critical;
133
134         critical = critical_find_restart_point((void*) uc->uc_mcontext.gregs[CTX_EPC]);
135
136         if (critical)
137                 uc->uc_mcontext.gregs[CTX_EPC] = (ptrint) critical;
138 }
139 #endif
140
141
142 /*
143  * These are local overrides for various environment variables in Emacs.
144  * Please do not remove this and leave it at the end of the file, where
145  * Emacs will automagically detect them.
146  * ---------------------------------------------------------------------
147  * Local variables:
148  * mode: c
149  * indent-tabs-mode: t
150  * c-basic-offset: 4
151  * tab-width: 4
152  * End:
153  */