1 /* src/vm/jit/x86_64/md.c - machine dependent x86_64 Linux 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: Christian Thalinger
31 $Id: md.c 4326 2006-01-20 13:25:24Z twisti $
43 #include "vm/jit/x86_64/md-abi.h"
45 #include "vm/exceptions.h"
46 #include "vm/signallocal.h"
47 #include "vm/jit/asmpart.h"
48 #include "vm/jit/stacktrace.h"
51 /* md_init *********************************************************************
53 Do some machine dependent initialization.
55 *******************************************************************************/
63 /* md_signal_handler_sigsegv ***************************************************
65 NullPointerException signal handler for hardware null pointer
68 *******************************************************************************/
70 void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
78 _uc = (ucontext_t *) _p;
79 _mc = &_uc->uc_mcontext;
81 /* ATTENTION: don't use CACAO internal REG_* defines as they are */
82 /* different to the ones in <ucontext.h> */
84 sp = (u1 *) _mc->gregs[REG_RSP];
85 xpc = (u1 *) _mc->gregs[REG_RIP];
86 ra = xpc; /* return address is equal to xpc */
89 (ptrint) stacktrace_hardware_nullpointerexception(NULL, sp, ra, xpc);
91 _mc->gregs[REG_R10] = (ptrint) xpc; /* REG_ITMP2_XPC */
92 _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
96 /* md_signal_handler_sigfpe ****************************************************
98 ArithmeticException signal handler for hardware divide by zero
101 *******************************************************************************/
103 void md_signal_handler_sigfpe(int sig, siginfo_t *siginfo, void *_p)
111 _uc = (ucontext_t *) _p;
112 _mc = &_uc->uc_mcontext;
114 /* ATTENTION: don't use CACAO internal REG_* defines as they are */
115 /* different to the ones in <ucontext.h> */
117 sp = (u1 *) _mc->gregs[REG_RSP];
118 xpc = (u1 *) _mc->gregs[REG_RIP];
119 ra = xpc; /* return address is equal to xpc */
121 _mc->gregs[REG_RAX] =
122 (ptrint) stacktrace_hardware_arithmeticexception(NULL, sp, ra, xpc);
124 _mc->gregs[REG_R10] = (ptrint) xpc; /* REG_ITMP2_XPC */
125 _mc->gregs[REG_RIP] = (ptrint) asm_handle_exception;
129 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
130 void thread_restartcriticalsection(ucontext_t *uc)
134 critical = thread_checkcritical((void *) uc->uc_mcontext.gregs[REG_RIP]);
137 uc->uc_mcontext.gregs[REG_RIP] = (ptrint) critical;
142 /* md_stacktrace_get_returnaddress *********************************************
144 Returns the return address of the current stackframe, specified by
145 the passed stack pointer and the stack frame size.
147 *******************************************************************************/
149 u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
153 /* on x86_64 the return address is above the current stack frame */
155 ra = *((u1 **) (sp + framesize));
161 /* md_codegen_findmethod *******************************************************
163 On this architecture just a wrapper function to codegen_findmethod.
165 *******************************************************************************/
167 u1 *md_codegen_findmethod(u1 *ra)
171 /* the the start address of the function which contains this
172 address from the method table */
174 pv = codegen_findmethod(ra);
181 * These are local overrides for various environment variables in Emacs.
182 * Please do not remove this and leave it at the end of the file, where
183 * Emacs will automagically detect them.
184 * ---------------------------------------------------------------------
187 * indent-tabs-mode: t