* src/vmcore/linker.c (build_display): Removed superfluous recursion; return
[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, 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
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 */
26
27
28 #include "config.h"
29
30 #include <assert.h>
31 #include <signal.h>
32 #include <stdint.h>
33 #include <sys/fpu.h>
34
35 #include "vm/types.h"
36
37 #include "vm/jit/mips/codegen.h"
38 #include "vm/jit/mips/md-abi.h"
39
40 #include "mm/gc-common.h"
41
42 #include "vm/global.h"
43 #include "vm/signallocal.h"
44 #include "vm/stringlocal.h"
45
46 #include "vm/jit/asmpart.h"
47 #include "vm/jit/codegen-common.h"
48 #include "vm/jit/stacktrace.h"
49
50
51 /* md_init *********************************************************************
52
53    Do some machine dependent initialization.
54
55 *******************************************************************************/
56
57 void md_init(void)
58 {
59         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a      */
60         /* dummy allocation here to ensure that the GC is initialized.            */
61
62 #if defined(ENABLE_GC_BOEHM)
63         (void) GCNEW(u1);
64 #endif
65
66
67         /* Turn off flush-to-zero */
68
69         {
70                 union fpc_csr n;
71                 n.fc_word = get_fpc_csr();
72                 n.fc_struct.flush = 0;
73                 set_fpc_csr(n.fc_word);
74         }
75 }
76
77
78 /* md_signal_handler_sigsegv ***************************************************
79
80    Signal handler for hardware-exceptions.
81
82 *******************************************************************************/
83
84 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
85 {
86         ucontext_t     *_uc;
87         mcontext_t     *_mc;
88         u1             *pv;
89         u1             *sp;
90         u1             *ra;
91         u1             *xpc;
92         u4              mcode;
93         int             d;
94         int             s1;
95         int16_t         disp;
96         intptr_t        val;
97         intptr_t        addr;
98         int              type;
99         void           *p;
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         /* get exception-throwing instruction */
110
111         mcode = *((u4 *) xpc);
112
113         d    = M_ITYPE_GET_RT(mcode);
114         s1   = M_ITYPE_GET_RS(mcode);
115         disp = M_ITYPE_GET_IMM(mcode);
116
117         /* check for special-load */
118
119         if (s1 == REG_ZERO) {
120                 /* we use the exception type as load displacement */
121
122                 type = disp;
123                 val  = _mc->gregs[d];
124         }
125         else {
126                 /* This is a normal NPE: addr must be NULL and the NPE-type
127                    define is 0. */
128
129                 addr = _mc->gregs[s1];
130                 type = (int) addr;
131                 val  = 0;
132         }
133
134         /* Handle the type. */
135
136         p = signal_handle(type, val, pv, sp, ra, xpc, _p);
137
138         /* set registers (only if exception object ready) */
139
140         if (p != NULL) {
141                 _mc->gregs[REG_ITMP1_XPTR] = (intptr_t) p;
142                 _mc->gregs[REG_ITMP2_XPC]  = (intptr_t) xpc;
143                 _mc->gregs[CTX_EPC]        = (intptr_t) asm_handle_exception;
144         }
145 }
146
147
148 /* md_critical_section_restart *************************************************
149
150    Search the critical sections tree for a matching section and set
151    the PC to the restart point, if necessary.
152
153 *******************************************************************************/
154
155 #if defined(ENABLE_THREADS)
156 void md_critical_section_restart(ucontext_t *_uc)
157 {
158         mcontext_t *_mc;
159         u1         *pc;
160         u1         *npc;
161
162         _mc = &_uc->uc_mcontext;
163
164         pc = (u1 *) _mc->gregs[CTX_EPC];
165
166         npc = critical_find_restart_point(pc);
167
168         if (npc != NULL) {
169                 log_println("md_critical_section_restart: pc=%p, npc=%p", pc, npc);
170                 _mc->gregs[CTX_EPC] = (ptrint) npc;
171         }
172 }
173 #endif
174
175
176 /*
177  * These are local overrides for various environment variables in Emacs.
178  * Please do not remove this and leave it at the end of the file, where
179  * Emacs will automagically detect them.
180  * ---------------------------------------------------------------------
181  * Local variables:
182  * mode: c
183  * indent-tabs-mode: t
184  * c-basic-offset: 4
185  * tab-width: 4
186  * End:
187  */