2ede96024f2ebb3302dc2e171983af488cbe55d7
[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, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <assert.h>
29 #include <signal.h>
30 #include <stdint.h>
31 #include <sys/fpu.h>
32
33 #include "vm/types.h"
34
35 #include "vm/jit/mips/codegen.h"
36 #include "vm/jit/mips/md-abi.h"
37
38 #include "mm/gc.hpp"
39
40 #include "vm/global.h"
41 #include "vm/signallocal.h"
42 #include "vm/stringlocal.h"
43
44 #include "vm/jit/asmpart.h"
45 #include "vm/jit/codegen-common.h"
46 #include "vm/jit/stacktrace.h"
47
48
49 /* md_init *********************************************************************
50
51    Do some machine dependent initialization.
52
53 *******************************************************************************/
54
55 void md_init(void)
56 {
57         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a      */
58         /* dummy allocation here to ensure that the GC is initialized.            */
59
60 #if defined(ENABLE_GC_BOEHM)
61         (void) GCNEW(u1);
62 #endif
63
64
65         /* Turn off flush-to-zero */
66
67         {
68                 union fpc_csr n;
69                 n.fc_word = get_fpc_csr();
70                 n.fc_struct.flush = 0;
71                 set_fpc_csr(n.fc_word);
72         }
73 }
74
75
76 /* md_signal_handler_sigsegv ***************************************************
77
78    Signal handler for hardware-exceptions.
79
80 *******************************************************************************/
81
82 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
83 {
84         ucontext_t     *_uc;
85         mcontext_t     *_mc;
86         u1             *pv;
87         u1             *sp;
88         u1             *ra;
89         u1             *xpc;
90         u4              mcode;
91         int             d;
92         int             s1;
93         int16_t         disp;
94         intptr_t        val;
95         intptr_t        addr;
96         int              type;
97         void           *p;
98
99         _uc = (struct ucontext *) _p;
100         _mc = &_uc->uc_mcontext;
101
102         pv  = (u1 *) _mc->gregs[REG_PV];
103         sp  = (u1 *) _mc->gregs[REG_SP];
104         ra  = (u1 *) _mc->gregs[REG_RA];             /* this is correct for leafs */
105         xpc = (u1 *) _mc->gregs[CTX_EPC];
106
107         /* get exception-throwing instruction */
108
109         mcode = *((u4 *) xpc);
110
111         d    = M_ITYPE_GET_RT(mcode);
112         s1   = M_ITYPE_GET_RS(mcode);
113         disp = M_ITYPE_GET_IMM(mcode);
114
115         /* check for special-load */
116
117         if (s1 == REG_ZERO) {
118                 /* we use the exception type as load displacement */
119
120                 type = disp;
121                 val  = _mc->gregs[d];
122         }
123         else {
124                 /* This is a normal NPE: addr must be NULL and the NPE-type
125                    define is 0. */
126
127                 addr = _mc->gregs[s1];
128                 type = (int) addr;
129                 val  = 0;
130         }
131
132         /* Handle the type. */
133
134         p = signal_handle(type, val, pv, sp, ra, xpc, _p);
135
136         /* set registers (only if exception object ready) */
137
138         if (p != NULL) {
139                 _mc->gregs[REG_ITMP1_XPTR] = (intptr_t) p;
140                 _mc->gregs[REG_ITMP2_XPC]  = (intptr_t) xpc;
141                 _mc->gregs[CTX_EPC]        = (intptr_t) asm_handle_exception;
142         }
143 }
144
145
146 /*
147  * These are local overrides for various environment variables in Emacs.
148  * Please do not remove this and leave it at the end of the file, where
149  * Emacs will automagically detect them.
150  * ---------------------------------------------------------------------
151  * Local variables:
152  * mode: c
153  * indent-tabs-mode: t
154  * c-basic-offset: 4
155  * tab-width: 4
156  * End:
157  */