2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <sys/appleapiopts.h>
30 #include <machine/cpu_capabilities.h>
31 #include <machine/commpage.h>
33 /* OSAtomic.h library native implementations. */
38 // This is a regparm(3) subroutine used by:
40 // bool OSAtomicCompareAndSwap32( int32_t old, int32_t new, int32_t *value);
41 // int32_t OSAtomicAnd32( int32_t mask, int32_t *value);
42 // int32_t OSAtomicOr32( int32_t mask, int32_t *value);
43 // int32_t OSAtomicXor32( int32_t mask, int32_t *value);
45 // It assumes old -> %eax, new -> %edx, value -> %ecx
46 // on success: returns with ZF set
47 // on failure: returns with *value in %eax, ZF clear
49 // The first word of the routine contains the address of the first instruction,
50 // so callers can pass parameters in registers by using the absolute:
52 // call *_COMPARE_AND_SWAP32
54 // TODO: move the .long onto a separate page to reduce icache pollution (?)
56 Lcompare_and_swap32_mp:
57 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
62 COMMPAGE_DESCRIPTOR(compare_and_swap32_mp,_COMM_PAGE_COMPARE_AND_SWAP32,0,kUP)
64 Lcompare_and_swap32_up:
65 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
69 COMMPAGE_DESCRIPTOR(compare_and_swap32_up,_COMM_PAGE_COMPARE_AND_SWAP32,kUP,0)
71 // This is a subroutine used by:
72 // bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value);
74 // It assumes old -> %eax/%edx, new -> %ebx/%ecx, value -> %esi
75 // on success: returns with ZF set
76 // on failure: returns with *value in %eax/%edx, ZF clear
78 Lcompare_and_swap64_mp:
79 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
84 COMMPAGE_DESCRIPTOR(compare_and_swap64_mp,_COMM_PAGE_COMPARE_AND_SWAP64,0,kUP)
86 Lcompare_and_swap64_up:
87 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
91 COMMPAGE_DESCRIPTOR(compare_and_swap64_up,_COMM_PAGE_COMPARE_AND_SWAP64,kUP,0)
93 // This is a subroutine used by:
94 // bool OSAtomicTestAndSet( uint32_t n, void *value );
95 // It assumes n -> %eax, value -> %edx
97 // Returns: old value of bit in CF
100 .long _COMM_PAGE_BTS+4
105 COMMPAGE_DESCRIPTOR(bit_test_and_set_mp,_COMM_PAGE_BTS,0,kUP)
107 Lbit_test_and_set_up:
108 .long _COMM_PAGE_BTS+4
112 COMMPAGE_DESCRIPTOR(bit_test_and_set_up,_COMM_PAGE_BTS,kUP,0)
114 // This is a subroutine used by:
115 // bool OSAtomicTestAndClear( uint32_t n, void *value );
116 // It assumes n -> %eax, value -> %edx
118 // Returns: old value of bit in CF
120 Lbit_test_and_clear_mp:
121 .long _COMM_PAGE_BTC+4
126 COMMPAGE_DESCRIPTOR(bit_test_and_clear_mp,_COMM_PAGE_BTC,0,kUP)
128 Lbit_test_and_clear_up:
129 .long _COMM_PAGE_BTC+4
133 COMMPAGE_DESCRIPTOR(bit_test_and_clear_up,_COMM_PAGE_BTC,kUP,0)
135 // This is a subroutine used by:
136 // int32_t OSAtomicAdd32( int32_t amt, int32_t *value );
137 // It assumes amt -> %eax, value -> %edx
139 // Returns: old value in %eax
140 // NB: OSAtomicAdd32 returns the new value, so clients will add amt to %eax
143 .long _COMM_PAGE_ATOMIC_ADD32+4
148 COMMPAGE_DESCRIPTOR(atomic_add32_mp,_COMM_PAGE_ATOMIC_ADD32,0,kUP)
151 .long _COMM_PAGE_ATOMIC_ADD32+4
155 COMMPAGE_DESCRIPTOR(atomic_add32_up,_COMM_PAGE_ATOMIC_ADD32,kUP,0)