]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/flipc_dep.h
xnu-792.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / flipc_dep.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 *
25 */
26
27 /*
28 * mach/i386/flipc_dep.h
29 *
30 * This file will have all of the FLIPC implementation machine dependent
31 * defines that need to be visible to both kernel and AIL (eg. bus locks
32 * and bus synchronization primitives).
33 */
34
35 #ifndef _MACH_FLIPC_DEP_H_
36 #define _MACH_FLIPC_DEP_H_
37
38 /* For the 386, we don't need to wrap synchronization variable writes
39 at all. */
40 #define SYNCVAR_WRITE(statement) statement
41
42 /* And similarly (I believe; check on this), for the 386 there isn't any
43 requirement for write fences. */
44 #define WRITE_FENCE()
45
46 /*
47 * Flipc simple lock defines. These are almost completely for the use
48 * of the AIL; the reason they are in this file is that they need to
49 * be initialized properly in the communications buffer initialization
50 * routine. Sigh. Note in particular that the kernel has no defined
51 * "simple_lock_yield_function", so it had better never expand the
52 * macro simple_lock_acquire.
53 *
54 * These locks may be declared by "flipc_simple_lock lock;". If they
55 * are instead declared by FLIPC_DECL_SIMPLE_LOCK(class,lockname) they
56 * may be used without initialization.
57 */
58
59 #define SIMPLE_LOCK_INITIALIZER 0
60 #define FLIPC_DECL_SIMPLE_LOCK(class,lockname) \
61 class flipc_simple_lock (lockname) = SIMPLE_LOCK_INITIALIZER
62
63 /*
64 * Lower case because they may be macros or functions.
65 * I'll include the function prototypes just for examples here.
66 */
67
68 #define flipc_simple_lock_init(lock) \
69 do { \
70 *(lock) = SIMPLE_LOCK_INITIALIZER; \
71 } while (0)
72
73 /*
74 * Defines of the actual routines, for gcc.
75 */
76
77 #define flipc_simple_lock_locked(lock) ((*lock) != SIMPLE_LOCK_INITIALIZER)
78
79 #ifdef __GNUC__
80 extern __inline__ int flipc_simple_lock_try(flipc_simple_lock *lock)
81 {
82 int r;
83 __asm__ volatile("movl $1, %0; xchgl %0, %1" : "=&r" (r), "=m" (*lock));
84 return !r;
85 }
86
87 /* I don't know why this requires an ASM, but I'll follow the leader. */
88 extern __inline__ void flipc_simple_lock_release(flipc_simple_lock *lock)
89 {
90 register int t;
91
92 __asm__ volatile("xorl %0, %0; xchgl %0, %1" : "=&r" (t), "=m" (*lock));
93 }
94 #else /* __GNUC__ */
95 /* If we aren't compiling with gcc, the above need to be functions. */
96 #endif /* __GNUC__ */
97
98 #endif /* _MACH_FLIPC_DEP_H_ */