* signal_handler_sigsegv: Use u1* instead of functionptr.
[cacao.git] / src / vm / jit / mips / linux / md-os.c
1 /* src/vm/jit/mips/linux/md-os.c - machine dependent MIPS Linux functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Andreas Krall
28             Reinhard Grafl
29
30    Changes: Christian Thalinger
31
32    $Id: md-os.c 3932 2005-12-09 15:10:04Z twisti $
33
34 */
35
36
37 #include <assert.h>
38 #include <signal.h>
39 #include <ucontext.h>
40
41 #include "config.h"
42 #include "vm/types.h"
43
44 #include "vm/jit/mips/md-abi.h"
45
46 #include "mm/boehm.h"
47 #include "vm/exceptions.h"
48 #include "vm/stringlocal.h"
49 #include "vm/jit/asmpart.h"
50 #include "vm/jit/stacktrace.h"
51
52
53 /* md_init *********************************************************************
54
55    Do some machine dependent initialization.
56
57 *******************************************************************************/
58
59 void md_init(void)
60 {
61         /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a      */
62         /* dummy allocation here to ensure that the GC is initialized.            */
63
64         heap_allocate(1, 0, NULL);
65
66 #if 0
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 #endif
76 }
77
78
79 /* signal_handler_sigsegv ******************************************************
80
81    NullPointerException signal handler for hardware null pointer check.
82
83 *******************************************************************************/
84
85 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
86 {
87         ucontext_t  *_uc;
88         mcontext_t  *_mc;
89         u4           instr;
90         ptrint       addr;
91         u1          *pv;
92         u1          *sp;
93         u1          *ra;
94         u1          *xpc;
95
96         _uc = (struct ucontext *) _p;
97         _mc = &_uc->uc_mcontext;
98
99         /* in ucontext.h the registers are defined as long long, even for
100            MIPS32, so we cast them */
101         
102         instr = *((u4 *) ((ptrint) _mc->pc));
103         addr = _mc->gregs[(instr >> 21) & 0x1f];
104
105         if (addr == 0) {
106                 pv  = (u1 *) (ptrint) _mc->gregs[REG_PV];
107                 sp  = (u1 *) (ptrint) _mc->gregs[REG_SP];
108                 ra  = (u1 *) (ptrint) _mc->gregs[REG_RA]; /* this is correct for leafs*/
109                 xpc = (u1 *) (ptrint) _mc->pc;
110
111                 _mc->gregs[REG_ITMP1_XPTR] =
112                         (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
113
114                 _mc->gregs[REG_ITMP2_XPC] = (ptrint) xpc;
115                 _mc->pc = (ptrint) asm_handle_exception;
116
117         } else {
118                 addr += (long) ((instr << 16) >> 16);
119
120                 throw_cacao_exception_exit(string_java_lang_InternalError,
121                                                                    "faulting address: 0x%lx at 0x%lx\n",
122                                                                    addr, _mc->pc);
123         }
124 }
125
126
127 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
128 void thread_restartcriticalsection(ucontext_t *_uc)
129 {
130         mcontext_t *_mc;
131         void *critical;
132
133         _mc = &_uc->uc_mcontext;
134
135         critical = thread_checkcritical((void *) (ptrint) _mc->pc);
136
137         if (critical)
138                 _mc->pc = (ptrint) critical;
139 }
140 #endif
141
142
143 /*
144  * These are local overrides for various environment variables in Emacs.
145  * Please do not remove this and leave it at the end of the file, where
146  * Emacs will automagically detect them.
147  * ---------------------------------------------------------------------
148  * Local variables:
149  * mode: c
150  * indent-tabs-mode: t
151  * c-basic-offset: 4
152  * tab-width: 4
153  * End:
154  */