0N/A/*
1879N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "asm/assembler.hpp"
1879N/A#include "assembler_x86.inline.hpp"
1879N/A#include "runtime/os.hpp"
1879N/A#include "runtime/threadLocalStorage.hpp"
0N/A
0N/A
0N/Avoid MacroAssembler::int3() {
304N/A push(rax);
304N/A push(rdx);
304N/A push(rcx);
0N/A call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
304N/A pop(rcx);
304N/A pop(rdx);
304N/A pop(rax);
0N/A}
0N/A
304N/A#define __ _masm->
304N/A#ifndef _LP64
304N/Astatic void slow_call_thr_specific(MacroAssembler* _masm, Register thread) {
0N/A
0N/A // slow call to of thr_getspecific
0N/A // int thr_getspecific(thread_key_t key, void **value);
0N/A // Consider using pthread_getspecific instead.
0N/A
304N/A__ push(0); // allocate space for return value
304N/A if (thread != rax) __ push(rax); // save rax, if caller still wants it
304N/A__ push(rcx); // save caller save
304N/A__ push(rdx); // save caller save
0N/A if (thread != rax) {
304N/A__ lea(thread, Address(rsp, 3 * sizeof(int))); // address of return value
0N/A } else {
304N/A__ lea(thread, Address(rsp, 2 * sizeof(int))); // address of return value
304N/A }
304N/A__ push(thread); // and pass the address
304N/A__ push(ThreadLocalStorage::thread_index()); // the key
304N/A__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, thr_getspecific)));
304N/A__ increment(rsp, 2 * wordSize);
304N/A__ pop(rdx);
304N/A__ pop(rcx);
304N/A if (thread != rax) __ pop(rax);
304N/A__ pop(thread);
304N/A
304N/A}
304N/A#else
304N/Astatic void slow_call_thr_specific(MacroAssembler* _masm, Register thread) {
304N/A // slow call to of thr_getspecific
304N/A // int thr_getspecific(thread_key_t key, void **value);
304N/A // Consider using pthread_getspecific instead.
304N/A
304N/A if (thread != rax) {
304N/A__ push(rax);
0N/A }
304N/A__ push(0); // space for return value
304N/A__ push(rdi);
304N/A__ push(rsi);
304N/A__ lea(rsi, Address(rsp, 16)); // pass return value address
304N/A__ push(rdx);
304N/A__ push(rcx);
304N/A__ push(r8);
304N/A__ push(r9);
304N/A__ push(r10);
304N/A // XXX
304N/A__ mov(r10, rsp);
304N/A__ andptr(rsp, -16);
304N/A__ push(r10);
304N/A__ push(r11);
304N/A
304N/A__ movl(rdi, ThreadLocalStorage::thread_index());
304N/A__ call(RuntimeAddress(CAST_FROM_FN_PTR(address, thr_getspecific)));
304N/A
304N/A__ pop(r11);
304N/A__ pop(rsp);
304N/A__ pop(r10);
304N/A__ pop(r9);
304N/A__ pop(r8);
304N/A__ pop(rcx);
304N/A__ pop(rdx);
304N/A__ pop(rsi);
304N/A__ pop(rdi);
304N/A__ pop(thread); // load return value
304N/A if (thread != rax) {
304N/A__ pop(rax);
304N/A }
0N/A}
304N/A#endif //LP64
304N/A
304N/Avoid MacroAssembler::get_thread(Register thread) {
304N/A
304N/A int segment = NOT_LP64(Assembler::GS_segment) LP64_ONLY(Assembler::FS_segment);
304N/A // Try to emit a Solaris-specific fast TSD/TLS accessor.
304N/A ThreadLocalStorage::pd_tlsAccessMode tlsMode = ThreadLocalStorage::pd_getTlsAccessMode ();
304N/A if (tlsMode == ThreadLocalStorage::pd_tlsAccessIndirect) { // T1
304N/A // Use thread as a temporary: mov r, gs:[0]; mov r, [r+tlsOffset]
304N/A emit_byte (segment);
304N/A // ExternalAddress doesn't work because it can't take NULL
304N/A AddressLiteral null(0, relocInfo::none);
304N/A movptr (thread, null);
304N/A movptr(thread, Address(thread, ThreadLocalStorage::pd_getTlsOffset())) ;
304N/A return ;
304N/A } else
304N/A if (tlsMode == ThreadLocalStorage::pd_tlsAccessDirect) { // T2
304N/A // mov r, gs:[tlsOffset]
304N/A emit_byte (segment);
304N/A AddressLiteral tls_off((address)ThreadLocalStorage::pd_getTlsOffset(), relocInfo::none);
304N/A movptr (thread, tls_off);
304N/A return ;
304N/A }
304N/A
304N/A slow_call_thr_specific(this, thread);
304N/A
304N/A}