MdePkg/Library/BaseSynchronizationLib: Enable VS2017/ARM64 builds
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / AArch64 / Synchronization.asm
1 ; Implementation of synchronization functions for ARM architecture (AArch64)
2 ;
3 ; Copyright (c) 2012-2015, ARM Limited. All rights reserved.
4 ; Copyright (c) 2015, Linaro Limited. All rights reserved.
5 ;
6 ; This program and the accompanying materials
7 ; are licensed and made available under the terms and conditions of the BSD License
8 ; which accompanies this distribution. The full text of the license may be found at
9 ; http://opensource.org/licenses/bsd-license.php
10 ;
11 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 ;
14 ;
15
16 EXPORT InternalSyncCompareExchange16
17 EXPORT InternalSyncCompareExchange32
18 EXPORT InternalSyncCompareExchange64
19 EXPORT InternalSyncIncrement
20 EXPORT InternalSyncDecrement
21 AREA BaseSynchronizationLib_LowLevel, CODE, READONLY
22
23 ;/**
24 ; Performs an atomic compare exchange operation on a 16-bit unsigned integer.
25 ;
26 ; Performs an atomic compare exchange operation on the 16-bit unsigned integer
27 ; specified by Value. If Value is equal to CompareValue, then Value is set to
28 ; ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
29 ; then Value is returned. The compare exchange operation must be performed using
30 ; MP safe mechanisms.
31 ;
32 ; @param Value A pointer to the 16-bit value for the compare exchange
33 ; operation.
34 ; @param CompareValue 16-bit value used in compare operation.
35 ; @param ExchangeValue 16-bit value used in exchange operation.
36 ;
37 ; @return The original *Value before exchange.
38 ;
39 ;**/
40 ;UINT16
41 ;EFIAPI
42 ;InternalSyncCompareExchange16 (
43 ; IN volatile UINT16 *Value,
44 ; IN UINT16 CompareValue,
45 ; IN UINT16 ExchangeValue
46 ; )
47 InternalSyncCompareExchange16
48 uxth w1, w1
49 uxth w2, w2
50 dmb sy
51
52 InternalSyncCompareExchange16Again
53 ldxrh w3, [x0]
54 cmp w3, w1
55 bne InternalSyncCompareExchange16Fail
56
57 InternalSyncCompareExchange16Exchange
58 stxrh w4, w2, [x0]
59 cbnz w4, InternalSyncCompareExchange16Again
60
61 InternalSyncCompareExchange16Fail
62 dmb sy
63 mov w0, w3
64 ret
65
66 ;/**
67 ; Performs an atomic compare exchange operation on a 32-bit unsigned integer.
68 ;
69 ; Performs an atomic compare exchange operation on the 32-bit unsigned integer
70 ; specified by Value. If Value is equal to CompareValue, then Value is set to
71 ; ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
72 ; then Value is returned. The compare exchange operation must be performed using
73 ; MP safe mechanisms.
74 ;
75 ; @param Value A pointer to the 32-bit value for the compare exchange
76 ; operation.
77 ; @param CompareValue 32-bit value used in compare operation.
78 ; @param ExchangeValue 32-bit value used in exchange operation.
79 ;
80 ; @return The original *Value before exchange.
81 ;
82 ;**/
83 ;UINT32
84 ;EFIAPI
85 ;InternalSyncCompareExchange32 (
86 ; IN volatile UINT32 *Value,
87 ; IN UINT32 CompareValue,
88 ; IN UINT32 ExchangeValue
89 ; )
90 InternalSyncCompareExchange32
91 dmb sy
92
93 InternalSyncCompareExchange32Again
94 ldxr w3, [x0]
95 cmp w3, w1
96 bne InternalSyncCompareExchange32Fail
97
98 InternalSyncCompareExchange32Exchange
99 stxr w4, w2, [x0]
100 cbnz w4, InternalSyncCompareExchange32Again
101
102 InternalSyncCompareExchange32Fail
103 dmb sy
104 mov w0, w3
105 ret
106
107 ;/**
108 ; Performs an atomic compare exchange operation on a 64-bit unsigned integer.
109 ;
110 ; Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
111 ; by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
112 ; CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
113 ; The compare exchange operation must be performed using MP safe mechanisms.
114 ;
115 ; @param Value A pointer to the 64-bit value for the compare exchange
116 ; operation.
117 ; @param CompareValue 64-bit value used in compare operation.
118 ; @param ExchangeValue 64-bit value used in exchange operation.
119 ;
120 ; @return The original *Value before exchange.
121 ;
122 ;**/
123 ;UINT64
124 ;EFIAPI
125 ;InternalSyncCompareExchange64 (
126 ; IN volatile UINT64 *Value,
127 ; IN UINT64 CompareValue,
128 ; IN UINT64 ExchangeValue
129 ; )
130 InternalSyncCompareExchange64
131 dmb sy
132
133 InternalSyncCompareExchange64Again
134 ldxr x3, [x0]
135 cmp x3, x1
136 bne InternalSyncCompareExchange64Fail
137
138 InternalSyncCompareExchange64Exchange
139 stxr w4, x2, [x0]
140 cbnz w4, InternalSyncCompareExchange64Again
141
142 InternalSyncCompareExchange64Fail
143 dmb sy
144 mov x0, x3
145 ret
146
147 ;/**
148 ; Performs an atomic increment of an 32-bit unsigned integer.
149 ;
150 ; Performs an atomic increment of the 32-bit unsigned integer specified by
151 ; Value and returns the incremented value. The increment operation must be
152 ; performed using MP safe mechanisms. The state of the return value is not
153 ; guaranteed to be MP safe.
154 ;
155 ; @param Value A pointer to the 32-bit value to increment.
156 ;
157 ; @return The incremented value.
158 ;
159 ;**/
160 ;UINT32
161 ;EFIAPI
162 ;InternalSyncIncrement (
163 ; IN volatile UINT32 *Value
164 ; )
165 InternalSyncIncrement
166 dmb sy
167 TryInternalSyncIncrement
168 ldxr w1, [x0]
169 add w1, w1, #1
170 stxr w2, w1, [x0]
171 cbnz w2, TryInternalSyncIncrement
172 mov w0, w1
173 dmb sy
174 ret
175
176 ;/**
177 ; Performs an atomic decrement of an 32-bit unsigned integer.
178 ;
179 ; Performs an atomic decrement of the 32-bit unsigned integer specified by
180 ; Value and returns the decrement value. The decrement operation must be
181 ; performed using MP safe mechanisms. The state of the return value is not
182 ; guaranteed to be MP safe.
183 ;
184 ; @param Value A pointer to the 32-bit value to decrement.
185 ;
186 ; @return The decrement value.
187 ;
188 ;**/
189 ;UINT32
190 ;EFIAPI
191 ;InternalSyncDecrement (
192 ; IN volatile UINT32 *Value
193 ; )
194 InternalSyncDecrement
195 dmb sy
196 TryInternalSyncDecrement
197 ldxr w1, [x0]
198 sub w1, w1, #1
199 stxr w2, w1, [x0]
200 cbnz w2, TryInternalSyncDecrement
201 mov w0, w1
202 dmb sy
203 ret
204
205 END