* Removed machine independent stuff
[cacao.git] / src / vm / jit / mips / md.c
1 /* src/vm/jit/mips/md.c - machine dependent MIPS 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.c 2827 2005-06-25 13:43:51Z twisti $
33
34 */
35
36
37 #include <signal.h>
38 #include <sys/fpu.h>
39 #include <sys/mman.h>
40 #include <unistd.h>
41
42 #include "config.h"
43 #include "vm/jit/mips/md-abi.h"
44 #include "vm/jit/mips/types.h"
45
46 #include "vm/exceptions.h"
47 #include "vm/stringlocal.h"
48 #include "vm/jit/asmpart.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         heap_allocate(1, 0, NULL);
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 /* signal_handler_sigsegv ******************************************************
77
78    NullPointerException signal handler for hardware null pointer check.
79
80 *******************************************************************************/
81
82 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
83 {
84         ucontext_t *_uc;
85         mcontext_t *_mc;
86         u4          instr;
87         ptrint      addr;
88
89         _uc = (struct ucontext *) _p;
90         _mc = &_uc->uc_mcontext;
91
92         instr = *((u4 *) (_mc->gregs[CTX_EPC]));
93         addr = _mc->gregs[(instr >> 21) & 0x1f];
94
95         if (addr == 0) {
96                 _mc->gregs[REG_ITMP1_XPTR] = (ptrint) new_nullpointerexception();
97                 _mc->gregs[REG_ITMP2_XPC] = _mc->gregs[CTX_EPC];
98                 _mc->gregs[CTX_EPC] = (ptrint) asm_handle_exception;
99
100         } else {
101         addr += (long) ((instr << 16) >> 16);
102
103                 throw_cacao_exception_exit(string_java_lang_InternalError,
104                                                                    "faulting address: 0x%lx at 0x%lx\n",
105                                                                    addr, _mc->gregs[CTX_EPC]);
106         }
107 }
108
109
110 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
111 void thread_restartcriticalsection(ucontext_t *uc)
112 {
113         void *critical;
114
115         critical = thread_checkcritical((void*) uc->uc_mcontext.gregs[CTX_EPC]);
116
117         if (critical)
118                 uc->uc_mcontext.gregs[CTX_EPC] = (ptrint) critical;
119 }
120 #endif
121
122
123 void docacheflush(u1 *p, long bytelen)
124 {
125         u1 *e = p + bytelen;
126         long psize = sysconf(_SC_PAGESIZE);
127         p -= (long) p & (psize - 1);
128         e += psize - ((((long) e - 1) & (psize - 1)) + 1);
129         bytelen = e-p;
130         mprotect(p, bytelen, PROT_READ | PROT_WRITE | PROT_EXEC);
131 }
132
133
134 /*
135  * These are local overrides for various environment variables in Emacs.
136  * Please do not remove this and leave it at the end of the file, where
137  * Emacs will automagically detect them.
138  * ---------------------------------------------------------------------
139  * Local variables:
140  * mode: c
141  * indent-tabs-mode: t
142  * c-basic-offset: 4
143  * tab-width: 4
144  * End:
145  */