2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 * Copyright (c) 2004-2006 Apple Computer, Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
25 #include <machine/cpu_capabilities.h>
30 .globl x ## Barrier ; \
36 DECLARE(_OSAtomicAnd32)
42 call *_COMM_PAGE_COMPARE_AND_SWAP32
47 DECLARE(_OSAtomicOr32)
53 call *_COMM_PAGE_COMPARE_AND_SWAP32
58 DECLARE(_OSAtomicXor32)
64 call *_COMM_PAGE_COMPARE_AND_SWAP32
69 DECLARE(_OSAtomicAnd32Orig)
75 call *_COMM_PAGE_COMPARE_AND_SWAP32
79 DECLARE(_OSAtomicOr32Orig)
85 call *_COMM_PAGE_COMPARE_AND_SWAP32
89 DECLARE(_OSAtomicXor32Orig)
95 call *_COMM_PAGE_COMPARE_AND_SWAP32
99 DECLARE(_OSAtomicCompareAndSwapPtr)
100 DECLARE(_OSAtomicCompareAndSwapInt)
101 DECLARE(_OSAtomicCompareAndSwapLong)
102 DECLARE(_OSAtomicCompareAndSwap32)
106 call *_COMM_PAGE_COMPARE_AND_SWAP32
108 movzbl %al,%eax // widen in case caller assumes we return an int
111 DECLARE(_OSAtomicCompareAndSwap64)
119 call *_COMM_PAGE_COMPARE_AND_SWAP64
121 movzbl %al,%eax // widen in case caller assumes we return an int
126 DECLARE(_OSAtomicAdd32)
130 call *_COMM_PAGE_ATOMIC_ADD32
134 DECLARE(_OSAtomicAdd64)
140 1: movl 12(%esp), %ebx
144 call *_COMM_PAGE_COMPARE_AND_SWAP64
152 DECLARE(_OSAtomicTestAndSet)
162 movzbl %al,%eax // widen in case caller assumes we return an int
165 DECLARE(_OSAtomicTestAndClear)
175 movzbl %al,%eax // widen in case caller assumes we return an int
179 .globl _OSSpinLockTry
180 .globl __spin_lock_try
183 movl $(_COMM_PAGE_SPINLOCK_TRY), %eax
187 .globl _OSSpinLockLock
193 movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax
197 .globl _OSSpinLockUnlock
208 .globl _OSMemoryBarrier
210 movl $(_COMM_PAGE_MEMORY_BARRIER), %eax
214 * typedef volatile struct {
215 * void *opaque1; <-- ptr to 1st queue element or null
216 * long opaque2; <-- generation count
219 * void OSAtomicEnqueue( OSQueueHead *list, void *new, size_t offset);
222 .globl _OSAtomicEnqueue
227 movl 16(%esp),%edi // %edi == ptr to list head
228 movl 20(%esp),%ebx // %ebx == new
229 movl 24(%esp),%esi // %esi == offset
230 movl (%edi),%eax // %eax == ptr to 1st element in Q
231 movl 4(%edi),%edx // %edx == current generation count
233 movl %eax,(%ebx,%esi)// link to old list head from new element
235 incl %ecx // increment generation count
236 lock // always lock for now...
237 cmpxchg8b (%edi) // ...push on new element
245 /* void* OSAtomicDequeue( OSQueueHead *list, size_t offset); */
247 .globl _OSAtomicDequeue
252 movl 16(%esp),%edi // %edi == ptr to list head
253 movl 20(%esp),%esi // %esi == offset
254 movl (%edi),%eax // %eax == ptr to 1st element in Q
255 movl 4(%edi),%edx // %edx == current generation count
257 testl %eax,%eax // list empty?
259 movl (%eax,%esi),%ebx // point to 2nd in Q
261 incl %ecx // increment generation count
262 lock // always lock for now...
263 cmpxchg8b (%edi) // ...pop off 1st element
269 ret // ptr to 1st element in Q still in %eax