-/* src/vm/jit/alpha/md.c - machine dependent Alpha functions
+/* src/vm/jit/alpha/linux/md-os.c - machine dependent Alpha Linux 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, 2007 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.
-
- Contact: cacao@complang.tuwien.ac.at
-
- Authors: Andreas Krall
- Reinhard Grafl
-
- Changes: Joseph Wenninger
- Christian Thalinger
-
- $Id: md-os.c 3772 2005-11-23 21:36:35Z twisti $
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
*/
+#include "config.h"
+
#include <assert.h>
+#include <stdint.h>
#include <ucontext.h>
-#include "config.h"
#include "vm/types.h"
+#include "vm/jit/alpha/codegen.h"
#include "vm/jit/alpha/md-abi.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#endif
+
+#include "vm/signallocal.h"
+
#include "vm/jit/asmpart.h"
#include "vm/jit/stacktrace.h"
-/* md_init *********************************************************************
+/* md_signal_handler_sigsegv ***************************************************
- Do some machine dependent initialization.
+ NullPointerException signal handler for hardware null pointer
+ check.
*******************************************************************************/
-void md_init(void)
+void md_signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
{
- /* XXX TWISTI: do we really need this? fptest's seem to work fine */
+ stackframeinfo sfi;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ u1 *pv;
+ u1 *sp;
+ u1 *ra;
+ u1 *xpc;
+ u4 mcode;
+ s4 d;
+ s4 s1;
+ s4 disp;
+ intptr_t val;
+ intptr_t addr;
+ int type;
+ void *p;
-#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.
-*/
+ _uc = (ucontext_t *) _p;
+ _mc = &_uc->uc_mcontext;
-#include <asm/fpu.h>
+ pv = (u1 *) _mc->sc_regs[REG_PV];
+ sp = (u1 *) _mc->sc_regs[REG_SP];
+ ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
+ xpc = (u1 *) _mc->sc_pc;
-extern unsigned long ieee_get_fp_control();
-extern void ieee_set_fp_control(unsigned long fp_control);
+ /* get exception-throwing instruction */
- /* initialize floating point control */
+ mcode = *((u4 *) xpc);
- 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
+ d = M_MEM_GET_A(mcode);
+ s1 = M_MEM_GET_B(mcode);
+ disp = M_MEM_GET_DISP(mcode);
- /* nothing to do */
-}
+ val = _mc->sc_regs[d];
+ /* check for special-load */
-/* signal_handler_sigsegv ******************************************************
+ if (s1 == REG_ZERO) {
+ /* we use the exception type as load displacement */
- NullPointerException signal handler for hardware null pointer check.
+ type = disp;
+ }
+ else {
+ /* This is a normal NPE: addr must be NULL and the NPE-type
+ define is 0. */
-*******************************************************************************/
+ addr = _mc->sc_regs[s1];
+ type = (int) addr;
+ }
-void signal_handler_sigsegv(int sig, siginfo_t *siginfo, void *_p)
-{
- ucontext_t *_uc;
- mcontext_t *_mc;
- u4 instr;
- ptrint addr;
- u1 *pv;
- u1 *sp;
- u1 *ra;
- u1 *xpc;
+ /* create stackframeinfo */
- _uc = (ucontext_t *) _p;
- _mc = &_uc->uc_mcontext;
+ stacktrace_create_extern_stackframeinfo(&sfi, pv, sp, ra, xpc);
- instr = *((s4 *) (_mc->sc_pc));
- addr = _mc->sc_regs[(instr >> 16) & 0x1f];
+ /* Handle the type. */
- if (addr == 0) {
- pv = (u1 *) _mc->sc_regs[REG_PV];
- sp = (u1 *) _mc->sc_regs[REG_SP];
- ra = (u1 *) _mc->sc_regs[REG_RA]; /* this is correct for leafs */
- xpc = (u1 *) _mc->sc_pc;
+ p = signal_handle(xpc, type, val);
- _mc->sc_regs[REG_ITMP1_XPTR] =
- (ptrint) stacktrace_hardware_nullpointerexception(pv, sp, ra, xpc);
+ /* remove stackframeinfo */
- _mc->sc_regs[REG_ITMP2_XPC] = (ptrint) xpc;
- _mc->sc_pc = (ptrint) asm_handle_exception;
+ stacktrace_remove_stackframeinfo(&sfi);
- } else {
- addr += (long) ((instr << 16) >> 16);
+ /* set registers */
- throw_cacao_exception_exit(string_java_lang_InternalError,
- "Segmentation fault: 0x%016lx at 0x%016lx\n",
- addr, _mc->sc_pc);
+ if (p != NULL) {
+ _mc->sc_regs[REG_ITMP1_XPTR] = (intptr_t) p;
+ _mc->sc_regs[REG_ITMP2_XPC] = (intptr_t) xpc;
+ _mc->sc_pc = (intptr_t) asm_handle_exception;
}
}
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void thread_restartcriticalsection(ucontext_t *uc)
+/* md_signal_handler_sigusr2 ***************************************************
+
+ Signal handler for profiling sampling.
+
+*******************************************************************************/
+
+#if defined(ENABLE_THREADS)
+void md_signal_handler_sigusr2(int sig, siginfo_t *siginfo, void *_p)
{
- void *critical;
+ threadobject *tobj;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ u1 *pc;
- critical = thread_checkcritical((void *) uc->uc_mcontext.sc_pc);
+ tobj = THREADOBJECT;
- if (critical)
- uc->uc_mcontext.sc_pc = (ptrint) critical;
+ _uc = (ucontext_t *) _p;
+ _mc = &_uc->uc_mcontext;
+
+ pc = (u1 *) _mc->sc_pc;
+
+ tobj->pc = pc;
}
#endif
-/* md_stacktrace_get_returnaddress *********************************************
+/* md_replace_executionstate_read **********************************************
- Returns the return address of the current stackframe, specified by
- the passed stack pointer and the stack frame size.
+ Read the given context into an executionstate for Replacement.
*******************************************************************************/
-u1 *md_stacktrace_get_returnaddress(u1 *sp, u4 framesize)
+#if defined(ENABLE_REPLACEMENT)
+void md_replace_executionstate_read(executionstate_t *es, void *context)
{
- u1 *ra;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ s4 i;
- /* on Alpha the return address is located on the top of the stackframe */
+ _uc = (ucontext_t *) context;
+ _mc = &_uc->uc_mcontext;
- ra = *((u1 **) (sp + framesize - SIZEOF_VOID_P));
+ /* read special registers */
+ es->pc = (u1 *) _mc->sc_pc;
+ es->sp = (u1 *) _mc->sc_regs[REG_SP];
+ es->pv = (u1 *) _mc->sc_regs[REG_PV];
- return ra;
-}
+ /* read integer registers */
+ for (i = 0; i < INT_REG_CNT; i++)
+ es->intregs[i] = _mc->sc_regs[i];
+ /* read float registers */
+ for (i = 0; i < FLT_REG_CNT; i++)
+ es->fltregs[i] = _mc->sc_fpregs[i];
+}
+#endif
-/* md_codegen_findmethod *******************************************************
- Machine code:
+/* md_replace_executionstate_write *********************************************
- 6b5b4000 jsr (pv)
- 277afffe ldah pv,-2(ra)
- 237ba61c lda pv,-23012(pv)
+ Write the given executionstate back to the context for Replacement.
*******************************************************************************/
-u1 *md_codegen_findmethod(u1 *ra)
+#if defined(ENABLE_REPLACEMENT)
+void md_replace_executionstate_write(executionstate_t *es, void *context)
{
- u1 *pv;
- u4 mcode;
- s4 offset;
-
- pv = ra;
+ ucontext_t *_uc;
+ mcontext_t *_mc;
+ s4 i;
- /* get first instruction word after jump */
+ _uc = (ucontext_t *) context;
+ _mc = &_uc->uc_mcontext;
- mcode = *((u4 *) ra);
+ /* write integer registers */
+ for (i = 0; i < INT_REG_CNT; i++)
+ _mc->sc_regs[i] = es->intregs[i];
- /* check if we have 2 instructions (ldah, lda) */
+ /* write float registers */
+ for (i = 0; i < FLT_REG_CNT; i++)
+ _mc->sc_fpregs[i] = es->fltregs[i];
- if ((mcode >> 16) == 0x277a) {
- /* get displacement of first instruction (ldah) */
+ /* write special registers */
+ _mc->sc_pc = es->pc;
+ _mc->sc_regs[REG_SP] = (ptrint) es->sp;
+ _mc->sc_regs[REG_PV] = (ptrint) es->pv;
+}
+#endif
- offset = (s4) (mcode << 16);
- pv += offset;
- /* get displacement of second instruction (lda) */
+/* md_critical_section_restart *************************************************
- mcode = *((u4 *) (ra + 1 * 4));
+ Search the critical sections tree for a matching section and set
+ the PC to the restart point, if necessary.
- if ((mcode >> 16) != 0x237b) {
- log_text("No `lda pv,x(pv)' instruction found on return address!");
- assert(0);
- }
+*******************************************************************************/
- offset = (s2) (mcode & 0x0000ffff);
- pv += offset;
+#if defined(ENABLE_THREADS)
+void md_critical_section_restart(ucontext_t *_uc)
+{
+ mcontext_t *_mc;
+ u1 *pc;
+ u1 *npc;
- } else {
- /* get displacement of first instruction (lda) */
+ _mc = &_uc->uc_mcontext;
- if ((mcode >> 16) != 0x237a) {
- log_text("No `lda pv,x(ra)' instruction found on return address!");
- assert(0);
- }
+ pc = (u1 *) _mc->sc_pc;
- offset = (s2) (mcode & 0x0000ffff);
- pv += offset;
- }
+ npc = critical_find_restart_point(pc);
- return pv;
+ if (npc != NULL)
+ _mc->sc_pc = (ptrint) npc;
}
+#endif
/*