xref: /illumos-gate/usr/src/lib/libc/i386/threads/tls_get_addr.S (revision 201ceb75ab95f9bf1f42ea1dc9ab363b43ba47cf)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26	.file	"tls_get_addr.s"
27
28/*
29 * To make thread-local storage accesses as fast as possible, we
30 * hand-craft the __tls_get_addr() function below, from this C code:
31 * void *
32 * __tls_get_addr(TLS_index *tls_index)
33 * {
34 *	ulwp_t *self = curthread;
35 *	tls_t *tlsent = self->ul_tlsent;
36 *	ulong_t moduleid;
37 *	caddr_t	base;
38 *
39 *	if ((moduleid = tls_index->ti_moduleid) < self->ul_ntlsent &&
40 *	    (base = tlsent[moduleid].tls_data) != NULL)
41 *		return (base + tls_index->ti_tlsoffset);
42 *
43 *	return (slow_tls_get_addr(tls_index));
44 * }
45 *
46 * ___tls_get_addr() is identical to __tls_get_addr() except that it
47 * assumes its argument is passed in %eax rather than on the stack.
48 */
49
50#include "SYS.h"
51#include <assym.h>
52
53	ENTRY_NP(__tls_get_addr)
54	movl	4(%esp), %eax
55	ALTENTRY(___tls_get_addr)
56	movl	%gs:UL_TLSENT, %edx
57	movl	TI_MODULEID (%eax), %ecx
58	cmpl	%gs:UL_NTLSENT, %ecx
59	jae	1f
60	movl	TLS_DATA (%edx,%ecx,SIZEOF_TLS_T), %edx
61	testl	%edx, %edx
62	je	1f
63	addl	TI_TLSOFFSET (%eax), %edx
64	movl	%edx, %eax
65	ret
661:
67	pushl	%ebp
68	movl	%esp, %ebp
69	pushl	%eax
70	call	slow_tls_get_addr
71	addl	$4, %esp
72	leave
73	ret
74	SET_SIZE(___tls_get_addr)
75	SET_SIZE(__tls_get_addr)
76