* src/vm/jit/codegen-common.c: Moved to .cpp.
[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
43 #include "vm/jit/asmpart.h"
44 #include "vm/jit/codegen-common.hpp"
45
46
47 /* md_init *********************************************************************
48
49    Do some machine dependent initialization.
50
51 *******************************************************************************/
52
53 void md_init(void)
54 {
55         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a      */
56         /* dummy allocation here to ensure that the GC is initialized.            */
57
58 #if defined(ENABLE_GC_BOEHM)
59         (void) GCNEW(u1);
60 #endif
61
62
63         /* Turn off flush-to-zero */
64
65         {
66                 union fpc_csr n;
67                 n.fc_word = get_fpc_csr();
68                 n.fc_struct.flush = 0;
69                 set_fpc_csr(n.fc_word);
70         }
71 }
72
73
74 /* md_signal_handler_sigsegv ***************************************************
75
76    Signal handler for hardware-exceptions.
77
78 *******************************************************************************/
79
80 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
81 {
82         ucontext_t     *_uc;
83         mcontext_t     *_mc;
84         u1             *pv;
85         u1             *sp;
86         u1             *ra;
87         u1             *xpc;
88         u4              mcode;
89         int             d;
90         int             s1;
91         int16_t         disp;
92         intptr_t        val;
93         intptr_t        addr;
94         int              type;
95         void           *p;
96
97         _uc = (struct ucontext *) _p;
98         _mc = &_uc->uc_mcontext;
99
100         pv  = (u1 *) _mc->gregs[REG_PV];
101         sp  = (u1 *) _mc->gregs[REG_SP];
102         ra  = (u1 *) _mc->gregs[REG_RA];             /* this is correct for leafs */
103         xpc = (u1 *) _mc->gregs[CTX_EPC];
104
105         /* get exception-throwing instruction */
106
107         mcode = *((u4 *) xpc);
108
109         d    = M_ITYPE_GET_RT(mcode);
110         s1   = M_ITYPE_GET_RS(mcode);
111         disp = M_ITYPE_GET_IMM(mcode);
112
113         /* check for special-load */
114
115         if (s1 == REG_ZERO) {
116                 /* we use the exception type as load displacement */
117
118                 type = disp;
119                 val  = _mc->gregs[d];
120         }
121         else {
122                 /* This is a normal NPE: addr must be NULL and the NPE-type
123                    define is 0. */
124
125                 addr = _mc->gregs[s1];
126                 type = (int) addr;
127                 val  = 0;
128         }
129
130         /* Handle the type. */
131
132         p = signal_handle(type, val, pv, sp, ra, xpc, _p);
133
134         /* set registers (only if exception object ready) */
135
136         if (p != NULL) {
137                 _mc->gregs[REG_ITMP1_XPTR] = (intptr_t) p;
138                 _mc->gregs[REG_ITMP2_XPC]  = (intptr_t) xpc;
139                 _mc->gregs[CTX_EPC]        = (intptr_t) asm_handle_exception;
140         }
141 }
142
143
144 /*
145  * These are local overrides for various environment variables in Emacs.
146  * Please do not remove this and leave it at the end of the file, where
147  * Emacs will automagically detect them.
148  * ---------------------------------------------------------------------
149  * Local variables:
150  * mode: c
151  * indent-tabs-mode: t
152  * c-basic-offset: 4
153  * tab-width: 4
154  * End:
155  */