thr_inlines.h revision ae115bc77f6fcde83175c75b4206dc2e50747966
0ec5755428223b8105e488e8fddc19de4db26521raf/*
0ec5755428223b8105e488e8fddc19de4db26521raf * CDDL HEADER START
0ec5755428223b8105e488e8fddc19de4db26521raf *
0ec5755428223b8105e488e8fddc19de4db26521raf * The contents of this file are subject to the terms of the
0ec5755428223b8105e488e8fddc19de4db26521raf * Common Development and Distribution License (the "License").
0ec5755428223b8105e488e8fddc19de4db26521raf * You may not use this file except in compliance with the License.
0ec5755428223b8105e488e8fddc19de4db26521raf *
0ec5755428223b8105e488e8fddc19de4db26521raf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0ec5755428223b8105e488e8fddc19de4db26521raf * or http://www.opensolaris.org/os/licensing.
0ec5755428223b8105e488e8fddc19de4db26521raf * See the License for the specific language governing permissions
0ec5755428223b8105e488e8fddc19de4db26521raf * and limitations under the License.
0ec5755428223b8105e488e8fddc19de4db26521raf *
0ec5755428223b8105e488e8fddc19de4db26521raf * When distributing Covered Code, include this CDDL HEADER in each
0ec5755428223b8105e488e8fddc19de4db26521raf * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0ec5755428223b8105e488e8fddc19de4db26521raf * If applicable, add the following below this CDDL HEADER, with the
0ec5755428223b8105e488e8fddc19de4db26521raf * fields enclosed by brackets "[]" replaced with your own identifying
0ec5755428223b8105e488e8fddc19de4db26521raf * information: Portions Copyright [yyyy] [name of copyright owner]
0ec5755428223b8105e488e8fddc19de4db26521raf *
0ec5755428223b8105e488e8fddc19de4db26521raf * CDDL HEADER END
0ec5755428223b8105e488e8fddc19de4db26521raf */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf/*
ae115bc77f6fcde83175c75b4206dc2e50747966mrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
0ec5755428223b8105e488e8fddc19de4db26521raf * Use is subject to license terms.
0ec5755428223b8105e488e8fddc19de4db26521raf */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#ifndef _THR_INLINES_H
0ec5755428223b8105e488e8fddc19de4db26521raf#define _THR_INLINES_H
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#pragma ident "%Z%%M% %I% %E% SMI"
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#if !defined(__lint) && defined(__GNUC__)
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf/* inlines for gcc */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ ulwp_t *
0ec5755428223b8105e488e8fddc19de4db26521raf_curthread(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__amd64)
0ec5755428223b8105e488e8fddc19de4db26521raf ulwp_t *__value;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__("movq %%fs:0, %0" : "=r" (__value));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__i386)
0ec5755428223b8105e488e8fddc19de4db26521raf ulwp_t *__value;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__("movl %%gs:0, %0" : "=r" (__value));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf register ulwp_t *__value __asm__("g7");
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ ulwp_t *
0ec5755428223b8105e488e8fddc19de4db26521raf__curthread(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf ulwp_t *__value;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__amd64)
0ec5755428223b8105e488e8fddc19de4db26521raf "movq %%fs:0, %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__i386)
0ec5755428223b8105e488e8fddc19de4db26521raf "movl %%gs:0, %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparcv9)
0ec5755428223b8105e488e8fddc19de4db26521raf ".register %%g7, #scratch\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "ldx [%%g7 + 80], %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf ".register %%g7, #scratch\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "ld [%%g7 + 80], %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf "1:"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=r" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : : "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ greg_t
0ec5755428223b8105e488e8fddc19de4db26521rafstkptr(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__amd64)
0ec5755428223b8105e488e8fddc19de4db26521raf register greg_t __value __asm__("rsp");
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__i386)
0ec5755428223b8105e488e8fddc19de4db26521raf register greg_t __value __asm__("esp");
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf register greg_t __value __asm__("sp");
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ hrtime_t
0ec5755428223b8105e488e8fddc19de4db26521rafgethrtime(void) /* note: caller-saved registers are trashed */
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__amd64)
0ec5755428223b8105e488e8fddc19de4db26521raf hrtime_t __value;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "movl $3, %%eax\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "int $0xd2"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=a" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__i386)
0ec5755428223b8105e488e8fddc19de4db26521raf hrtime_t __value;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "movl $3, %%eax\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "int $0xd2"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=A" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : : "ecx", "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparcv9)
0ec5755428223b8105e488e8fddc19de4db26521raf register hrtime_t __value __asm__("o0");
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ta 0x24\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "sllx %%o0, 32, %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "or %%o1, %0, %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=r" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : : "o1", "o2", "o3", "o4", "o5", "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf register hrtime_t __value __asm__("o0");
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ta 0x24"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=r" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : : "o2", "o3", "o4", "o5", "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ int
0ec5755428223b8105e488e8fddc19de4db26521rafset_lock_byte(volatile uint8_t *__lockp)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf int __value;
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "movl $1, %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "xchgb %%dl, %1"
0ec5755428223b8105e488e8fddc19de4db26521raf : "+d" (__value), "+m" (*__lockp));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ldstub %1, %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "membar #LoadLoad"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=r" (__value), "+m" (*__lockp));
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ uint32_t
0ec5755428223b8105e488e8fddc19de4db26521rafswap32(volatile uint32_t *__memory, uint32_t __value)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "xchgl %0, %1"
0ec5755428223b8105e488e8fddc19de4db26521raf : "+q" (__value), "+m" (*__memory));
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf uint32_t __tmp1, __tmp2;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ld [%3], %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "1:\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "mov %4, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cas [%3], %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cmp %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "bne,a,pn %%icc, 1b\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf " mov %1, %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf : "r" (__memory), "r" (__value)
0ec5755428223b8105e488e8fddc19de4db26521raf : "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf return (__tmp2);
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ uint32_t
0ec5755428223b8105e488e8fddc19de4db26521rafcas32(volatile uint32_t *__memory, uint32_t __cmp, uint32_t __newvalue)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf uint32_t __oldvalue;
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "lock; cmpxchgl %3, %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=m" (*__memory), "=a" (__oldvalue)
0ec5755428223b8105e488e8fddc19de4db26521raf : "a" (__cmp), "r" (__newvalue));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "cas [%2], %3, %1"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=m" (*__memory), "+r" (__oldvalue)
0ec5755428223b8105e488e8fddc19de4db26521raf : "r" (__memory), "r" (__cmp), "1" (__newvalue));
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf return (__oldvalue);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ void
0ec5755428223b8105e488e8fddc19de4db26521rafincr32(volatile uint32_t *__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "lock; incl %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "+m" (*__memory));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf uint32_t __tmp1, __tmp2;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ld [%3], %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "1:\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "add %0, 1, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cas [%3], %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cmp %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "bne,a,pn %%icc, 1b\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf " mov %1, %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf : "r" (__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf : "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ void
0ec5755428223b8105e488e8fddc19de4db26521rafdecr32(volatile uint32_t *__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86)
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "lock; decl %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "+m" (*__memory));
0ec5755428223b8105e488e8fddc19de4db26521raf#elif defined(__sparc)
0ec5755428223b8105e488e8fddc19de4db26521raf uint32_t __tmp1, __tmp2;
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__(
0ec5755428223b8105e488e8fddc19de4db26521raf "ld [%3], %0\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "1:\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "sub %0, 1, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cas [%3], %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "cmp %0, %1\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf "bne,a,pn %%icc, 1b\n\t"
0ec5755428223b8105e488e8fddc19de4db26521raf " mov %1, %0"
0ec5755428223b8105e488e8fddc19de4db26521raf : "=&r" (__tmp1), "=&r" (__tmp2), "=m" (*__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf : "r" (__memory)
0ec5755428223b8105e488e8fddc19de4db26521raf : "cc");
0ec5755428223b8105e488e8fddc19de4db26521raf#else
0ec5755428223b8105e488e8fddc19de4db26521raf#error "port me"
0ec5755428223b8105e488e8fddc19de4db26521raf#endif
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__sparc) /* only needed on sparc */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ ulong_t
0ec5755428223b8105e488e8fddc19de4db26521rafcaller(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf register ulong_t __value __asm__("i7");
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ ulong_t
0ec5755428223b8105e488e8fddc19de4db26521rafgetfp(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf register ulong_t __value __asm__("fp");
0ec5755428223b8105e488e8fddc19de4db26521raf return (__value);
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#endif /* __sparc */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#if defined(__x86) /* only needed on x86 */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521rafextern __inline__ void
0ec5755428223b8105e488e8fddc19de4db26521rafht_pause(void)
0ec5755428223b8105e488e8fddc19de4db26521raf{
0ec5755428223b8105e488e8fddc19de4db26521raf __asm__ __volatile__("rep; nop");
0ec5755428223b8105e488e8fddc19de4db26521raf}
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#endif /* __x86 */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#endif /* !__lint && __GNUC__ */
0ec5755428223b8105e488e8fddc19de4db26521raf
0ec5755428223b8105e488e8fddc19de4db26521raf#endif /* _THR_INLINES_H */