1 /* 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/macroAssembler.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "runtime/os.hpp" 29 #include "runtime/threadLocalStorage.hpp" 30 31 32 // get_thread can be called anywhere inside generated code so we need 33 // to save whatever non-callee save context might get clobbered by the 34 // call to the C thread_local lookup call or, indeed, the call setup 35 // code. x86 appears to save C arg registers. 36 37 void MacroAssembler::get_thread(Register dst) { 38 // call pthread_getspecific 39 // void * pthread_getspecific(pthread_key_t key); 40 41 // Save all call-clobbered regs except dst, plus r19 and r20. 42 RegSet saved_regs = RegSet::range(r0, r20) + lr - dst; 43 push(saved_regs, sp); 44 mov(c_rarg0, ThreadLocalStorage::thread_index()); 45 mov(r19, CAST_FROM_FN_PTR(address, pthread_getspecific)); 46 blr(r19); 47 if (dst != c_rarg0) { 48 mov(dst, c_rarg0); 49 } 50 // restore pushed registers 51 pop(saved_regs, sp); 52 } 53