]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/commpage/atomic.s
xnu-792.17.14.tar.gz
[apple/xnu.git] / osfmk / i386 / commpage / atomic.s
CommitLineData
91447636 1/*
8f6c56a5 2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
91447636 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 5 *
8f6c56a5
A
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
27 */
28
29#include <sys/appleapiopts.h>
30#include <machine/cpu_capabilities.h>
31#include <machine/commpage.h>
32
33/* OSAtomic.h library native implementations. */
34
35 .text
36 .align 2, 0x90
37
38// This is a regparm(3) subroutine used by:
39
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);
44
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
48
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:
51
52// call *_COMPARE_AND_SWAP32
53
54// TODO: move the .long onto a separate page to reduce icache pollution (?)
55
56Lcompare_and_swap32_mp:
57.long _COMM_PAGE_COMPARE_AND_SWAP32+4
58 lock
59 cmpxchgl %edx, (%ecx)
60 ret
61
62 COMMPAGE_DESCRIPTOR(compare_and_swap32_mp,_COMM_PAGE_COMPARE_AND_SWAP32,0,kUP)
63
64Lcompare_and_swap32_up:
65.long _COMM_PAGE_COMPARE_AND_SWAP32+4
66 cmpxchgl %edx, (%ecx)
67 ret
68
69 COMMPAGE_DESCRIPTOR(compare_and_swap32_up,_COMM_PAGE_COMPARE_AND_SWAP32,kUP,0)
70
71// This is a subroutine used by:
72// bool OSAtomicCompareAndSwap64( int64_t old, int64_t new, int64_t *value);
73
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
77
78Lcompare_and_swap64_mp:
79.long _COMM_PAGE_COMPARE_AND_SWAP64+4
80 lock
81 cmpxchg8b (%esi)
82 ret
83
84 COMMPAGE_DESCRIPTOR(compare_and_swap64_mp,_COMM_PAGE_COMPARE_AND_SWAP64,0,kUP)
85
86Lcompare_and_swap64_up:
87.long _COMM_PAGE_COMPARE_AND_SWAP64+4
88 cmpxchg8b (%esi)
89 ret
90
91 COMMPAGE_DESCRIPTOR(compare_and_swap64_up,_COMM_PAGE_COMPARE_AND_SWAP64,kUP,0)
92
93// This is a subroutine used by:
94// bool OSAtomicTestAndSet( uint32_t n, void *value );
95// It assumes n -> %eax, value -> %edx
96
97// Returns: old value of bit in CF
98
99Lbit_test_and_set_mp:
100.long _COMM_PAGE_BTS+4
101 lock
8f6c56a5 102 bts %eax, (%edx)
91447636
A
103 ret
104
105 COMMPAGE_DESCRIPTOR(bit_test_and_set_mp,_COMM_PAGE_BTS,0,kUP)
106
107Lbit_test_and_set_up:
108.long _COMM_PAGE_BTS+4
8f6c56a5 109 bts %eax, (%edx)
91447636
A
110 ret
111
112 COMMPAGE_DESCRIPTOR(bit_test_and_set_up,_COMM_PAGE_BTS,kUP,0)
113
114// This is a subroutine used by:
115// bool OSAtomicTestAndClear( uint32_t n, void *value );
116// It assumes n -> %eax, value -> %edx
117
118// Returns: old value of bit in CF
119
120Lbit_test_and_clear_mp:
121.long _COMM_PAGE_BTC+4
122 lock
8f6c56a5 123 btc %eax, (%edx)
91447636
A
124 ret
125
126 COMMPAGE_DESCRIPTOR(bit_test_and_clear_mp,_COMM_PAGE_BTC,0,kUP)
127
128Lbit_test_and_clear_up:
129.long _COMM_PAGE_BTC+4
8f6c56a5 130 btc %eax, (%edx)
91447636
A
131 ret
132
133 COMMPAGE_DESCRIPTOR(bit_test_and_clear_up,_COMM_PAGE_BTC,kUP,0)
134
135// This is a subroutine used by:
136// int32_t OSAtomicAdd32( int32_t amt, int32_t *value );
137// It assumes amt -> %eax, value -> %edx
138
139// Returns: old value in %eax
140// NB: OSAtomicAdd32 returns the new value, so clients will add amt to %eax
141
142Latomic_add32_mp:
143.long _COMM_PAGE_ATOMIC_ADD32+4
144 lock
145 xaddl %eax, (%edx)
146 ret
147
148 COMMPAGE_DESCRIPTOR(atomic_add32_mp,_COMM_PAGE_ATOMIC_ADD32,0,kUP)
149
150Latomic_add32_up:
151.long _COMM_PAGE_ATOMIC_ADD32+4
152 xaddl %eax, (%edx)
153 ret
154
155 COMMPAGE_DESCRIPTOR(atomic_add32_up,_COMM_PAGE_ATOMIC_ADD32,kUP,0)