]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/bit_routines.h
2 * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (C) 1998 Apple Computer
36 * Mach Operating System
37 * Copyright (c) 1991,1990 Carnegie Mellon University
38 * All Rights Reserved.
40 * Permission to use, copy, modify and distribute this software and its
41 * documentation is hereby granted, provided that both the copyright
42 * notice and this permission notice appear in all copies of the
43 * software, derivative works or modified versions, and any portions
44 * thereof, and that both notices appear in supporting documentation.
46 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
47 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
48 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
50 * Carnegie Mellon requests users of this software to return to
52 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
53 * School of Computer Science
54 * Carnegie Mellon University
55 * Pittsburgh PA 15213-3890
57 * any improvements or extensions that they make and grant Carnegie Mellon
58 * the rights to redistribute these changes.
62 * Bit-mask manipulation routines
65 #ifndef _I386_BIT_ROUTINES_H_
66 #define _I386_BIT_ROUTINES_H_
68 #ifdef MACH_KERNEL_PRIVATE
71 * General bit-lock routines.
74 #define bit_lock(bit,l) \
75 __asm__ volatile(" jmp 1f \n \
82 "r" (bit), "m" (*(volatile int *)(l)) : \
85 #define bit_unlock(bit,l) \
86 __asm__ volatile(" lock \n \
89 "r" (bit), "m" (*(volatile int *)(l)));
92 * Set or clear individual bits in a long word.
93 * The locked access is needed only to lock access
94 * to the word, not to individual bits.
97 #define i_bit_set(bit,l) \
98 __asm__ volatile(" lock \n \
101 "r" (bit), "m" (*(volatile int *)(l)));
103 #define i_bit_clear(bit,l) \
104 __asm__ volatile(" lock \n \
107 "r" (bit), "m" (*(volatile int *)(l)));
109 static inline char xchgb(volatile char * cp
, char new)
113 __asm__
volatile (" xchgb %0,%2" :
115 "0" (new), "m" (*(volatile char *)cp
) : "memory");
119 static inline void atomic_incl(volatile long * p
, long delta
)
121 __asm__
volatile (" lock \n \
124 "r" (delta
), "m" (*(volatile long *)p
));
127 static inline void atomic_incs(volatile short * p
, short delta
)
129 __asm__
volatile (" lock \n \
132 "q" (delta
), "m" (*(volatile short *)p
));
135 static inline void atomic_incb(volatile char * p
, char delta
)
137 __asm__
volatile (" lock \n \
140 "q" (delta
), "m" (*(volatile char *)p
));
143 static inline void atomic_decl(volatile long * p
, long delta
)
145 __asm__
volatile (" lock \n \
148 "r" (delta
), "m" (*(volatile long *)p
));
151 static inline int atomic_decl_and_test(volatile long * p
, long delta
)
159 : "r" (delta
), "m" (*(volatile long *)p
));
163 static inline void atomic_decs(volatile short * p
, short delta
)
165 __asm__
volatile (" lock \n \
168 "q" (delta
), "m" (*(volatile short *)p
));
171 static inline void atomic_decb(volatile char * p
, char delta
)
173 __asm__
volatile (" lock \n \
176 "q" (delta
), "m" (*(volatile char *)p
));
179 static inline long atomic_getl(const volatile long * p
)
184 static inline short atomic_gets(const volatile short * p
)
189 static inline char atomic_getb(const volatile char * p
)
194 static inline void atomic_setl(volatile long * p
, long value
)
199 static inline void atomic_sets(volatile short * p
, short value
)
204 static inline void atomic_setb(volatile char * p
, char value
)
209 #endif /* MACH_KERNEL_PRIVATE */
211 #endif /* _I386_BIT_ROUTINES_H_ */