]>
Commit | Line | Data |
---|---|---|
91447636 A |
1 | /* |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
91447636 | 11 | * |
37839358 A |
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 | |
91447636 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
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. | |
91447636 A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
23 | #include <sys/appleapiopts.h> | |
24 | #include <machine/cpu_capabilities.h> | |
25 | #include <machine/commpage.h> | |
26 | ||
27 | /* OSAtomic.h library native implementations. */ | |
28 | ||
29 | .text | |
30 | .align 2, 0x90 | |
31 | ||
32 | // This is a regparm(3) subroutine used by: | |
33 | ||
34 | // bool OSAtomicCompareAndSwap32( int32_t old, int32_t new, int32_t *value); | |
35 | // int32_t OSAtomicAnd32( int32_t mask, int32_t *value); | |
36 | // int32_t OSAtomicOr32( int32_t mask, int32_t *value); | |
37 | // int32_t OSAtomicXor32( int32_t mask, int32_t *value); | |
38 | ||
39 | // It assumes old -> %eax, new -> %edx, value -> %ecx | |
40 | // on success: returns with ZF set | |
41 | // on failure: returns with *value in %eax, ZF clear | |
42 | ||
43 | // The first word of the routine contains the address of the first instruction, | |
44 | // so callers can pass parameters in registers by using the absolute: | |
45 | ||
46 | // call *_COMPARE_AND_SWAP32 | |
47 | ||
48 | // TODO: move the .long onto a separate page to reduce icache pollution (?) | |
49 | ||
50 | Lcompare_and_swap32_mp: | |
51 | .long _COMM_PAGE_COMPARE_AND_SWAP32+4 | |
52 | lock | |
53 | cmpxchgl %edx, (%ecx) | |
54 | ret | |
55 | ||
56 | COMMPAGE_DESCRIPTOR(compare_and_swap32_mp,_COMM_PAGE_COMPARE_AND_SWAP32,0,kUP) | |
57 | ||
58 | Lcompare_and_swap32_up: | |
59 | .long _COMM_PAGE_COMPARE_AND_SWAP32+4 | |
60 | cmpxchgl %edx, (%ecx) | |
61 | ret | |
62 | ||
63 | COMMPAGE_DESCRIPTOR(compare_and_swap32_up,_COMM_PAGE_COMPARE_AND_SWAP32,kUP,0) | |
64 | ||
65 | // This is a subroutine used by: | |
66 | // bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value); | |
67 | ||
68 | // It assumes old -> %eax/%edx, new -> %ebx/%ecx, value -> %esi | |
69 | // on success: returns with ZF set | |
70 | // on failure: returns with *value in %eax/%edx, ZF clear | |
71 | ||
72 | Lcompare_and_swap64_mp: | |
73 | .long _COMM_PAGE_COMPARE_AND_SWAP64+4 | |
74 | lock | |
75 | cmpxchg8b (%esi) | |
76 | ret | |
77 | ||
78 | COMMPAGE_DESCRIPTOR(compare_and_swap64_mp,_COMM_PAGE_COMPARE_AND_SWAP64,0,kUP) | |
79 | ||
80 | Lcompare_and_swap64_up: | |
81 | .long _COMM_PAGE_COMPARE_AND_SWAP64+4 | |
82 | cmpxchg8b (%esi) | |
83 | ret | |
84 | ||
85 | COMMPAGE_DESCRIPTOR(compare_and_swap64_up,_COMM_PAGE_COMPARE_AND_SWAP64,kUP,0) | |
86 | ||
87 | // This is a subroutine used by: | |
88 | // bool OSAtomicTestAndSet( uint32_t n, void *value ); | |
89 | // It assumes n -> %eax, value -> %edx | |
90 | ||
91 | // Returns: old value of bit in CF | |
92 | ||
93 | Lbit_test_and_set_mp: | |
94 | .long _COMM_PAGE_BTS+4 | |
95 | lock | |
96 | bts %eax, (%edx) | |
97 | ret | |
98 | ||
99 | COMMPAGE_DESCRIPTOR(bit_test_and_set_mp,_COMM_PAGE_BTS,0,kUP) | |
100 | ||
101 | Lbit_test_and_set_up: | |
102 | .long _COMM_PAGE_BTS+4 | |
103 | bts %eax, (%edx) | |
104 | ret | |
105 | ||
106 | COMMPAGE_DESCRIPTOR(bit_test_and_set_up,_COMM_PAGE_BTS,kUP,0) | |
107 | ||
108 | // This is a subroutine used by: | |
109 | // bool OSAtomicTestAndClear( uint32_t n, void *value ); | |
110 | // It assumes n -> %eax, value -> %edx | |
111 | ||
112 | // Returns: old value of bit in CF | |
113 | ||
114 | Lbit_test_and_clear_mp: | |
115 | .long _COMM_PAGE_BTC+4 | |
116 | lock | |
117 | btc %eax, (%edx) | |
118 | ret | |
119 | ||
120 | COMMPAGE_DESCRIPTOR(bit_test_and_clear_mp,_COMM_PAGE_BTC,0,kUP) | |
121 | ||
122 | Lbit_test_and_clear_up: | |
123 | .long _COMM_PAGE_BTC+4 | |
124 | btc %eax, (%edx) | |
125 | ret | |
126 | ||
127 | COMMPAGE_DESCRIPTOR(bit_test_and_clear_up,_COMM_PAGE_BTC,kUP,0) | |
128 | ||
129 | // This is a subroutine used by: | |
130 | // int32_t OSAtomicAdd32( int32_t amt, int32_t *value ); | |
131 | // It assumes amt -> %eax, value -> %edx | |
132 | ||
133 | // Returns: old value in %eax | |
134 | // NB: OSAtomicAdd32 returns the new value, so clients will add amt to %eax | |
135 | ||
136 | Latomic_add32_mp: | |
137 | .long _COMM_PAGE_ATOMIC_ADD32+4 | |
138 | lock | |
139 | xaddl %eax, (%edx) | |
140 | ret | |
141 | ||
142 | COMMPAGE_DESCRIPTOR(atomic_add32_mp,_COMM_PAGE_ATOMIC_ADD32,0,kUP) | |
143 | ||
144 | Latomic_add32_up: | |
145 | .long _COMM_PAGE_ATOMIC_ADD32+4 | |
146 | xaddl %eax, (%edx) | |
147 | ret | |
148 | ||
149 | COMMPAGE_DESCRIPTOR(atomic_add32_up,_COMM_PAGE_ATOMIC_ADD32,kUP,0) |