2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #include <sys/appleapiopts.h>
24 #include <machine/cpu_capabilities.h>
25 #include <machine/commpage.h>
27 /* OSAtomic.h library native implementations. */
32 // This is a regparm(3) subroutine used by:
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);
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
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:
46 // call *_COMPARE_AND_SWAP32
48 // TODO: move the .long onto a separate page to reduce icache pollution (?)
50 Lcompare_and_swap32_mp:
51 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
56 COMMPAGE_DESCRIPTOR(compare_and_swap32_mp,_COMM_PAGE_COMPARE_AND_SWAP32,0,kUP)
58 Lcompare_and_swap32_up:
59 .long _COMM_PAGE_COMPARE_AND_SWAP32+4
63 COMMPAGE_DESCRIPTOR(compare_and_swap32_up,_COMM_PAGE_COMPARE_AND_SWAP32,kUP,0)
65 // This is a subroutine used by:
66 // bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value);
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
72 Lcompare_and_swap64_mp:
73 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
78 COMMPAGE_DESCRIPTOR(compare_and_swap64_mp,_COMM_PAGE_COMPARE_AND_SWAP64,0,kUP)
80 Lcompare_and_swap64_up:
81 .long _COMM_PAGE_COMPARE_AND_SWAP64+4
85 COMMPAGE_DESCRIPTOR(compare_and_swap64_up,_COMM_PAGE_COMPARE_AND_SWAP64,kUP,0)
87 // This is a subroutine used by:
88 // bool OSAtomicTestAndSet( uint32_t n, void *value );
89 // It assumes n -> %eax, value -> %edx
91 // Returns: old value of bit in CF
94 .long _COMM_PAGE_BTS+4
99 COMMPAGE_DESCRIPTOR(bit_test_and_set_mp,_COMM_PAGE_BTS,0,kUP)
101 Lbit_test_and_set_up:
102 .long _COMM_PAGE_BTS+4
106 COMMPAGE_DESCRIPTOR(bit_test_and_set_up,_COMM_PAGE_BTS,kUP,0)
108 // This is a subroutine used by:
109 // bool OSAtomicTestAndClear( uint32_t n, void *value );
110 // It assumes n -> %eax, value -> %edx
112 // Returns: old value of bit in CF
114 Lbit_test_and_clear_mp:
115 .long _COMM_PAGE_BTC+4
120 COMMPAGE_DESCRIPTOR(bit_test_and_clear_mp,_COMM_PAGE_BTC,0,kUP)
122 Lbit_test_and_clear_up:
123 .long _COMM_PAGE_BTC+4
127 COMMPAGE_DESCRIPTOR(bit_test_and_clear_up,_COMM_PAGE_BTC,kUP,0)
129 // This is a subroutine used by:
130 // int32_t OSAtomicAdd32( int32_t amt, int32_t *value );
131 // It assumes amt -> %eax, value -> %edx
133 // Returns: old value in %eax
134 // NB: OSAtomicAdd32 returns the new value, so clients will add amt to %eax
137 .long _COMM_PAGE_ATOMIC_ADD32+4
142 COMMPAGE_DESCRIPTOR(atomic_add32_mp,_COMM_PAGE_ATOMIC_ADD32,0,kUP)
145 .long _COMM_PAGE_ATOMIC_ADD32+4
149 COMMPAGE_DESCRIPTOR(atomic_add32_up,_COMM_PAGE_ATOMIC_ADD32,kUP,0)