/* src/vm/jit/alpha/md.c - machine dependent Alpha functions
- Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Authors: Andreas Krall
Reinhard Grafl
Changes: Joseph Wenninger
Christian Thalinger
- $Id: md.c 2735 2005-06-17 13:38:35Z twisti $
+ $Id: md.c 4357 2006-01-22 23:33:38Z twisti $
*/
+#include "config.h"
+
#include <assert.h>
-#include <signal.h>
#include <ucontext.h>
-#include "config.h"
+#if defined(__LINUX__)
+# include <asm/fpu.h>
+
+extern unsigned long ieee_get_fp_control();
+extern void ieee_set_fp_control(unsigned long fp_control);
+#endif
+
+#include "vm/types.h"
+
#include "vm/jit/alpha/md-abi.h"
-#include "vm/jit/alpha/types.h"
-#include "vm/options.h"
+#include "vm/exceptions.h"
#include "vm/stringlocal.h"
#include "vm/jit/asmpart.h"
+#include "vm/jit/stacktrace.h"
-/* catch_NullPointerException **************************************************
+/* md_init *********************************************************************
- NullPointerException signal handler for hardware null pointer check.
+ Do some machine dependent initialization.
*******************************************************************************/
-void catch_NullPointerException(int sig, siginfo_t *siginfo, void *_p)
+void md_init(void)
{
- ucontext_t *_uc;
- mcontext_t *_mc;
- struct sigaction act;
- sigset_t nsig;
- int instr;
- long faultaddr;
+ /* XXX TWISTI: do we really need this? fptest's seem to work fine */
- _uc = (ucontext_t *) _p;
- _mc = &_uc->uc_mcontext;
+#if defined(__LINUX__)
+ /* Linux on Digital Alpha needs an initialisation of the ieee
+ floating point control for IEEE compliant arithmetic (option
+ -mieee of GCC). Under Digital Unix this is done
+ automatically. */
- instr = *((s4 *) (_mc->sc_pc));
- faultaddr = _mc->sc_regs[(instr >> 16) & 0x1f];
+ /* initialize floating point control */
- if (faultaddr == 0) {
- /* Reset signal handler - necessary for SysV, does no harm for BSD */
- act.sa_sigaction = catch_NullPointerException;
- act.sa_flags = SA_SIGINFO;
- sigaction(sig, &act, NULL);
+ ieee_set_fp_control(ieee_get_fp_control()
+ & ~IEEE_TRAP_ENABLE_INV
+ & ~IEEE_TRAP_ENABLE_DZE
+/* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */
+ & ~IEEE_TRAP_ENABLE_OVF);
+#endif
+}
- sigemptyset(&nsig);
- sigaddset(&nsig, sig);
- sigprocmask(SIG_UNBLOCK, &nsig, NULL); /* unblock signal */
- _mc->sc_regs[REG_ITMP1_XPTR] =
- (ptrint) string_java_lang_NullPointerException;
+/* md_stacktrace_get_returnaddress *********************************************
- _mc->sc_regs[REG_ITMP2_XPC] = _mc->sc_pc;
- _mc->sc_pc = (ptrint) asm_throw_and_handle_exception;
+ Returns the return address of the current stackframe, specified by
+ the passed stack pointer and the stack frame size.
- } else {
- faultaddr += (long) ((instr << 16) >> 16);
+*******************************************************************************/
- printf("faulting address: 0x%016lx\n", faultaddr);
- assert(0);
- }
-}
+u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
+{
+ u1 *ra;
+ /* on Alpha the return address is located on the top of the stackframe */
-#if defined(__OSF__)
+ ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P));
-void init_exceptions(void)
-{
+ return ra;
+}
-#else /* Linux */
-/* Linux on Digital Alpha needs an initialisation of the ieee floating point
- control for IEEE compliant arithmetic (option -mieee of GCC). Under
- Digital Unix this is done automatically.
-*/
+/* md_codegen_findmethod *******************************************************
-#include <asm/fpu.h>
+ Machine code:
-extern unsigned long ieee_get_fp_control();
-extern void ieee_set_fp_control(unsigned long fp_control);
+ 6b5b4000 jsr (pv)
+ 277afffe ldah pv,-2(ra)
+ 237ba61c lda pv,-23012(pv)
-void init_exceptions(void)
+*******************************************************************************/
+
+u1 *md_codegen_findmethod(u1 *ra)
{
- struct sigaction act;
+ u1 *pv;
+ u4 mcode;
+ s4 offset;
- /* initialize floating point control */
+ pv = ra;
- ieee_set_fp_control(ieee_get_fp_control()
- & ~IEEE_TRAP_ENABLE_INV
- & ~IEEE_TRAP_ENABLE_DZE
-/* & ~IEEE_TRAP_ENABLE_UNF we dont want underflow */
- & ~IEEE_TRAP_ENABLE_OVF);
-#endif
+ /* get first instruction word after jump */
- /* install signal handlers we need to convert to exceptions */
+ mcode = *((u4 *) ra);
- if (!checknull) {
- act.sa_sigaction = catch_NullPointerException;
- act.sa_flags = SA_SIGINFO;
+ /* check if we have 2 instructions (ldah, lda) */
-#if defined(SIGSEGV)
- sigaction(SIGSEGV, &act, NULL);
-#endif
+ if ((mcode >> 16) == 0x277a) {
+ /* get displacement of first instruction (ldah) */
-#if defined(SIGBUS)
- sigaction(SIGBUS, &act, NULL);
-#endif
- }
-}
+ offset = (s4) (mcode << 16);
+ pv += offset;
+ /* get displacement of second instruction (lda) */
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void thread_restartcriticalsection(ucontext_t *uc)
-{
- void *critical;
+ mcode = *((u4 *) (ra + 1 * 4));
+
+ if ((mcode >> 16) != 0x237b) {
+ log_text("No `lda pv,x(pv)' instruction found on return address!");
+ assert(0);
+ }
- critical = thread_checkcritical((void *) uc->uc_mcontext.sc_pc);
+ offset = (s2) (mcode & 0x0000ffff);
+ pv += offset;
- if (critical)
- uc->uc_mcontext.sc_pc = (ptrint) critical;
+ } else {
+ /* get displacement of first instruction (lda) */
+
+ if ((mcode >> 16) != 0x237a) {
+ log_text("No `lda pv,x(ra)' instruction found on return address!");
+ assert(0);
+ }
+
+ offset = (s2) (mcode & 0x0000ffff);
+ pv += offset;
+ }
+
+ return pv;
}
-#endif
/*