2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/appleapiopts.h>
25 #include <machine/cpu_capabilities.h>
26 #include <machine/commpage.h>
28 /* OSAtomic.h library native implementations. */
33 // This is a regparm(3) subroutine used by:
35 // bool OSAtomicCompareAndSwap32( int32_t old, int32_t new, int32_t *value);
36 // int32_t OSAtomicAnd32( int32_t mask, int32_t *value);
37 // int32_t OSAtomicOr32( int32_t mask, int32_t *value);
38 // int32_t OSAtomicXor32( int32_t mask, int32_t *value);
40 // It assumes old -> %eax, new -> %edx, value -> %ecx
41 // on success: returns with ZF set
42 // on failure: returns with *value in %eax, ZF clear
44 // The first word of the routine contains the address of the first instruction,
45 // so callers can pass parameters in registers by using the absolute:
47 // call *_COMPARE_AND_SWAP32
49 // TODO: move the .long onto a separate page to reduce icache pollution (?)
51 Lcompare_and_swap32_mp:
52 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
57 COMMPAGE_DESCRIPTOR(compare_and_swap32_mp,_COMM_PAGE_COMPARE_AND_SWAP32,0,kUP)
59 Lcompare_and_swap32_up:
60 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
64 COMMPAGE_DESCRIPTOR(compare_and_swap32_up,_COMM_PAGE_COMPARE_AND_SWAP32,kUP,0)
66 // This is a subroutine used by:
67 // bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value);
69 // It assumes old -> %eax/%edx, new -> %ebx/%ecx, value -> %esi
70 // on success: returns with ZF set
71 // on failure: returns with *value in %eax/%edx, ZF clear
73 Lcompare_and_swap64_mp:
74 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
79 COMMPAGE_DESCRIPTOR(compare_and_swap64_mp,_COMM_PAGE_COMPARE_AND_SWAP64,0,kUP)
81 Lcompare_and_swap64_up:
82 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
86 COMMPAGE_DESCRIPTOR(compare_and_swap64_up,_COMM_PAGE_COMPARE_AND_SWAP64,kUP,0)
88 // This is a subroutine used by:
89 // bool OSAtomicTestAndSet( uint32_t n, void *value );
90 // It assumes n -> %eax, value -> %edx
92 // Returns: old value of bit in CF
95 .long _COMM_PAGE_BTS+4
100 COMMPAGE_DESCRIPTOR(bit_test_and_set_mp,_COMM_PAGE_BTS,0,kUP)
102 Lbit_test_and_set_up:
103 .long _COMM_PAGE_BTS+4
107 COMMPAGE_DESCRIPTOR(bit_test_and_set_up,_COMM_PAGE_BTS,kUP,0)
109 // This is a subroutine used by:
110 // bool OSAtomicTestAndClear( uint32_t n, void *value );
111 // It assumes n -> %eax, value -> %edx
113 // Returns: old value of bit in CF
115 Lbit_test_and_clear_mp:
116 .long _COMM_PAGE_BTC+4
121 COMMPAGE_DESCRIPTOR(bit_test_and_clear_mp,_COMM_PAGE_BTC,0,kUP)
123 Lbit_test_and_clear_up:
124 .long _COMM_PAGE_BTC+4
128 COMMPAGE_DESCRIPTOR(bit_test_and_clear_up,_COMM_PAGE_BTC,kUP,0)
130 // This is a subroutine used by:
131 // int32_t OSAtomicAdd32( int32_t amt, int32_t *value );
132 // It assumes amt -> %eax, value -> %edx
134 // Returns: old value in %eax
135 // NB: OSAtomicAdd32 returns the new value, so clients will add amt to %eax
138 .long _COMM_PAGE_ATOMIC_ADD32+4
143 COMMPAGE_DESCRIPTOR(atomic_add32_mp,_COMM_PAGE_ATOMIC_ADD32,0,kUP)
146 .long _COMM_PAGE_ATOMIC_ADD32+4
150 COMMPAGE_DESCRIPTOR(atomic_add32_up,_COMM_PAGE_ATOMIC_ADD32,kUP,0)