assembler_linux_x86.cpp revision 1879:f95d63e2154a
1218822Sdim/*
2130561Sobrien * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
333965Sjdp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4130561Sobrien *
5218822Sdim * This code is free software; you can redistribute it and/or modify it
638889Sjdp * under the terms of the GNU General Public License version 2 only, as
738889Sjdp * published by the Free Software Foundation.
838889Sjdp *
933965Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT
1038889Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1138889Sjdp * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1238889Sjdp * version 2 for more details (a copy is included in the LICENSE file that
1338889Sjdp * accompanied this code).
1433965Sjdp *
15130561Sobrien * You should have received a copy of the GNU General Public License version
1633965Sjdp * 2 along with this work; if not, write to the Free Software Foundation,
1733965Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1838889Sjdp *
1938889Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2033965Sjdp * or visit www.oracle.com if you need additional information or have any
2138889Sjdp * questions.
2238889Sjdp *
2338889Sjdp */
2438889Sjdp
25130561Sobrien#include "precompiled.hpp"
2638889Sjdp#include "asm/assembler.hpp"
27130561Sobrien#include "assembler_x86.inline.hpp"
28130561Sobrien#include "runtime/os.hpp"
29130561Sobrien#include "runtime/threadLocalStorage.hpp"
30130561Sobrien
31130561Sobrien#ifndef _LP64
3238889Sjdpvoid MacroAssembler::int3() {
3338889Sjdp  call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
3438889Sjdp}
3538889Sjdp
3638889Sjdpvoid MacroAssembler::get_thread(Register thread) {
3738889Sjdp  movl(thread, rsp);
3838889Sjdp  shrl(thread, PAGE_SHIFT);
3938889Sjdp
4038889Sjdp  ExternalAddress tls_base((address)ThreadLocalStorage::sp_map_addr());
41130561Sobrien  Address index(noreg, thread, Address::times_4);
42130561Sobrien  ArrayAddress tls(tls_base, index);
43130561Sobrien
44130561Sobrien  movptr(thread, tls);
45130561Sobrien}
46130561Sobrien#else
47130561Sobrienvoid MacroAssembler::int3() {
48218822Sdim  call(RuntimeAddress(CAST_FROM_FN_PTR(address, os::breakpoint)));
49218822Sdim}
50218822Sdim
51218822Sdimvoid MacroAssembler::get_thread(Register thread) {
52130561Sobrien  // call pthread_getspecific
53130561Sobrien  // void * pthread_getspecific(pthread_key_t key);
54218822Sdim   if (thread != rax) {
55218822Sdim     push(rax);
56218822Sdim   }
57218822Sdim   push(rdi);
58218822Sdim   push(rsi);
59218822Sdim   push(rdx);
60218822Sdim   push(rcx);
61218822Sdim   push(r8);
62218822Sdim   push(r9);
63218822Sdim   push(r10);
64130561Sobrien   // XXX
65130561Sobrien   mov(r10, rsp);
66130561Sobrien   andq(rsp, -16);
67130561Sobrien   push(r10);
68130561Sobrien   push(r11);
69130561Sobrien
70130561Sobrien   movl(rdi, ThreadLocalStorage::thread_index());
71130561Sobrien   call(RuntimeAddress(CAST_FROM_FN_PTR(address, pthread_getspecific)));
72130561Sobrien
73218822Sdim   pop(r11);
74218822Sdim   pop(rsp);
75218822Sdim   pop(r10);
76218822Sdim   pop(r9);
77218822Sdim   pop(r8);
78218822Sdim   pop(rcx);
79218822Sdim   pop(rdx);
80218822Sdim   pop(rsi);
81218822Sdim   pop(rdi);
82130561Sobrien   if (thread != rax) {
83130561Sobrien       mov(thread, rax);
84130561Sobrien       pop(rax);
85130561Sobrien   }
86130561Sobrien}
87130561Sobrien#endif
88218822Sdim