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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #ifndef _THR_INLINES_H
28 #define _THR_INLINES_H
29
30 #include <sys/ccompile.h>
31
32 #if !defined(__lint) && defined(__GNUC__)
33
34 /* inlines for gcc */
35
36 /*
37 * ON-usable GCC 4.x emits register pseudo-ops declaring %g7 as ignored, rather
38 * than scratch, GCC 3 does the reverse. All uses, both ones it generated
39 * (_curthread) and ones it didn't (__curthread) must agree.
40 */
41 #if __GNUC__ > 3
42 #define SPARC_REG_SPEC "#ignore"
43 #else
44 #define SPARC_REG_SPEC "#scratch"
45 #endif
46
121 "ta 0x24\n\t"
122 "sllx %%o0, 32, %0\n\t"
123 "or %%o1, %0, %0"
124 : "=r" (__value)
125 : : "o1", "o2", "o3", "o4", "o5", "cc");
126 #elif defined(__sparc)
127 register hrtime_t __value __asm__("o0");
128 __asm__ __volatile__(
129 "ta 0x24"
130 : "=r" (__value)
131 : : "o2", "o3", "o4", "o5", "cc");
132 #else
133 #error "port me"
134 #endif
135 return (__value);
136 }
137
138 extern __GNU_INLINE int
139 set_lock_byte(volatile uint8_t *__lockp)
140 {
141 int __value;
142 #if defined(__x86)
143 __asm__ __volatile__(
144 "movl $1, %0\n\t"
145 "xchgb %%dl, %1"
146 : "+d" (__value), "+m" (*__lockp));
147 #elif defined(__sparc)
148 __asm__ __volatile__(
149 "ldstub %1, %0\n\t"
150 "membar #LoadLoad"
151 : "=r" (__value), "+m" (*__lockp));
152 #else
153 #error "port me"
154 #endif
155 return (__value);
156 }
157
158 extern __GNU_INLINE uint32_t
159 atomic_swap_32(volatile uint32_t *__memory, uint32_t __value)
160 {
161 #if defined(__x86)
|
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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * Copyright 2019 Joyent, Inc.
29 */
30
31 #ifndef _THR_INLINES_H
32 #define _THR_INLINES_H
33
34 #include <sys/ccompile.h>
35
36 #if !defined(__lint) && defined(__GNUC__)
37
38 /* inlines for gcc */
39
40 /*
41 * ON-usable GCC 4.x emits register pseudo-ops declaring %g7 as ignored, rather
42 * than scratch, GCC 3 does the reverse. All uses, both ones it generated
43 * (_curthread) and ones it didn't (__curthread) must agree.
44 */
45 #if __GNUC__ > 3
46 #define SPARC_REG_SPEC "#ignore"
47 #else
48 #define SPARC_REG_SPEC "#scratch"
49 #endif
50
125 "ta 0x24\n\t"
126 "sllx %%o0, 32, %0\n\t"
127 "or %%o1, %0, %0"
128 : "=r" (__value)
129 : : "o1", "o2", "o3", "o4", "o5", "cc");
130 #elif defined(__sparc)
131 register hrtime_t __value __asm__("o0");
132 __asm__ __volatile__(
133 "ta 0x24"
134 : "=r" (__value)
135 : : "o2", "o3", "o4", "o5", "cc");
136 #else
137 #error "port me"
138 #endif
139 return (__value);
140 }
141
142 extern __GNU_INLINE int
143 set_lock_byte(volatile uint8_t *__lockp)
144 {
145 int __value = 0;
146 #if defined(__x86)
147 __asm__ __volatile__(
148 "movl $1, %0\n\t"
149 "xchgb %%dl, %1"
150 : "+d" (__value), "+m" (*__lockp));
151 #elif defined(__sparc)
152 __asm__ __volatile__(
153 "ldstub %1, %0\n\t"
154 "membar #LoadLoad"
155 : "=r" (__value), "+m" (*__lockp));
156 #else
157 #error "port me"
158 #endif
159 return (__value);
160 }
161
162 extern __GNU_INLINE uint32_t
163 atomic_swap_32(volatile uint32_t *__memory, uint32_t __value)
164 {
165 #if defined(__x86)
|