aoqi@1: /* aoqi@1: * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@1: * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved. aoqi@1: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@1: * aoqi@1: * This code is free software; you can redistribute it and/or modify it aoqi@1: * under the terms of the GNU General Public License version 2 only, as aoqi@1: * published by the Free Software Foundation. aoqi@1: * aoqi@1: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@1: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@1: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@1: * version 2 for more details (a copy is included in the LICENSE file that aoqi@1: * accompanied this code). aoqi@1: * aoqi@1: * You should have received a copy of the GNU General Public License version aoqi@1: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@1: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@1: * aoqi@1: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@1: * or visit www.oracle.com if you need additional information or have any aoqi@1: * questions. aoqi@1: * aoqi@1: */ aoqi@1: aoqi@6880: // no precompiled headers aoqi@1: #include "asm/macroAssembler.hpp" aoqi@1: #include "classfile/classLoader.hpp" aoqi@1: #include "classfile/systemDictionary.hpp" aoqi@1: #include "classfile/vmSymbols.hpp" aoqi@1: #include "code/icBuffer.hpp" aoqi@1: #include "code/vtableStubs.hpp" aoqi@1: #include "interpreter/interpreter.hpp" aoqi@1: #include "jvm_linux.h" aoqi@1: #include "memory/allocation.inline.hpp" aoqi@1: #include "mutex_linux.inline.hpp" aoqi@1: #include "os_share_linux.hpp" aoqi@1: #include "prims/jniFastGetField.hpp" aoqi@1: #include "prims/jvm.h" aoqi@1: #include "prims/jvm_misc.hpp" aoqi@1: #include "runtime/arguments.hpp" aoqi@1: #include "runtime/extendedPC.hpp" aoqi@1: #include "runtime/frame.inline.hpp" aoqi@1: #include "runtime/interfaceSupport.hpp" aoqi@1: #include "runtime/java.hpp" aoqi@1: #include "runtime/javaCalls.hpp" aoqi@1: #include "runtime/mutexLocker.hpp" aoqi@1: #include "runtime/osThread.hpp" aoqi@1: #include "runtime/sharedRuntime.hpp" aoqi@1: #include "runtime/stubRoutines.hpp" aoqi@1: #include "runtime/thread.inline.hpp" aoqi@1: #include "runtime/timer.hpp" aoqi@1: #include "utilities/events.hpp" aoqi@1: #include "utilities/vmError.hpp" aoqi@1: #include "utilities/debug.hpp" aoqi@1: #include "compiler/disassembler.hpp" aoqi@1: // put OS-includes here aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: # include aoqi@1: aoqi@1: #define REG_SP 29 aoqi@1: #define REG_FP 30 aoqi@1: aoqi@1: address os::current_stack_pointer() { aoqi@179: register void *sp __asm__ ("$29"); aoqi@179: return (address) sp; aoqi@1: } aoqi@1: aoqi@1: char* os::non_memory_address_word() { aoqi@1: // Must never look like an address returned by reserve_memory, aoqi@1: // even in its subfields (as defined by the CPU immediate fields, aoqi@1: // if the CPU splits constants across multiple instructions). aoqi@1: aoqi@1: return (char*) -1; aoqi@1: } aoqi@1: aoqi@1: void os::initialize_thread(Thread* thr) { aoqi@1: // Nothing to do. aoqi@1: } aoqi@1: aoqi@1: address os::Linux::ucontext_get_pc(ucontext_t * uc) { aoqi@1: //return (address)uc->uc_mcontext.gregs[REG_PC]; aoqi@1: return (address)uc->uc_mcontext.pc;//aoqi:what is gregs? aoqi@1: } aoqi@1: aoqi@1: intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) { aoqi@1: return (intptr_t*)uc->uc_mcontext.gregs[REG_SP]; aoqi@1: } aoqi@1: aoqi@1: intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) { aoqi@1: return (intptr_t*)uc->uc_mcontext.gregs[REG_FP]; aoqi@1: } aoqi@1: aoqi@1: // For Forte Analyzer AsyncGetCallTrace profiling support - thread aoqi@1: // is currently interrupted by SIGPROF. aoqi@1: // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal aoqi@1: // frames. Currently we don't do that on Linux, so it's the same as aoqi@1: // os::fetch_frame_from_context(). aoqi@1: ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, aoqi@1: ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { aoqi@1: aoqi@1: assert(thread != NULL, "just checking"); aoqi@1: assert(ret_sp != NULL, "just checking"); aoqi@1: assert(ret_fp != NULL, "just checking"); aoqi@1: aoqi@1: return os::fetch_frame_from_context(uc, ret_sp, ret_fp); aoqi@1: } aoqi@1: aoqi@1: ExtendedPC os::fetch_frame_from_context(void* ucVoid, aoqi@1: intptr_t** ret_sp, intptr_t** ret_fp) { aoqi@1: aoqi@1: ExtendedPC epc; aoqi@1: ucontext_t* uc = (ucontext_t*)ucVoid; aoqi@1: aoqi@1: if (uc != NULL) { aoqi@9151: epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); aoqi@1: if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc); aoqi@1: if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc); aoqi@1: } else { aoqi@1: // construct empty ExtendedPC for return value checking aoqi@1: epc = ExtendedPC(NULL); aoqi@1: if (ret_sp) *ret_sp = (intptr_t *)NULL; aoqi@1: if (ret_fp) *ret_fp = (intptr_t *)NULL; aoqi@1: } aoqi@1: aoqi@1: return epc; aoqi@1: } aoqi@1: aoqi@1: frame os::fetch_frame_from_context(void* ucVoid) { aoqi@1: intptr_t* sp; aoqi@1: intptr_t* fp; aoqi@1: ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); aoqi@1: return frame(sp, fp, epc.pc()); aoqi@1: } aoqi@1: aoqi@1: // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get aoqi@1: // turned off by -fomit-frame-pointer, aoqi@1: frame os::get_sender_for_C_frame(frame* fr) { aoqi@179: return frame(fr->sender_sp(), fr->link(), fr->sender_pc()); aoqi@1: } aoqi@1: aoqi@1: //intptr_t* _get_previous_fp() { aoqi@1: jint* os::get_previous_fp() { aoqi@179: int *pc; aoqi@179: int sp; aoqi@179: int *pc_limit = (int*)(void*)&os::get_previous_fp; aoqi@179: int insn; aoqi@1: aoqi@179: { aoqi@179: l_pc:; aoqi@179: pc = (int*)&&l_pc; aoqi@179: __asm__ __volatile__ ("move %0, $sp" : "=r" (sp)); aoqi@179: } aoqi@1: aoqi@179: do { aoqi@179: --pc; aoqi@179: insn = *pc; aoqi@179: switch(bitfield(insn, 16, 16)) { aoqi@179: case 0x27bd: /* addiu $sp,$sp,-i */ aoqi@179: case 0x23bd: /* addi $sp,$sp,-i */ aoqi@179: case 0x67bd: /* daddiu $sp,$sp,-i */ aoqi@179: case 0x63bd: /* daddi $sp,$sp,-i */ aoqi@179: assert ((short)bitfield(insn, 0, 16)<0, "bad frame"); aoqi@179: sp -= (short)bitfield(insn, 0, 16); aoqi@179: return (jint*)sp; aoqi@179: } aoqi@179: } while (pc>pc_limit); aoqi@1: aoqi@179: ShouldNotReachHere(); aoqi@1: } aoqi@1: aoqi@6880: aoqi@1: frame os::current_frame() { aoqi@6880: intptr_t* fp = (intptr_t*)get_previous_fp(); aoqi@179: frame myframe((intptr_t*)os::current_stack_pointer(), aoqi@6880: (intptr_t*)fp, aoqi@1: CAST_FROM_FN_PTR(address, os::current_frame)); aoqi@1: if (os::is_first_C_frame(&myframe)) { aoqi@1: // stack is not walkable aoqi@6880: return frame(); aoqi@1: } else { aoqi@1: return os::get_sender_for_C_frame(&myframe); aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: //x86 add 2 new assemble function here! aoqi@179: extern "C" int aoqi@1: JVM_handle_linux_signal(int sig, aoqi@1: siginfo_t* info, aoqi@1: void* ucVoid, aoqi@1: int abort_if_unrecognized) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print_cr("Signal: signo=%d, sicode=%d, sierrno=%d, siaddr=%lx", aoqi@179: info->si_signo, aoqi@179: info->si_code, aoqi@179: info->si_errno, aoqi@179: info->si_addr); aoqi@179: #endif aoqi@1: aoqi@1: ucontext_t* uc = (ucontext_t*) ucVoid; aoqi@1: aoqi@1: Thread* t = ThreadLocalStorage::get_thread_slow(); aoqi@1: aoqi@1: SignalHandlerMark shm(t); aoqi@1: aoqi@1: // Note: it's not uncommon that JNI code uses signal/sigset to install aoqi@1: // then restore certain signal handler (e.g. to temporarily block SIGPIPE, aoqi@1: // or have a SIGILL handler when detecting CPU type). When that happens, aoqi@1: // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To aoqi@1: // avoid unnecessary crash when libjsig is not preloaded, try handle signals aoqi@1: // that do not require siginfo/ucontext first. aoqi@1: aoqi@8012: if (sig == SIGPIPE/* || sig == SIGXFSZ*/) { aoqi@1: // allow chained handler to go first aoqi@1: if (os::Linux::chained_handler(sig, info, ucVoid)) { aoqi@1: return true; aoqi@1: } else { aoqi@1: if (PrintMiscellaneous && (WizardMode || Verbose)) { aoqi@1: warning("Ignoring SIGPIPE - see bug 4229104"); aoqi@1: } aoqi@1: return true; aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: JavaThread* thread = NULL; aoqi@1: VMThread* vmthread = NULL; aoqi@1: if (os::Linux::signal_handlers_are_installed) { aoqi@1: if (t != NULL ){ aoqi@1: if(t->is_Java_thread()) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("this thread is a java thread"); aoqi@179: #endif aoqi@1: thread = (JavaThread*)t; aoqi@1: } aoqi@1: else if(t->is_VM_thread()){ aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("this thread is a VM thread\n"); aoqi@179: #endif aoqi@1: vmthread = (VMThread *)t; aoqi@1: } aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: // decide if this trap can be handled by a stub aoqi@1: address stub = NULL; aoqi@1: address pc = NULL; aoqi@1: aoqi@1: pc = (address) os::Linux::ucontext_get_pc(uc); aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print_cr("pc=%lx", pc); aoqi@1: os::print_context(tty, uc); aoqi@1: #endif aoqi@1: //%note os_trap_1 aoqi@1: if (info != NULL && uc != NULL && thread != NULL) { aoqi@1: pc = (address) os::Linux::ucontext_get_pc(uc); aoqi@1: // Handle ALL stack overflow variations here aoqi@1: if (sig == SIGSEGV) { aoqi@1: address addr = (address) info->si_addr; aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print("handle all stack overflow variations: "); aoqi@6880: /*tty->print("addr = %lx, stack base = %lx, stack top = %lx\n", aoqi@6880: addr, aoqi@6880: thread->stack_base(), aoqi@179: thread->stack_base() - thread->stack_size()); aoqi@179: */ aoqi@179: #endif aoqi@1: aoqi@6880: // check if fault address is within thread stack aoqi@1: if (addr < thread->stack_base() && aoqi@1: addr >= thread->stack_base() - thread->stack_size()) { aoqi@1: // stack overflow aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print("stack exception check \n"); aoqi@179: #endif aoqi@1: if (thread->in_stack_yellow_zone(addr)) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("exception addr is in yellow zone\n"); aoqi@179: #endif aoqi@1: thread->disable_stack_yellow_zone(); aoqi@1: if (thread->thread_state() == _thread_in_Java) { aoqi@1: // Throw a stack overflow exception. Guard pages will be reenabled aoqi@1: // while unwinding the stack. aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("this thread is in java\n"); aoqi@179: #endif aoqi@1: stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); aoqi@1: } else { aoqi@1: // Thread was in the vm or native code. Return and try to finish. aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("this thread is in vm or native codes and return\n"); aoqi@179: #endif aoqi@1: return 1; aoqi@1: } aoqi@1: } else if (thread->in_stack_red_zone(addr)) { aoqi@1: // Fatal red zone violation. Disable the guard pages and fall through aoqi@1: // to handle_unexpected_exception way down below. aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("exception addr is in red zone\n"); aoqi@179: #endif aoqi@1: thread->disable_stack_red_zone(); aoqi@1: tty->print_raw_cr("An irrecoverable stack overflow has occurred."); aoqi@6880: aoqi@6880: // This is a likely cause, but hard to verify. Let's just print aoqi@6880: // it as a hint. aoqi@6880: tty->print_raw_cr("Please check if any of your loaded .so files has " aoqi@6880: "enabled executable stack (see man page execstack(8))"); aoqi@1: } else { aoqi@1: // Accessing stack address below sp may cause SEGV if current aoqi@1: // thread has MAP_GROWSDOWN stack. This should only happen when aoqi@1: // current thread was created by user code with MAP_GROWSDOWN flag aoqi@1: // and then attached to VM. See notes in os_linux.cpp. aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("exception addr is neither in yellow zone nor in the red one\n"); aoqi@179: #endif aoqi@1: if (thread->osthread()->expanding_stack() == 0) { aoqi@1: thread->osthread()->set_expanding_stack(); aoqi@1: if (os::Linux::manually_expand_stack(thread, addr)) { aoqi@1: thread->osthread()->clear_expanding_stack(); aoqi@1: return 1; aoqi@1: } aoqi@1: thread->osthread()->clear_expanding_stack(); aoqi@1: } else { aoqi@1: fatal("recursive segv. expanding stack."); aoqi@1: } aoqi@1: } aoqi@1: } //addr < aoqi@1: } //sig == SIGSEGV aoqi@1: aoqi@1: if (thread->thread_state() == _thread_in_Java) { aoqi@1: // Java thread running in Java code => find exception handler if any aoqi@1: // a fault inside compiled code, the interpreter, or a stub aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print("java thread running in java code\n"); aoqi@179: #endif aoqi@8012: wangxue@9146: // Handle signal from NativeJump::patch_verified_entry(). wangxue@9146: if (sig == SIGILL & nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) { wangxue@9146: #ifdef PRINT_SIGNAL_HANDLE wangxue@9146: tty->print_cr("verified entry = %lx, sig=%d", nativeInstruction_at(pc), sig); wangxue@9146: #endif wangxue@9146: stub = SharedRuntime::get_handle_wrong_method_stub(); wangxue@9146: } else if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) { aoqi@8012: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("polling address = %lx, sig=%d", os::get_polling_page(), sig); aoqi@8012: #endif aoqi@1: stub = SharedRuntime::get_poll_stub(pc); aoqi@1: } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) { aoqi@1: // BugId 4454115: A read from a MappedByteBuffer can fault aoqi@1: // here if the underlying file has been truncated. aoqi@1: // Do not crash the VM in such a case. aoqi@1: CodeBlob* cb = CodeCache::find_blob_unsafe(pc); aoqi@1: nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print("cb = %lx, nm = %lx\n", cb, nm); aoqi@179: #endif aoqi@1: if (nm != NULL && nm->has_unsafe_access()) { aoqi@1: stub = StubRoutines::handler_for_unsafe_access(); aoqi@1: } aoqi@1: } else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) { aoqi@1: // HACK: si_code does not work on linux 2.2.12-20!!! aoqi@1: int op = pc[0] & 0x3f; aoqi@179: int op1 = pc[3] & 0x3f; aoqi@179: tty->print_cr("unknown opcode 0x%X -0x%X with SIGFPE.", op, op1); aoqi@179: //FIXME, Must port to mips code!! aoqi@1: switch (op) { aoqi@179: case 0x1e: //ddiv aoqi@179: case 0x1f: //ddivu aoqi@179: case 0x1a: //div aoqi@179: case 0x1b: //divu aoqi@179: case 0x34: //trap aoqi@179: /* In MIPS, div_by_zero exception can only be triggered by explicit 'trap'. aoqi@179: * Ref: [c1_LIRAssembler_mips.cpp] arithmetic_idiv() aoqi@179: */ aoqi@179: stub = SharedRuntime::continuation_for_implicit_exception(thread, aoqi@179: pc, aoqi@1: SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); aoqi@179: break; aoqi@1: default: aoqi@179: // TODO: handle more cases if we are using other x86 instructions aoqi@179: // that can generate SIGFPE signal on linux. aoqi@179: tty->print_cr("unknown opcode 0x%X -0x%X with SIGFPE.", op, op1); aoqi@179: //fatal("please update this code."); aoqi@179: } aoqi@8012: } else if (sig == SIGSEGV && aoqi@179: !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { aoqi@8012: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print("continuation for implicit exception\n"); aoqi@8012: #endif aoqi@179: // Determination of interpreter/vtable stub/compiled code null exception aoqi@8012: stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("continuation_for_implicit_exception stub: %lx", stub); aoqi@179: #endif aoqi@8012: } else if (/*thread->thread_state() == _thread_in_Java && */sig == SIGILL) { aoqi@395: //Since kernel does not have emulation of PS instructions yet, the emulation must be handled here. aoqi@395: //The method is to trigger kernel emulation of float emulation. aoqi@395: int inst = *(int*)pc; aoqi@395: int ops = (inst >> 26) & 0x3f; aoqi@395: int ops_fmt = (inst >> 21) & 0x1f; aoqi@395: int op = inst & 0x3f; aoqi@395: if (ops == Assembler::cop1_op && ops_fmt == Assembler::ps_fmt) { aoqi@395: int ft, fs, fd; aoqi@395: ft = (inst >> 16) & 0x1f; aoqi@395: fs = (inst >> 11) & 0x1f; aoqi@395: fd = (inst >> 6) & 0x1f; aoqi@395: float ft_upper, ft_lower, fs_upper, fs_lower, fd_upper, fd_lower; aoqi@395: double ft_value, fs_value, fd_value; aoqi@395: ft_value = uc->uc_mcontext.fpregs.fp_r.fp_dregs[ft]; aoqi@395: fs_value = uc->uc_mcontext.fpregs.fp_r.fp_dregs[fs]; fujie@414: __asm__ __volatile__ ( aoqi@395: "cvt.s.pl %0, %4\n\t" aoqi@395: "cvt.s.pu %1, %4\n\t" aoqi@395: "cvt.s.pl %2, %5\n\t" aoqi@395: "cvt.s.pu %3, %5\n\t" aoqi@395: : "=f" (fs_lower), "=f" (fs_upper), "=f" (ft_lower), "=f" (ft_upper) aoqi@395: : "f" (fs_value), "f" (ft_value) aoqi@395: ); aoqi@395: aoqi@395: switch (op) { aoqi@395: case Assembler::fadd_op: fujie@414: __asm__ __volatile__ ( aoqi@395: "add.s %1, %3, %5\n\t" aoqi@395: "add.s %2, %4, %6\n\t" aoqi@395: "pll.ps %0, %1, %2\n\t" aoqi@395: : "=f" (fd_value), "=f" (fd_upper), "=f" (fd_lower) aoqi@395: : "f" (fs_upper), "f" (fs_lower), "f" (ft_upper), "f" (ft_lower) aoqi@395: ); aoqi@395: uc->uc_mcontext.fpregs.fp_r.fp_dregs[fd] = fd_value; aoqi@395: stub = pc + 4; aoqi@395: break; aoqi@395: case Assembler::fsub_op: aoqi@395: //fd = fs - ft fujie@414: __asm__ __volatile__ ( aoqi@395: "sub.s %1, %3, %5\n\t" aoqi@395: "sub.s %2, %4, %6\n\t" aoqi@395: "pll.ps %0, %1, %2\n\t" aoqi@395: : "=f" (fd_value), "=f" (fd_upper), "=f" (fd_lower) aoqi@395: : "f" (fs_upper), "f" (fs_lower), "f" (ft_upper), "f" (ft_lower) aoqi@395: ); aoqi@395: uc->uc_mcontext.fpregs.fp_r.fp_dregs[fd] = fd_value; aoqi@395: stub = pc + 4; aoqi@395: break; aoqi@395: case Assembler::fmul_op: fujie@414: __asm__ __volatile__ ( aoqi@395: "mul.s %1, %3, %5\n\t" aoqi@395: "mul.s %2, %4, %6\n\t" aoqi@395: "pll.ps %0, %1, %2\n\t" aoqi@395: : "=f" (fd_value), "=f" (fd_upper), "=f" (fd_lower) aoqi@395: : "f" (fs_upper), "f" (fs_lower), "f" (ft_upper), "f" (ft_lower) aoqi@395: ); aoqi@395: uc->uc_mcontext.fpregs.fp_r.fp_dregs[fd] = fd_value; aoqi@395: stub = pc + 4; aoqi@395: break; aoqi@395: default: aoqi@395: tty->print_cr("unknown cop1 opcode 0x%x with SIGILL.", op); aoqi@395: } aoqi@8012: } else if (ops == Assembler::cop1x_op /*&& op == Assembler::nmadd_ps_op*/) { aoqi@395: // madd.ps is not used, the code below were not tested aoqi@395: int fr, ft, fs, fd; aoqi@395: float fr_upper, fr_lower, fs_upper, fs_lower, ft_upper, ft_lower, fd_upper, fd_lower; aoqi@395: double fr_value, ft_value, fs_value, fd_value; aoqi@395: switch (op) { aoqi@395: case Assembler::madd_ps_op: aoqi@395: // fd = (fs * ft) + fr aoqi@395: fr = (inst >> 21) & 0x1f; aoqi@395: ft = (inst >> 16) & 0x1f; aoqi@395: fs = (inst >> 11) & 0x1f; aoqi@395: fd = (inst >> 6) & 0x1f; aoqi@395: fr_value = uc->uc_mcontext.fpregs.fp_r.fp_dregs[fr]; aoqi@395: ft_value = uc->uc_mcontext.fpregs.fp_r.fp_dregs[ft]; aoqi@395: fs_value = uc->uc_mcontext.fpregs.fp_r.fp_dregs[fs]; fujie@414: __asm__ __volatile__ ( aoqi@395: "cvt.s.pu %3, %9\n\t" aoqi@395: "cvt.s.pl %4, %9\n\t" aoqi@395: "cvt.s.pu %5, %10\n\t" aoqi@395: "cvt.s.pl %6, %10\n\t" aoqi@395: "cvt.s.pu %7, %11\n\t" aoqi@395: "cvt.s.pl %8, %11\n\t" aoqi@395: "madd.s %1, %3, %5, %7\n\t" aoqi@395: "madd.s %2, %4, %6, %8\n\t" aoqi@395: "pll.ps %0, %1, %2\n\t" aoqi@395: : "=f" (fd_value), "=f" (fd_upper), "=f" (fd_lower), "=f" (fr_upper), "=f" (fr_lower), "=f" (fs_upper), "=f" (fs_lower), "=f" (ft_upper), "=f" (ft_lower) aoqi@395: : "f" (fr_value)/*9*/, "f" (fs_value)/*10*/, "f" (ft_value)/*11*/ aoqi@395: ); aoqi@395: uc->uc_mcontext.fpregs.fp_r.fp_dregs[fd] = fd_value; aoqi@395: stub = pc + 4; aoqi@395: break; aoqi@395: default: aoqi@395: tty->print_cr("unknown cop1x opcode 0x%x with SIGILL.", op); aoqi@395: } aoqi@395: } aoqi@395: } //SIGILL aoqi@1: } else if (thread->thread_state() == _thread_in_vm && aoqi@1: sig == SIGBUS && /* info->si_code == BUS_OBJERR && */ aoqi@1: thread->doing_unsafe_access()) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@179: tty->print_cr("SIGBUS in vm thread \n"); aoqi@179: #endif aoqi@8012: stub = StubRoutines::handler_for_unsafe_access(); aoqi@1: } aoqi@1: aoqi@1: // jni_fast_GetField can trap at certain pc's if a GC kicks in aoqi@1: // and the heap gets shrunk before the field access. aoqi@1: if ((sig == SIGSEGV) || (sig == SIGBUS)) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print("jni fast get trap: "); aoqi@179: #endif aoqi@1: address addr = JNI_FastGetField::find_slowcase_pc(pc); aoqi@1: if (addr != (address)-1) { aoqi@1: stub = addr; aoqi@1: } aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("addr = %d, stub = %lx", addr, stub); aoqi@179: #endif aoqi@1: } aoqi@1: aoqi@1: // Check to see if we caught the safepoint code in the aoqi@1: // process of write protecting the memory serialization page. aoqi@1: // It write enables the page immediately after protecting it aoqi@1: // so we can just return to retry the write. aoqi@1: if ((sig == SIGSEGV) && aoqi@1: os::is_memory_serialize_page(thread, (address) info->si_addr)) { aoqi@8012: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print("write protecting the memory serialiazation page\n"); aoqi@8012: #endif aoqi@1: // Block current thread until the memory serialize page permission restored. aoqi@1: os::block_on_serialize_page_trap(); aoqi@1: return true; aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: // Execution protection violation aoqi@1: // aoqi@1: // This should be kept as the last step in the triage. We don't aoqi@1: // have a dedicated trap number for a no-execute fault, so be aoqi@1: // conservative and allow other handlers the first shot. aoqi@1: // aoqi@1: // Note: We don't test that info->si_code == SEGV_ACCERR here. aoqi@1: // this si_code is so generic that it is almost meaningless; and aoqi@1: // the si_code for this condition may change in the future. aoqi@1: // Furthermore, a false-positive should be harmless. aoqi@1: if (UnguardOnExecutionViolation > 0 && aoqi@1: //(sig == SIGSEGV || sig == SIGBUS) && aoqi@1: //uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) { aoqi@179: (sig == SIGSEGV || sig == SIGBUS aoqi@1: #ifdef OPT_RANGECHECK aoqi@179: || sig == SIGSYS aoqi@1: #endif aoqi@179: ) && aoqi@179: //(uc->uc_mcontext.cause == 2 || uc->uc_mcontext.cause == 3)) { aoqi@179: (uc->uc_mcontext.hi1 == 2 || uc->uc_mcontext.hi1 == 3)) { aoqi@179: //aoqi: copy from jdk1.5, dont understand the struct mcontext_t. aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print_cr("execution protection violation\n"); aoqi@1: #endif aoqi@179: aoqi@1: int page_size = os::vm_page_size(); aoqi@1: address addr = (address) info->si_addr; aoqi@1: address pc = os::Linux::ucontext_get_pc(uc); aoqi@1: // Make sure the pc and the faulting address are sane. aoqi@1: // aoqi@1: // If an instruction spans a page boundary, and the page containing aoqi@1: // the beginning of the instruction is executable but the following aoqi@1: // page is not, the pc and the faulting address might be slightly aoqi@1: // different - we still want to unguard the 2nd page in this case. aoqi@1: // aoqi@1: // 15 bytes seems to be a (very) safe value for max instruction size. aoqi@1: bool pc_is_near_addr = aoqi@1: (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15); aoqi@1: bool instr_spans_page_boundary = aoqi@1: (align_size_down((intptr_t) pc ^ (intptr_t) addr, aoqi@1: (intptr_t) page_size) > 0); aoqi@1: aoqi@1: if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) { aoqi@1: static volatile address last_addr = aoqi@1: (address) os::non_memory_address_word(); aoqi@1: aoqi@1: // In conservative mode, don't unguard unless the address is in the VM aoqi@1: if (addr != last_addr && aoqi@1: (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) { aoqi@1: aoqi@1: // Set memory to RWX and retry aoqi@1: address page_start = aoqi@1: (address) align_size_down((intptr_t) addr, (intptr_t) page_size); aoqi@19: bool res = os::protect_memory((char*) page_start, page_size, aoqi@19: os::MEM_PROT_RWX); aoqi@1: aoqi@1: if (PrintMiscellaneous && Verbose) { aoqi@1: char buf[256]; aoqi@1: jio_snprintf(buf, sizeof(buf), "Execution protection violation " aoqi@1: "at " INTPTR_FORMAT aoqi@1: ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr, aoqi@1: page_start, (res ? "success" : "failed"), errno); aoqi@1: tty->print_raw_cr(buf); aoqi@1: } aoqi@1: stub = pc; aoqi@1: aoqi@1: // Set last_addr so if we fault again at the same address, we don't end aoqi@1: // up in an endless loop. aoqi@1: // aoqi@1: // There are two potential complications here. Two threads trapping at aoqi@1: // the same address at the same time could cause one of the threads to aoqi@1: // think it already unguarded, and abort the VM. Likely very rare. aoqi@1: // aoqi@1: // The other race involves two threads alternately trapping at aoqi@1: // different addresses and failing to unguard the page, resulting in aoqi@1: // an endless loop. This condition is probably even more unlikely than aoqi@1: // the first. aoqi@1: // aoqi@1: // Although both cases could be avoided by using locks or thread local aoqi@1: // last_addr, these solutions are unnecessary complication: this aoqi@1: // handler is a best-effort safety net, not a complete solution. It is aoqi@1: // disabled by default and should only be used as a workaround in case aoqi@1: // we missed any no-execute-unsafe VM code. aoqi@1: aoqi@1: last_addr = addr; aoqi@1: } aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: if (stub != NULL) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@8012: tty->print_cr("resolved stub=%lx\n",stub); aoqi@179: #endif aoqi@1: // save all thread context in case we need to restore it aoqi@1: if (thread != NULL) thread->set_saved_exception_pc(pc); aoqi@1: aoqi@1: uc->uc_mcontext.pc = (greg_t)stub; aoqi@1: return true; aoqi@1: } aoqi@1: aoqi@1: // signal-chaining aoqi@1: if (os::Linux::chained_handler(sig, info, ucVoid)) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print_cr("signal chaining\n"); aoqi@179: #endif aoqi@1: return true; aoqi@1: } aoqi@1: aoqi@1: if (!abort_if_unrecognized) { aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print_cr("abort becauce of unrecognized\n"); aoqi@179: #endif aoqi@8012: // caller wants another chance, so give it to him aoqi@1: return false; aoqi@1: } aoqi@1: aoqi@1: if (pc == NULL && uc != NULL) { aoqi@1: pc = os::Linux::ucontext_get_pc(uc); aoqi@1: } aoqi@1: aoqi@1: // unmask current signal aoqi@1: sigset_t newset; aoqi@1: sigemptyset(&newset); aoqi@1: sigaddset(&newset, sig); aoqi@1: sigprocmask(SIG_UNBLOCK, &newset, NULL); aoqi@181: #ifdef PRINT_SIGNAL_HANDLE aoqi@1: tty->print_cr("VMError in signal handler\n"); aoqi@179: #endif aoqi@1: VMError err(t, sig, pc, info, ucVoid); aoqi@1: err.report_and_die(); aoqi@1: aoqi@1: ShouldNotReachHere(); aoqi@1: } aoqi@1: aoqi@179: // FCSR:...|24| 23 |22|21|... aoqi@179: // ...|FS|FCC0|FO|FN|... aoqi@1: void os::Linux::init_thread_fpu_state(void) { aoqi@179: if (SetFSFOFN == 999) aoqi@179: return; aoqi@179: int fs = (SetFSFOFN / 100)? 1:0; aoqi@179: int fo = ((SetFSFOFN % 100) / 10)? 1:0; aoqi@179: int fn = (SetFSFOFN % 10)? 1:0; aoqi@179: int mask = fs << 24 | fo << 22 | fn << 21; aoqi@179: aoqi@179: int fcsr = get_fpu_control_word(); aoqi@179: fcsr = fcsr | mask; aoqi@179: set_fpu_control_word(fcsr); aoqi@179: /* aoqi@179: if (fcsr != get_fpu_control_word()) aoqi@179: tty->print_cr(" fail to set to %lx, get_fpu_control_word:%lx", fcsr, get_fpu_control_word()); aoqi@179: */ aoqi@1: } aoqi@1: aoqi@1: int os::Linux::get_fpu_control_word(void) { aoqi@179: int fcsr; fujie@414: __asm__ __volatile__ ( aoqi@179: ".set noat;" aoqi@179: "daddiu %0, $0, 0;" aoqi@179: "cfc1 %0, $31;" aoqi@179: : "=r" (fcsr) aoqi@179: ); aoqi@179: return fcsr; aoqi@1: } aoqi@1: aoqi@1: void os::Linux::set_fpu_control_word(int fpu_control) { fujie@414: __asm__ __volatile__ ( aoqi@179: ".set noat;" aoqi@179: "ctc1 %0, $31;" aoqi@179: : aoqi@179: : "r" (fpu_control) aoqi@179: ); aoqi@1: } aoqi@1: aoqi@1: bool os::is_allocatable(size_t bytes) { aoqi@1: aoqi@1: if (bytes < 2 * G) { aoqi@1: return true; aoqi@1: } aoqi@1: aoqi@1: char* addr = reserve_memory(bytes, NULL); aoqi@1: aoqi@1: if (addr != NULL) { aoqi@1: release_memory(addr, bytes); aoqi@1: } aoqi@1: aoqi@1: return addr != NULL; aoqi@1: } aoqi@1: aoqi@1: //////////////////////////////////////////////////////////////////////////////// aoqi@1: // thread stack aoqi@1: aoqi@1: size_t os::Linux::min_stack_allowed = 96 * K; aoqi@1: aoqi@1: aoqi@1: // Test if pthread library can support variable thread stack size. LinuxThreads aoqi@1: // in fixed stack mode allocates 2M fixed slot for each thread. LinuxThreads aoqi@1: // in floating stack mode and NPTL support variable stack size. aoqi@1: bool os::Linux::supports_variable_stack_size() { aoqi@1: if (os::Linux::is_NPTL()) { aoqi@1: // NPTL, yes aoqi@1: return true; aoqi@1: aoqi@1: } else { aoqi@1: // Note: We can't control default stack size when creating a thread. aoqi@1: // If we use non-default stack size (pthread_attr_setstacksize), both aoqi@1: // floating stack and non-floating stack LinuxThreads will return the aoqi@1: // same value. This makes it impossible to implement this function by aoqi@1: // detecting thread stack size directly. aoqi@1: // aoqi@1: // An alternative approach is to check %gs. Fixed-stack LinuxThreads aoqi@1: // do not use %gs, so its value is 0. Floating-stack LinuxThreads use aoqi@1: // %gs (either as LDT selector or GDT selector, depending on kernel) aoqi@1: // to access thread specific data. aoqi@1: // aoqi@1: // Note that %gs is a reserved glibc register since early 2001, so aoqi@1: // applications are not allowed to change its value (Ulrich Drepper from aoqi@179: // Redhat confirmed that all known offenders have been modified to use aoqi@1: // either %fs or TSD). In the worst case scenario, when VM is embedded in aoqi@1: // a native application that plays with %gs, we might see non-zero %gs aoqi@1: // even LinuxThreads is running in fixed stack mode. As the result, we'll aoqi@1: // return true and skip _thread_safety_check(), so we may not be able to aoqi@1: // detect stack-heap collisions. But otherwise it's harmless. aoqi@1: // aoqi@1: return false; aoqi@1: } aoqi@1: } aoqi@1: aoqi@1: // return default stack size for thr_type aoqi@1: size_t os::Linux::default_stack_size(os::ThreadType thr_type) { aoqi@1: // default stack size (compiler thread needs larger stack) aoqi@1: size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K); aoqi@1: return s; aoqi@1: } aoqi@1: aoqi@1: size_t os::Linux::default_guard_size(os::ThreadType thr_type) { aoqi@1: // Creating guard page is very expensive. Java thread has HotSpot aoqi@1: // guard page, only enable glibc guard page for non-Java threads. aoqi@1: return (thr_type == java_thread ? 0 : page_size()); aoqi@1: } aoqi@1: aoqi@1: // Java thread: aoqi@1: // aoqi@1: // Low memory addresses aoqi@1: // +------------------------+ aoqi@1: // | |\ JavaThread created by VM does not have glibc aoqi@1: // | glibc guard page | - guard, attached Java thread usually has aoqi@1: // | |/ 1 page glibc guard. aoqi@1: // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() aoqi@1: // | |\ aoqi@1: // | HotSpot Guard Pages | - red and yellow pages aoqi@1: // | |/ aoqi@1: // +------------------------+ JavaThread::stack_yellow_zone_base() aoqi@1: // | |\ aoqi@1: // | Normal Stack | - aoqi@1: // | |/ aoqi@1: // P2 +------------------------+ Thread::stack_base() aoqi@1: // aoqi@1: // Non-Java thread: aoqi@1: // aoqi@1: // Low memory addresses aoqi@1: // +------------------------+ aoqi@1: // | |\ aoqi@1: // | glibc guard page | - usually 1 page aoqi@1: // | |/ aoqi@1: // P1 +------------------------+ Thread::stack_base() - Thread::stack_size() aoqi@1: // | |\ aoqi@1: // | Normal Stack | - aoqi@1: // | |/ aoqi@1: // P2 +------------------------+ Thread::stack_base() aoqi@1: // aoqi@1: // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from aoqi@1: // pthread_attr_getstack() aoqi@1: aoqi@1: static void current_stack_region(address * bottom, size_t * size) { aoqi@1: if (os::Linux::is_initial_thread()) { aoqi@1: // initial thread needs special handling because pthread_getattr_np() aoqi@1: // may return bogus value. aoqi@1: *bottom = os::Linux::initial_thread_stack_bottom(); aoqi@1: *size = os::Linux::initial_thread_stack_size(); aoqi@1: } else { aoqi@1: pthread_attr_t attr; aoqi@1: aoqi@1: int rslt = pthread_getattr_np(pthread_self(), &attr); aoqi@1: aoqi@1: // JVM needs to know exact stack location, abort if it fails aoqi@1: if (rslt != 0) { aoqi@1: if (rslt == ENOMEM) { aoqi@1: vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np"); aoqi@1: } else { aoqi@1: fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); aoqi@1: } aoqi@1: } aoqi@1: aoqi@179: if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) { aoqi@179: fatal("Can not locate current stack attributes!"); aoqi@179: } aoqi@179: aoqi@1: pthread_attr_destroy(&attr); aoqi@1: aoqi@1: } aoqi@1: assert(os::current_stack_pointer() >= *bottom && aoqi@1: os::current_stack_pointer() < *bottom + *size, "just checking"); aoqi@1: } aoqi@1: aoqi@1: address os::current_stack_base() { aoqi@1: address bottom; aoqi@1: size_t size; aoqi@1: current_stack_region(&bottom, &size); aoqi@1: return (bottom + size); aoqi@1: } aoqi@1: aoqi@1: size_t os::current_stack_size() { aoqi@1: // stack size includes normal stack and HotSpot guard pages aoqi@1: address bottom; aoqi@1: size_t size; aoqi@1: current_stack_region(&bottom, &size); aoqi@1: return size; aoqi@1: } aoqi@1: aoqi@1: ///////////////////////////////////////////////////////////////////////////// aoqi@1: // helper functions for fatal error handler aoqi@1: void os::print_register_info(outputStream *st, void *context) { aoqi@1: if (context == NULL) return; aoqi@1: aoqi@1: ucontext_t *uc = (ucontext_t*)context; aoqi@1: aoqi@1: st->print_cr("Register to memory mapping:"); aoqi@1: st->cr(); aoqi@1: // this is horrendously verbose but the layout of the registers in the aoqi@1: // // context does not match how we defined our abstract Register set, so aoqi@1: // // we can't just iterate through the gregs area aoqi@1: // aoqi@1: // // this is only for the "general purpose" registers aoqi@1: st->print("R0=" ); print_location(st, uc->uc_mcontext.gregs[0]); aoqi@1: st->print("AT=" ); print_location(st, uc->uc_mcontext.gregs[1]); aoqi@1: st->print("V0=" ); print_location(st, uc->uc_mcontext.gregs[2]); aoqi@1: st->print("V1=" ); print_location(st, uc->uc_mcontext.gregs[3]); aoqi@1: st->cr(); aoqi@1: st->print("A0=" ); print_location(st, uc->uc_mcontext.gregs[4]); aoqi@1: st->print("A1=" ); print_location(st, uc->uc_mcontext.gregs[5]); aoqi@1: st->print("A2=" ); print_location(st, uc->uc_mcontext.gregs[6]); aoqi@1: st->print("A3=" ); print_location(st, uc->uc_mcontext.gregs[7]); aoqi@1: st->cr(); aoqi@1: st->print("A4=" ); print_location(st, uc->uc_mcontext.gregs[8]); aoqi@1: st->print("A5=" ); print_location(st, uc->uc_mcontext.gregs[9]); aoqi@1: st->print("A6=" ); print_location(st, uc->uc_mcontext.gregs[10]); aoqi@1: st->print("A7=" ); print_location(st, uc->uc_mcontext.gregs[11]); aoqi@1: st->cr(); aoqi@1: st->print("T0=" ); print_location(st, uc->uc_mcontext.gregs[12]); aoqi@1: st->print("T1=" ); print_location(st, uc->uc_mcontext.gregs[13]); aoqi@1: st->print("T2=" ); print_location(st, uc->uc_mcontext.gregs[14]); aoqi@1: st->print("T3=" ); print_location(st, uc->uc_mcontext.gregs[15]); aoqi@1: st->cr(); aoqi@1: st->print("S0=" ); print_location(st, uc->uc_mcontext.gregs[16]); aoqi@1: st->print("S1=" ); print_location(st, uc->uc_mcontext.gregs[17]); aoqi@1: st->print("S2=" ); print_location(st, uc->uc_mcontext.gregs[18]); aoqi@1: st->print("S3=" ); print_location(st, uc->uc_mcontext.gregs[19]); aoqi@1: st->cr(); aoqi@1: st->print("S4=" ); print_location(st, uc->uc_mcontext.gregs[20]); aoqi@1: st->print("S5=" ); print_location(st, uc->uc_mcontext.gregs[21]); aoqi@1: st->print("S6=" ); print_location(st, uc->uc_mcontext.gregs[22]); aoqi@1: st->print("S7=" ); print_location(st, uc->uc_mcontext.gregs[23]); aoqi@1: st->cr(); aoqi@1: st->print("T8=" ); print_location(st, uc->uc_mcontext.gregs[24]); aoqi@1: st->print("T9=" ); print_location(st, uc->uc_mcontext.gregs[25]); aoqi@1: st->print("K0=" ); print_location(st, uc->uc_mcontext.gregs[26]); aoqi@1: st->print("K1=" ); print_location(st, uc->uc_mcontext.gregs[27]); aoqi@1: st->cr(); aoqi@1: st->print("GP=" ); print_location(st, uc->uc_mcontext.gregs[28]); aoqi@1: st->print("SP=" ); print_location(st, uc->uc_mcontext.gregs[29]); aoqi@1: st->print("FP=" ); print_location(st, uc->uc_mcontext.gregs[30]); aoqi@1: st->print("RA=" ); print_location(st, uc->uc_mcontext.gregs[31]); aoqi@1: st->cr(); aoqi@179: aoqi@1: } aoqi@1: void os::print_context(outputStream *st, void *context) { aoqi@1: if (context == NULL) return; aoqi@1: aoqi@1: ucontext_t *uc = (ucontext_t*)context; aoqi@1: st->print_cr("Registers:"); aoqi@1: st->print( "R0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[0]); aoqi@1: st->print(", AT=" INTPTR_FORMAT, uc->uc_mcontext.gregs[1]); aoqi@1: st->print(", V0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[2]); aoqi@1: st->print(", V1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[3]); aoqi@1: st->cr(); aoqi@1: st->print( "A0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[4]); aoqi@1: st->print(", A1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[5]); aoqi@1: st->print(", A2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[6]); aoqi@1: st->print(", A3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[7]); aoqi@1: st->cr(); aoqi@1: st->print( "A4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[8]); aoqi@1: st->print(", A5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[9]); aoqi@1: st->print(", A6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[10]); aoqi@1: st->print(", A7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[11]); aoqi@1: st->cr(); aoqi@1: st->print( "T0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[12]); aoqi@1: st->print(", T1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[13]); aoqi@1: st->print(", T2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[14]); aoqi@1: st->print(", T3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[15]); aoqi@1: st->cr(); aoqi@1: st->print( "S0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[16]); aoqi@1: st->print(", S1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[17]); aoqi@1: st->print(", S2=" INTPTR_FORMAT, uc->uc_mcontext.gregs[18]); aoqi@1: st->print(", S3=" INTPTR_FORMAT, uc->uc_mcontext.gregs[19]); aoqi@1: st->cr(); aoqi@1: st->print( "S4=" INTPTR_FORMAT, uc->uc_mcontext.gregs[20]); aoqi@1: st->print(", S5=" INTPTR_FORMAT, uc->uc_mcontext.gregs[21]); aoqi@1: st->print(", S6=" INTPTR_FORMAT, uc->uc_mcontext.gregs[22]); aoqi@1: st->print(", S7=" INTPTR_FORMAT, uc->uc_mcontext.gregs[23]); aoqi@1: st->cr(); aoqi@1: st->print( "T8=" INTPTR_FORMAT, uc->uc_mcontext.gregs[24]); aoqi@1: st->print(", T9=" INTPTR_FORMAT, uc->uc_mcontext.gregs[25]); aoqi@1: st->print(", K0=" INTPTR_FORMAT, uc->uc_mcontext.gregs[26]); aoqi@1: st->print(", K1=" INTPTR_FORMAT, uc->uc_mcontext.gregs[27]); aoqi@1: st->cr(); aoqi@1: st->print( "GP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[28]); aoqi@1: st->print(", SP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[29]); aoqi@1: st->print(", FP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[30]); aoqi@1: st->print(", RA=" INTPTR_FORMAT, uc->uc_mcontext.gregs[31]); aoqi@1: st->cr(); aoqi@1: st->cr(); aoqi@1: aoqi@1: intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); aoqi@1: st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); aoqi@1: //print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t)); aoqi@1: print_hex_dump(st, (address)sp-32, (address)(sp + 32), sizeof(intptr_t)); aoqi@1: st->cr(); aoqi@1: aoqi@1: // Note: it may be unsafe to inspect memory near pc. For example, pc may aoqi@1: // point to garbage if entry point in an nmethod is corrupted. Leave aoqi@1: // this at the end, and hope for the best. aoqi@1: address pc = os::Linux::ucontext_get_pc(uc); aoqi@1: st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); aoqi@1: print_hex_dump(st, pc - 64, pc + 64, sizeof(char)); aoqi@1: Disassembler::decode(pc - 80, pc + 80, st); aoqi@1: } aoqi@1: aoqi@179: void os::setup_fpu() { aoqi@179: /* aoqi@179: //no use for MIPS aoqi@179: int fcsr; aoqi@179: address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std(); fujie@414: __asm__ __volatile__ ( aoqi@179: ".set noat;" aoqi@179: "cfc1 %0, $31;" aoqi@179: "sw %0, 0(%1);" aoqi@179: : "=r" (fcsr) aoqi@179: : "r" (fpu_cntrl) aoqi@179: : "memory" aoqi@179: ); aoqi@179: printf("fpu_cntrl: %lx\n", fpu_cntrl); aoqi@179: */ aoqi@179: } aoqi@179: aoqi@1: #ifndef PRODUCT aoqi@1: void os::verify_stack_alignment() { aoqi@1: assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment"); aoqi@1: } aoqi@1: #endif