10Sstevel@tonic-gate/* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56812Sraf * Common Development and Distribution License (the "License"). 66812Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 216812Sraf 220Sstevel@tonic-gate/* 236812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 27*7298SMark.J.Nelson@Sun.COM .file "tls_get_addr.s" 280Sstevel@tonic-gate 296812Sraf#include "SYS.h" 300Sstevel@tonic-gate#include <../assym.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate/* 330Sstevel@tonic-gate * To make thread-local storage accesses as fast as possible, we 340Sstevel@tonic-gate * hand-craft the __tls_get_addr() function below, from this C code: 350Sstevel@tonic-gate * void * 360Sstevel@tonic-gate * __tls_get_addr(TLS_index *tls_index) 370Sstevel@tonic-gate * { 380Sstevel@tonic-gate * ulwp_t *self = curthread; 390Sstevel@tonic-gate * tls_t *tlsent = self->ul_tlsent; 400Sstevel@tonic-gate * ulong_t moduleid; 410Sstevel@tonic-gate * caddr_t base; 420Sstevel@tonic-gate * 430Sstevel@tonic-gate * if ((moduleid = tls_index->ti_moduleid) < self->ul_ntlsent && 440Sstevel@tonic-gate * (base = tlsent[moduleid].tls_data) != NULL) 450Sstevel@tonic-gate * return (base + tls_index->ti_tlsoffset); 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * return (slow_tls_get_addr(tls_index)); 480Sstevel@tonic-gate * } 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate 510Sstevel@tonic-gate/* 520Sstevel@tonic-gate * We assume that the tls_t structure contains two pointer-sized elements. 530Sstevel@tonic-gate * Cause a build failure if this becomes not true. 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate#if SIZEOF_TLS_T == 8 && !defined(__sparcv9) 560Sstevel@tonic-gate#define SHIFT 3 570Sstevel@tonic-gate#elif SIZEOF_TLS_T == 16 && defined(__sparcv9) 580Sstevel@tonic-gate#define SHIFT 4 590Sstevel@tonic-gate#else 600Sstevel@tonic-gate#error "Assumption violated: SIZEOF_TLS_T is not 2 * sizeof (uintptr_t)" 610Sstevel@tonic-gate#endif 620Sstevel@tonic-gate 630Sstevel@tonic-gate#if defined(__sparcv9) 640Sstevel@tonic-gate#define PN ,pn %xcc, 650Sstevel@tonic-gate#else 660Sstevel@tonic-gate#define PN 670Sstevel@tonic-gate#endif 680Sstevel@tonic-gate 690Sstevel@tonic-gate ENTRY(__tls_get_addr) 700Sstevel@tonic-gate ldn [%o0 + TI_MODULEID], %o1 710Sstevel@tonic-gate ldn [%g7 + UL_TLSENT], %o2 720Sstevel@tonic-gate ldn [%g7 + UL_NTLSENT], %o3 730Sstevel@tonic-gate cmp %o1, %o3 740Sstevel@tonic-gate bgeu PN 1f 750Sstevel@tonic-gate slln %o1, SHIFT, %o1 760Sstevel@tonic-gate#if TLS_DATA != 0 770Sstevel@tonic-gate add %o1, TLS_DATA, %o1 780Sstevel@tonic-gate#endif 790Sstevel@tonic-gate ldn [%o1 + %o2], %o2 800Sstevel@tonic-gate cmp %o2, 0 810Sstevel@tonic-gate be PN 1f 820Sstevel@tonic-gate ldn [%o0 + TI_TLSOFFSET], %o1 830Sstevel@tonic-gate retl 840Sstevel@tonic-gate add %o1, %o2, %o0 850Sstevel@tonic-gate1: 860Sstevel@tonic-gate mov %o7, %g1 870Sstevel@tonic-gate call slow_tls_get_addr 880Sstevel@tonic-gate mov %g1, %o7 890Sstevel@tonic-gate SET_SIZE(__tls_get_addr) 90