]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/X64/machine/atomic.h
StdLib: Remove EfiSocketLib and Ip4Config Protocol dependency.
[mirror_edk2.git] / StdLib / Include / X64 / machine / atomic.h
CommitLineData
2aa62f2b 1/* $NetBSD: atomic.h,v 1.4 2005/12/28 19:09:29 perry Exp $ */\r
2\r
3/*\r
4 * Copyright 2002 (c) Wasabi Systems, Inc.\r
5 * All rights reserved.\r
6 *\r
7 * Written by Frank van der Linden for Wasabi Systems, Inc.\r
8 *\r
9 * Redistribution and use in source and binary forms, with or without\r
10 * modification, are permitted provided that the following conditions\r
11 * are met:\r
12 * 1. Redistributions of source code must retain the above copyright\r
13 * notice, this list of conditions and the following disclaimer.\r
14 * 2. Redistributions in binary form must reproduce the above copyright\r
15 * notice, this list of conditions and the following disclaimer in the\r
16 * documentation and/or other materials provided with the distribution.\r
17 * 3. All advertising materials mentioning features or use of this software\r
18 * must display the following acknowledgement:\r
19 * This product includes software developed for the NetBSD Project by\r
20 * Wasabi Systems, Inc.\r
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse\r
22 * or promote products derived from this software without specific prior\r
23 * written permission.\r
24 *\r
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND\r
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC\r
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
35 * POSSIBILITY OF SUCH DAMAGE.\r
36 */\r
37\r
38#ifndef _ATOMIC_H\r
39#define _ATOMIC_H\r
40\r
41#ifndef _LOCORE\r
42\r
43static __inline u_int64_t\r
44x86_atomic_testset_u64(volatile u_int64_t *ptr, u_int64_t val) {\r
45 __asm volatile ("xchgq %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
46 return val;\r
47}\r
48\r
49static __inline u_int32_t\r
50x86_atomic_testset_u32(volatile u_int32_t *ptr, u_int32_t val) {\r
51 __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
52 return val;\r
53}\r
54\r
55\r
56\r
57static __inline int32_t\r
58x86_atomic_testset_i32(volatile int32_t *ptr, int32_t val) {\r
59 __asm volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr));\r
60 return val;\r
61}\r
62\r
63\r
64\r
65static __inline void\r
66x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {\r
67 __asm volatile("lock ; orl %1,%0" : "=m" (*ptr) : "ir" (bits));\r
68}\r
69\r
70static __inline void\r
71x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) {\r
72 __asm volatile("lock ; andl %1,%0" : "=m" (*ptr) : "ir" (~bits));\r
73}\r
74\r
75\r
76\r
77static __inline void\r
78x86_atomic_setbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {\r
79 __asm volatile("lock ; orq %1,%0" : "=m" (*ptr) : "ir" (~bits));\r
80}\r
81\r
82static __inline void\r
83x86_atomic_clearbits_u64(volatile u_int64_t *ptr, u_int64_t bits) {\r
84 __asm volatile("lock ; andq %1,%0" : "=m" (*ptr) : "ir" (~bits));\r
85}\r
86\r
87#define x86_atomic_testset_ul x86_atomic_testset_u32\r
88#define x86_atomic_testset_i x86_atomic_testset_i32\r
89#define x86_atomic_setbits_l x86_atomic_setbits_u32\r
90#define x86_atomic_setbits_ul x86_atomic_setbits_u32\r
91#define x86_atomic_clearbits_l x86_atomic_clearbits_u32\r
92#define x86_atomic_clearbits_ul x86_atomic_clearbits_u32\r
93\r
94#endif\r
95#endif\r