1 /* src/vm/jit/mips/md.c - machine dependent MIPS functions
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Andreas Krall
30 Changes: Christian Thalinger
32 $Id: md.c 3002 2005-07-12 16:02:45Z twisti $
45 #include "vm/jit/mips/md-abi.h"
46 #include "vm/jit/mips/types.h"
48 #include "vm/exceptions.h"
49 #include "vm/stringlocal.h"
50 #include "vm/jit/asmpart.h"
53 /* md_init *********************************************************************
55 Do some machine dependent initialization.
57 *******************************************************************************/
61 /* The Boehm GC initialization blocks the SIGSEGV signal. So we do a */
62 /* dummy allocation here to ensure that the GC is initialized. */
64 heap_allocate(1, 0, NULL);
67 /* Turn off flush-to-zero */
71 n.fc_word = get_fpc_csr();
72 n.fc_struct.flush = 0;
73 set_fpc_csr(n.fc_word);
78 /* signal_handler_sigsegv ******************************************************
80 NullPointerException signal handler for hardware null pointer check.
82 *******************************************************************************/
84 void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
91 _uc = (struct ucontext *) _p;
92 _mc = &_uc->uc_mcontext;
94 instr = *((u4 *) (_mc->gregs[CTX_EPC]));
95 addr = _mc->gregs[(instr >> 21) & 0x1f];
98 _mc->gregs[REG_ITMP1_XPTR] = (ptrint) new_nullpointerexception();
99 _mc->gregs[REG_ITMP2_XPC] = _mc->gregs[CTX_EPC];
100 _mc->gregs[CTX_EPC] = (ptrint) asm_handle_exception;
103 addr += (long) ((instr << 16) >> 16);
105 throw_cacao_exception_exit(string_java_lang_InternalError,
106 "faulting address: 0x%lx at 0x%lx\n",
107 addr, _mc->gregs[CTX_EPC]);
112 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
113 void thread_restartcriticalsection(ucontext_t *uc)
117 critical = thread_checkcritical((void*) uc->uc_mcontext.gregs[CTX_EPC]);
120 uc->uc_mcontext.gregs[CTX_EPC] = (ptrint) critical;
125 void docacheflush(u1 *p, long bytelen)
128 long psize = sysconf(_SC_PAGESIZE);
129 p -= (long) p & (psize - 1);
130 e += psize - ((((long) e - 1) & (psize - 1)) + 1);
132 mprotect(p, bytelen, PROT_READ | PROT_WRITE | PROT_EXEC);
136 /* md_stacktrace_get_returnaddress *********************************************
138 Returns the return address of the current stackframe, specified by
139 the passed stack pointer and the stack frame size.
141 *******************************************************************************/
143 functionptr md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
147 /* on MIPS the return address is located on the top of the stackframe */
149 ra = (functionptr) *((u1 **) (sp + framesize - SIZEOF_VOID_P));
155 /* codegen_findmethod **********************************************************
160 237affe8 lda pv,-24(ra)
162 *******************************************************************************/
164 functionptr codegen_findmethod(functionptr pc)
174 /* get offset of first instruction (lda) */
176 mcode = *((u4 *) ra);
178 if ((mcode >> 16) != 0x237a) {
179 log_text("No `lda pv,x(ra)' instruction found on return address!");
183 offset = (s2) (mcode & 0x0000ffff);
186 /* check for second instruction (ldah) */
188 mcode = *((u4 *) (ra + 1 * 4));
190 if ((mcode >> 16) == 0x177b) {
191 offset = (s2) (mcode << 16);
195 return (functionptr) pv;
200 * These are local overrides for various environment variables in Emacs.
201 * Please do not remove this and leave it at the end of the file, where
202 * Emacs will automagically detect them.
203 * ---------------------------------------------------------------------
206 * indent-tabs-mode: t