thr_inlines.h revision 41efec2219526a9b3ecce26f97aba761ef1e1d0d
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _THR_INLINES_H
#define _THR_INLINES_H
#pragma ident "%Z%%M% %I% %E% SMI"
/* inlines for gcc */
extern __inline__ ulwp_t *
_curthread(void)
{
#if defined(__amd64)
#else
#error "port me"
#endif
return (__value);
}
extern __inline__ ulwp_t *
__curthread(void)
{
#if defined(__amd64)
"movq %%fs:0, %0\n\t"
"movl %%gs:0, %0\n\t"
".register %%g7, #scratch\n\t"
"ldx [%%g7 + 80], %0\n\t"
".register %%g7, #scratch\n\t"
"ld [%%g7 + 80], %0\n\t"
#else
#error "port me"
#endif
"1:"
: "=r" (__value)
: : "cc");
return (__value);
}
extern __inline__ greg_t
stkptr(void)
{
#if defined(__amd64)
#else
#error "port me"
#endif
return (__value);
}
extern __inline__ hrtime_t
gethrtime(void) /* note: caller-saved registers are trashed */
{
#if defined(__amd64)
"movl $3, %%eax\n\t"
"int $0xd2"
: "=a" (__value)
: : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "cc");
"movl $3, %%eax\n\t"
"int $0xd2"
: "=A" (__value)
: : "ecx", "cc");
"ta 0x24\n\t"
"sllx %%o0, 32, %0\n\t"
"or %%o1, %0, %0"
: "=r" (__value)
: : "o1", "o2", "o3", "o4", "o5", "cc");
"ta 0x24"
: "=r" (__value)
: : "o2", "o3", "o4", "o5", "cc");
#else
#error "port me"
#endif
return (__value);
}
extern __inline__ int
{
int __value;
#if defined(__x86)
"movl $1, %0\n\t"
"xchgb %%dl, %1"
"ldstub %1, %0\n\t"
"membar #LoadLoad"
#else
#error "port me"
#endif
return (__value);
}
extern __inline__ uint32_t
{
#if defined(__x86)
"xchgl %0, %1"
return (__value);
"ld [%3], %0\n\t"
"1:\n\t"
"mov %4, %1\n\t"
"cas [%3], %0, %1\n\t"
"cmp %0, %1\n\t"
"bne,a,pn %%icc, 1b\n\t"
" mov %1, %0"
: "cc");
return (__tmp2);
#else
#error "port me"
#endif
}
extern __inline__ uint32_t
{
#if defined(__x86)
"lock; cmpxchgl %3, %0"
"cas [%2], %3, %1"
#else
#error "port me"
#endif
return (__oldvalue);
}
extern __inline__ void
{
#if defined(__x86)
"lock; incl %0"
: "+m" (*__memory));
"ld [%3], %0\n\t"
"1:\n\t"
"add %0, 1, %1\n\t"
"cas [%3], %0, %1\n\t"
"cmp %0, %1\n\t"
"bne,a,pn %%icc, 1b\n\t"
" mov %1, %0"
: "r" (__memory)
: "cc");
#else
#error "port me"
#endif
}
extern __inline__ void
{
#if defined(__x86)
"lock; decl %0"
: "+m" (*__memory));
"ld [%3], %0\n\t"
"1:\n\t"
"sub %0, 1, %1\n\t"
"cas [%3], %0, %1\n\t"
"cmp %0, %1\n\t"
"bne,a,pn %%icc, 1b\n\t"
" mov %1, %0"
: "r" (__memory)
: "cc");
#else
#error "port me"
#endif
}
extern __inline__ void
{
#if defined(__x86)
"lock; andl %1, %0"
: "+m" (*__memory)
: "r" (__bits));
"ld [%3], %0\n\t"
"1:\n\t"
"and %0, %4, %1\n\t"
"cas [%3], %0, %1\n\t"
"cmp %0, %1\n\t"
"bne,a,pn %%icc, 1b\n\t"
" mov %1, %0"
: "cc");
#else
#error "port me"
#endif
}
extern __inline__ void
{
#if defined(__x86)
"lock; orl %1, %0"
: "+m" (*__memory)
: "r" (__bits));
"ld [%3], %0\n\t"
"1:\n\t"
"or %0, %4, %1\n\t"
"cas [%3], %0, %1\n\t"
"cmp %0, %1\n\t"
"bne,a,pn %%icc, 1b\n\t"
" mov %1, %0"
: "cc");
#else
#error "port me"
#endif
}
#if defined(__sparc) /* only needed on sparc */
extern __inline__ ulong_t
caller(void)
{
return (__value);
}
extern __inline__ ulong_t
getfp(void)
{
return (__value);
}
#endif /* __sparc */
#if defined(__x86) /* only needed on x86 */
extern __inline__ void
ht_pause(void)
{
}
#endif /* __x86 */
#endif /* !__lint && __GNUC__ */
#endif /* _THR_INLINES_H */