]>
Commit | Line | Data |
---|---|---|
3d9156a7 A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #include <machine/cpu_capabilities.h> | |
25 | ||
26 | #define DECLARE(x) \ | |
27 | .align 2, 0x90 ; \ | |
28 | .globl x ; \ | |
29 | .globl x ## Barrier ; \ | |
30 | x: ; \ | |
31 | x ## Barrier: | |
32 | ||
33 | .text | |
34 | ||
35 | DECLARE(_OSAtomicAnd32) | |
36 | movl 8(%esp), %ecx | |
37 | movl (%ecx), %eax | |
38 | 1: | |
39 | movl 4(%esp), %edx | |
40 | andl %eax, %edx | |
41 | call *_COMM_PAGE_COMPARE_AND_SWAP32 | |
42 | jnz 1b | |
43 | movl %edx, %eax | |
44 | ret | |
45 | ||
46 | DECLARE(_OSAtomicOr32) | |
47 | movl 8(%esp), %ecx | |
48 | movl (%ecx), %eax | |
49 | 1: | |
50 | movl 4(%esp), %edx | |
51 | orl %eax, %edx | |
52 | call *_COMM_PAGE_COMPARE_AND_SWAP32 | |
53 | jnz 1b | |
54 | movl %edx, %eax | |
55 | ret | |
56 | ||
57 | DECLARE(_OSAtomicXor32) | |
58 | movl 8(%esp), %ecx | |
59 | movl (%ecx), %eax | |
60 | 1: | |
61 | movl 4(%esp), %edx | |
62 | xorl %eax, %edx | |
63 | call *_COMM_PAGE_COMPARE_AND_SWAP32 | |
64 | jnz 1b | |
65 | movl %edx, %eax | |
66 | ret | |
67 | ||
68 | DECLARE(_OSAtomicCompareAndSwap32) | |
69 | movl 4(%esp), %eax | |
70 | movl 8(%esp), %edx | |
71 | movl 12(%esp), %ecx | |
72 | call *_COMM_PAGE_COMPARE_AND_SWAP32 | |
73 | sete %al | |
74 | ret | |
75 | ||
76 | .align 2, 0x90 | |
77 | DECLARE(_OSAtomicCompareAndSwap64) | |
78 | pushl %ebx | |
79 | pushl %esi | |
80 | movl 12(%esp), %eax | |
81 | movl 16(%esp), %edx | |
82 | movl 20(%esp), %ebx | |
83 | movl 24(%esp), %ecx | |
84 | movl 28(%esp), %esi | |
85 | call *_COMM_PAGE_COMPARE_AND_SWAP64 | |
86 | sete %al | |
87 | popl %esi | |
88 | popl %ebx | |
89 | ret | |
90 | ||
91 | DECLARE(_OSAtomicAdd32) | |
92 | movl 4(%esp), %eax | |
93 | movl 8(%esp), %edx | |
94 | movl %eax, %ecx | |
95 | call *_COMM_PAGE_ATOMIC_ADD32 | |
96 | addl %ecx, %eax | |
97 | ret | |
98 | ||
99 | DECLARE(_OSAtomicAdd64) | |
100 | pushl %ebx | |
101 | pushl %esi | |
102 | movl 20(%esp), %esi | |
103 | movl 0(%esi), %eax | |
104 | movl 4(%esi), %edx | |
105 | 1: movl 12(%esp), %ebx | |
106 | movl 16(%esp), %ecx | |
107 | addl %eax, %ebx | |
108 | adcl %edx, %ecx | |
109 | call *_COMM_PAGE_COMPARE_AND_SWAP64 | |
110 | jnz 1b | |
111 | movl %ebx, %eax | |
8e029c65 | 112 | movl %ecx, %edx |
3d9156a7 A |
113 | popl %esi |
114 | popl %ebx | |
115 | ret | |
116 | ||
117 | DECLARE(_OSAtomicTestAndSet) | |
118 | movl 4(%esp), %eax | |
119 | movl 8(%esp), %edx | |
eb1cde05 A |
120 | movl %eax, %ecx |
121 | andl $-8, %ecx | |
122 | notl %eax | |
123 | andl $7, %eax | |
124 | orl %ecx, %eax | |
3d9156a7 A |
125 | call *_COMM_PAGE_BTS |
126 | setc %al | |
127 | ret | |
128 | ||
129 | DECLARE(_OSAtomicTestAndClear) | |
130 | movl 4(%esp), %eax | |
131 | movl 8(%esp), %edx | |
eb1cde05 A |
132 | movl %eax, %ecx |
133 | andl $-8, %ecx | |
134 | notl %eax | |
135 | andl $7, %eax | |
136 | orl %ecx, %eax | |
3d9156a7 A |
137 | call *_COMM_PAGE_BTC |
138 | setc %al | |
139 | ret | |
140 | ||
141 | .align 2, 0x90 | |
142 | .globl _OSSpinLockTry | |
143 | _OSSpinLockTry: | |
144 | movl $(_COMM_PAGE_SPINLOCK_TRY), %eax | |
8e029c65 | 145 | jmpl *%eax |
3d9156a7 A |
146 | |
147 | .align 2, 0x90 | |
148 | .globl _OSSpinLockLock | |
149 | _OSSpinLockLock: | |
150 | movl $(_COMM_PAGE_SPINLOCK_LOCK), %eax | |
8e029c65 | 151 | jmpl *%eax |
3d9156a7 A |
152 | |
153 | .align 2, 0x90 | |
154 | .globl _OSSpinLockUnlock | |
155 | _OSSpinLockUnlock: | |
156 | movl 4(%esp), %eax | |
157 | movl $0, (%eax) | |
158 | ret | |
159 | ||
160 | .align 2, 0x90 | |
161 | .globl _OSMemoryBarrier | |
162 | _OSMemoryBarrier: | |
163 | ret |