atomic.h (216524) | atomic.h (220404) |
---|---|
1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/i386/include/atomic.h 216524 2010-12-18 16:41:11Z kib $ | 26 * $FreeBSD: head/sys/i386/include/atomic.h 220404 2011-04-06 23:59:59Z jkim $ |
27 */ 28#ifndef _MACHINE_ATOMIC_H_ 29#define _MACHINE_ATOMIC_H_ 30 31#ifndef _SYS_CDEFS_H_ 32#error this file needs sys/cdefs.h as a prerequisite 33#endif 34 --- 80 unchanged lines hidden (view full) --- 115{ \ 116 __asm __volatile(MPLOCKED OP \ 117 : "=m" (*p) \ 118 : CONS (V), "m" (*p) \ 119 : "memory", "cc"); \ 120} \ 121struct __hack 122 | 27 */ 28#ifndef _MACHINE_ATOMIC_H_ 29#define _MACHINE_ATOMIC_H_ 30 31#ifndef _SYS_CDEFS_H_ 32#error this file needs sys/cdefs.h as a prerequisite 33#endif 34 --- 80 unchanged lines hidden (view full) --- 115{ \ 116 __asm __volatile(MPLOCKED OP \ 117 : "=m" (*p) \ 118 : CONS (V), "m" (*p) \ 119 : "memory", "cc"); \ 120} \ 121struct __hack 122 |
123#if defined(_KERNEL) && !defined(WANT_FUNCTIONS) 124 125/* I486 does not support SMP or CMPXCHG8B. */ 126static __inline uint64_t 127atomic_load_acq_64_i386(volatile uint64_t *p) 128{ 129 volatile uint32_t *high, *low; 130 uint64_t res; 131 132 low = (volatile uint32_t *)p; 133 high = (volatile uint32_t *)p + 1; 134 __asm __volatile( 135 " pushfl ; " 136 " cli ; " 137 " movl %1,%%eax ; " 138 " movl %2,%%edx ; " 139 " popfl" 140 : "=&A" (res) /* 0 */ 141 : "m" (*low), /* 1 */ 142 "m" (*high) /* 2 */ 143 : "memory"); 144 145 return (res); 146} 147 148static __inline void 149atomic_store_rel_64_i386(volatile uint64_t *p, uint64_t v) 150{ 151 volatile uint32_t *high, *low; 152 153 low = (volatile uint32_t *)p; 154 high = (volatile uint32_t *)p + 1; 155 __asm __volatile( 156 " pushfl ; " 157 " cli ; " 158 " movl %%eax,%0 ; " 159 " movl %%edx,%1 ; " 160 " popfl" 161 : "=m" (*low), /* 0 */ 162 "=m" (*high) /* 1 */ 163 : "A" (v) /* 2 */ 164 : "memory"); 165} 166 167static __inline uint64_t 168atomic_load_acq_64_i586(volatile uint64_t *p) 169{ 170 uint64_t res; 171 172 __asm __volatile( 173 " movl %%ebx,%%eax ; " 174 " movl %%ecx,%%edx ; " 175 " " MPLOCKED " " 176 " cmpxchg8b %2" 177 : "=&A" (res), /* 0 */ 178 "=m" (*p) /* 1 */ 179 : "m" (*p) /* 2 */ 180 : "memory", "cc"); 181 182 return (res); 183} 184 185static __inline void 186atomic_store_rel_64_i586(volatile uint64_t *p, uint64_t v) 187{ 188 189 __asm __volatile( 190 " movl %%eax,%%ebx ; " 191 " movl %%edx,%%ecx ; " 192 "1: " 193 " " MPLOCKED " " 194 " cmpxchg8b %2 ; " 195 " jne 1b" 196 : "=m" (*p), /* 0 */ 197 "+A" (v) /* 1 */ 198 : "m" (*p) /* 2 */ 199 : "ebx", "ecx", "memory", "cc"); 200} 201 202#endif /* _KERNEL && !WANT_FUNCTIONS */ 203 |
|
123/* 124 * Atomic compare and set, used by the mutex functions 125 * 126 * if (*dst == expect) *dst = src (all 32 bit words) 127 * 128 * Returns 0 on failure, non-zero on success 129 */ 130 --- 156 unchanged lines hidden (view full) --- 287ATOMIC_STORE_LOAD(int, "cmpxchgl %0,%1", "xchgl %1,%0"); 288ATOMIC_STORE_LOAD(long, "cmpxchgl %0,%1", "xchgl %1,%0"); 289 290#undef ATOMIC_ASM 291#undef ATOMIC_STORE_LOAD 292 293#ifndef WANT_FUNCTIONS 294 | 204/* 205 * Atomic compare and set, used by the mutex functions 206 * 207 * if (*dst == expect) *dst = src (all 32 bit words) 208 * 209 * Returns 0 on failure, non-zero on success 210 */ 211 --- 156 unchanged lines hidden (view full) --- 368ATOMIC_STORE_LOAD(int, "cmpxchgl %0,%1", "xchgl %1,%0"); 369ATOMIC_STORE_LOAD(long, "cmpxchgl %0,%1", "xchgl %1,%0"); 370 371#undef ATOMIC_ASM 372#undef ATOMIC_STORE_LOAD 373 374#ifndef WANT_FUNCTIONS 375 |
376#ifdef _KERNEL 377extern uint64_t (*atomic_load_acq_64)(volatile uint64_t *); 378extern void (*atomic_store_rel_64)(volatile uint64_t *, uint64_t); 379#endif 380 |
|
295static __inline int 296atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src) 297{ 298 299 return (atomic_cmpset_int((volatile u_int *)dst, (u_int)expect, 300 (u_int)src)); 301} 302 --- 185 unchanged lines hidden --- | 381static __inline int 382atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src) 383{ 384 385 return (atomic_cmpset_int((volatile u_int *)dst, (u_int)expect, 386 (u_int)src)); 387} 388 --- 185 unchanged lines hidden --- |