]>
git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ppc/IOSharedLockImp.h
2 * Copyright (c) 1998-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, Inc. All rights reserved.
32 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
34 * EventShmemLock.h - Shared memory area locks for use between the
35 * WindowServer and the Event Driver.
38 * 30 Nov 1992 Ben Fathi (benf@next.com)
41 * 29 April 1992 Mike Paquette at NeXT
44 * Multiprocessor locks used within the shared memory area between the
45 * kernel and event system. These must work in both user and kernel mode.
46 * The locks are defined in an include file so they get exported to the local
51 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
52 #define _IOKIT_IOSHAREDLOCKIMP_H
54 #include <architecture/ppc/asm_help.h>
57 #include <mach/ppc/asm.h>
60 .macro DISABLE_PREEMPTION
62 stwu r1
,-(FM_SIZE
)(r1
)
65 stw r0
,(FM_SIZE
+FM_LR_SAVE
)(r1
)
66 bl
EXT(_disable_preemption
)
73 .macro ENABLE_PREEMPTION
75 stwu r1
,-(FM_SIZE
)(r1
)
78 stw r0
,(FM_SIZE
+FM_LR_SAVE
)(r1
)
79 bl
EXT(_enable_preemption
)
92 * Lock the lock pointed to by p. Spin (possibly forever) until
93 * the lock is available. Test and test and set logic used.
100 li a6
,1 // lock value
102 8: lwz a7
,0(a0
) // Get lock word
103 mr
. a7
,a7
// Is it held?
106 9: lwarx a7
,0,a0
// read the lock
107 mr
. a7
,a7
// Is it held?
108 bne
-- 7f
// yes, kill reservation
109 stwcx
. a6
,0,a0
// try to get the lock
110 bne
-- 9b
// failed, try again
112 blr
// got it, return
114 7: li a7
,-4 // Point to a spot in the red zone
115 stwcx
. a7
,a7
,r1
// Kill reservation
116 b
8b
// Go wait some more...
123 li a6
,1 // lock value
125 8: lwz a7
,0(a0
) // Get lock word
126 mr
. a7
,a7
// Is it held?
129 9: lwarx a7
,0,a0
// read the lock
130 mr
. a7
,a7
// Is it held?
131 bne
-- 7f
// yes, kill reservation
132 stwcx
. a6
,0,a0
// try to get the lock
133 bne
-- 9b
// failed, try again
135 blr
// got it, return
137 7: li a7
,-4 // Point to a spot in the red zone
138 stwcx
. a7
,a7
,r1
// Kill reservation
139 b
8b
// Go wait some more...
148 * Unlock the lock pointed to by p.
172 * Try to lock p. Return TRUE if successful in obtaining lock.
179 li a6
,1 // lock value
181 lwz a7
,0(a0
) // Get lock word
182 mr
. a7
,a7
// Is it held?
185 9: lwarx a7
,0,a0
// read the lock
186 mr
. a7
,a7
// Is it held?
187 bne
-- 7f
// yes, kill reservation
188 stwcx
. a6
,0,a0
// try to get the lock
189 bne
-- 9b
// failed, try again
190 li a0
,1 // return TRUE
192 blr
// got it, return
194 7: li a7
,-4 // Point to a spot in the red zone
195 stwcx
. a7
,a7
,r1
// Kill reservation
199 li a0
,0 // return FALSE
208 li a6
,1 // lock value
210 lwz a7
,0(a0
) // Get lock word
211 mr
. a7
,a7
// Is it held?
214 9: lwarx a7
,0,a0
// read the lock
215 mr
. a7
,a7
// Is it held?
216 bne
-- 7f
// yes, kill reservation
217 stwcx
. a6
,0,a0
// try to get the lock
218 bne
-- 9b
// failed, try again
219 li a0
,1 // return TRUE
221 blr
// got it, return
223 7: li a7
,-4 // Point to a spot in the red zone
224 stwcx
. a7
,a7
,r1
// Kill reservation
228 li a0
,0 // return FALSE
233 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */