]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/lock.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (C) 1998 Apple Computer
33 * Mach Operating System
34 * Copyright (c) 1991,1990 Carnegie Mellon University
35 * All Rights Reserved.
37 * Permission to use, copy, modify and distribute this software and its
38 * documentation is hereby granted, provided that both the copyright
39 * notice and this permission notice appear in all copies of the
40 * software, derivative works or modified versions, and any portions
41 * thereof, and that both notices appear in supporting documentation.
43 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
44 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
45 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
47 * Carnegie Mellon requests users of this software to return to
49 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
50 * School of Computer Science
51 * Carnegie Mellon University
52 * Pittsburgh PA 15213-3890
54 * any improvements or extensions that they make and grant Carnegie Mellon
55 * the rights to redistribute these changes.
62 * Machine-dependent simple locks for the i386.
68 #include <sys/appleapiopts.h>
70 #ifdef __APPLE_API_PRIVATE
72 #ifdef MACH_KERNEL_PRIVATE
74 #include <kern/macro_help.h>
75 #include <kern/assert.h>
76 #include <i386/hw_lock_types.h>
79 #include <mach_ldebug.h>
86 * General bit-lock routines.
89 #define bit_lock(bit,l) \
90 __asm__ volatile(" jmp 1f \n \
97 "r" (bit), "m" (*(volatile int *)(l)) : \
100 #define bit_unlock(bit,l) \
101 __asm__ volatile(" lock \n \
104 "r" (bit), "m" (*(volatile int *)(l)));
107 * Set or clear individual bits in a long word.
108 * The locked access is needed only to lock access
109 * to the word, not to individual bits.
112 #define i_bit_set(bit,l) \
113 __asm__ volatile(" lock \n \
116 "r" (bit), "m" (*(volatile int *)(l)));
118 #define i_bit_clear(bit,l) \
119 __asm__ volatile(" lock \n \
122 "r" (bit), "m" (*(volatile int *)(l)));
124 extern __inline__
unsigned long i_bit_isset(unsigned int testbit
, volatile unsigned long *word
)
128 __asm__
volatile("btl %2,%1\n\tsbbl %0,%0" : "=r" (bit
)
129 : "m" (word
), "ir" (testbit
));
133 extern __inline__
char xchgb(volatile char * cp
, char new);
135 extern __inline__
void atomic_incl(long * p
, long delta
);
136 extern __inline__
void atomic_incs(short * p
, short delta
);
137 extern __inline__
void atomic_incb(char * p
, char delta
);
139 extern __inline__
void atomic_decl(long * p
, long delta
);
140 extern __inline__
void atomic_decs(short * p
, short delta
);
141 extern __inline__
void atomic_decb(char * p
, char delta
);
143 extern __inline__
long atomic_getl(long * p
);
144 extern __inline__
short atomic_gets(short * p
);
145 extern __inline__
char atomic_getb(char * p
);
147 extern __inline__
void atomic_setl(long * p
, long value
);
148 extern __inline__
void atomic_sets(short * p
, short value
);
149 extern __inline__
void atomic_setb(char * p
, char value
);
151 extern __inline__
char xchgb(volatile char * cp
, char new)
153 register char old
= new;
155 __asm__
volatile (" xchgb %0,%2" :
157 "0" (new), "m" (*(volatile char *)cp
) : "memory");
161 extern __inline__
void atomic_incl(long * p
, long delta
)
164 __asm__
volatile (" lock \n \
167 "r" (delta
), "m" (*(volatile long *)p
));
168 #else /* NEED_ATOMIC */
170 #endif /* NEED_ATOMIC */
173 extern __inline__
void atomic_incs(short * p
, short delta
)
176 __asm__
volatile (" lock \n \
179 "q" (delta
), "m" (*(volatile short *)p
));
180 #else /* NEED_ATOMIC */
182 #endif /* NEED_ATOMIC */
185 extern __inline__
void atomic_incb(char * p
, char delta
)
188 __asm__
volatile (" lock \n \
191 "q" (delta
), "m" (*(volatile char *)p
));
192 #else /* NEED_ATOMIC */
194 #endif /* NEED_ATOMIC */
197 extern __inline__
void atomic_decl(long * p
, long delta
)
200 __asm__
volatile (" lock \n \
203 "r" (delta
), "m" (*(volatile long *)p
));
204 #else /* NCPUS > 1 */
206 #endif /* NCPUS > 1 */
209 extern __inline__
void atomic_decs(short * p
, short delta
)
212 __asm__
volatile (" lock \n \
215 "q" (delta
), "m" (*(volatile short *)p
));
216 #else /* NEED_ATOMIC */
218 #endif /* NEED_ATOMIC */
221 extern __inline__
void atomic_decb(char * p
, char delta
)
224 __asm__
volatile (" lock \n \
227 "q" (delta
), "m" (*(volatile char *)p
));
228 #else /* NEED_ATOMIC */
230 #endif /* NEED_ATOMIC */
233 extern __inline__
long atomic_getl(long * p
)
238 extern __inline__
short atomic_gets(short * p
)
243 extern __inline__
char atomic_getb(char * p
)
248 extern __inline__
void atomic_setl(long * p
, long value
)
253 extern __inline__
void atomic_sets(short * p
, short value
)
258 extern __inline__
void atomic_setb(char * p
, char value
)
264 #else /* !defined(__GNUC__) */
266 extern void i_bit_set(
270 extern void i_bit_clear(
274 extern void bit_lock(
278 extern void bit_unlock(
283 * All other routines defined in __GNUC__ case lack
284 * definitions otherwise. - XXX
287 #endif /* !defined(__GNUC__) */
290 #if !(USLOCK_DEBUG || USLOCK_STATS)
292 * Take responsibility for production-quality usimple_locks.
293 * Let the portable lock package build simple_locks in terms
294 * of usimple_locks, which is done efficiently with macros.
295 * Currently, these aren't inlined although they probably
296 * should be. The portable lock package is used for the
297 * usimple_lock prototypes and data declarations.
299 * For non-production configurations, punt entirely to the
300 * portable lock package.
302 * N.B. I've left in the hooks for ETAP, so we can
303 * compare the performance of stats-gathering on top
304 * of "production" locks v. stats-gathering on top
305 * of portable, C-based locks.
307 #define USIMPLE_LOCK_CALLS
308 #endif /* !(USLOCK_DEBUG || USLOCK_STATS) */
310 extern void kernel_preempt_check (void);
312 #endif /* MACH_KERNEL_PRIVATE */
314 #endif /* __APLE_API_PRIVATE */
316 #endif /* _I386_LOCK_H_ */