]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / AArch64 / Synchronization.S
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 // SPDX-License-Identifier: BSD-2-Clause-Patent
7 //
8 //
9
10 .text
11 .align 3
12
13 GCC_ASM_EXPORT(InternalSyncCompareExchange16)
14 GCC_ASM_EXPORT(InternalSyncCompareExchange32)
15 GCC_ASM_EXPORT(InternalSyncCompareExchange64)
16 GCC_ASM_EXPORT(InternalSyncIncrement)
17 GCC_ASM_EXPORT(InternalSyncDecrement)
18
19 /**
20 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
21
22 Performs an atomic compare exchange operation on the 16-bit unsigned integer
23 specified by Value. If Value is equal to CompareValue, then Value is set to
24 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
25 then Value is returned. The compare exchange operation must be performed using
26 MP safe mechanisms.
27
28 @param Value A pointer to the 16-bit value for the compare exchange
29 operation.
30 @param CompareValue 16-bit value used in compare operation.
31 @param ExchangeValue 16-bit value used in exchange operation.
32
33 @return The original *Value before exchange.
34
35 **/
36 //UINT16
37 //EFIAPI
38 //InternalSyncCompareExchange16 (
39 // IN volatile UINT16 *Value,
40 // IN UINT16 CompareValue,
41 // IN UINT16 ExchangeValue
42 // )
43 ASM_PFX(InternalSyncCompareExchange16):
44 uxth w1, w1
45 uxth w2, w2
46 dmb sy
47
48 InternalSyncCompareExchange16Again:
49 ldxrh w3, [x0]
50 cmp w3, w1
51 bne InternalSyncCompareExchange16Fail
52
53 InternalSyncCompareExchange16Exchange:
54 stxrh w4, w2, [x0]
55 cbnz w4, InternalSyncCompareExchange16Again
56
57 InternalSyncCompareExchange16Fail:
58 dmb sy
59 mov w0, w3
60 ret
61
62 /**
63 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
64
65 Performs an atomic compare exchange operation on the 32-bit unsigned integer
66 specified by Value. If Value is equal to CompareValue, then Value is set to
67 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
68 then Value is returned. The compare exchange operation must be performed using
69 MP safe mechanisms.
70
71 @param Value A pointer to the 32-bit value for the compare exchange
72 operation.
73 @param CompareValue 32-bit value used in compare operation.
74 @param ExchangeValue 32-bit value used in exchange operation.
75
76 @return The original *Value before exchange.
77
78 **/
79 //UINT32
80 //EFIAPI
81 //InternalSyncCompareExchange32 (
82 // IN volatile UINT32 *Value,
83 // IN UINT32 CompareValue,
84 // IN UINT32 ExchangeValue
85 // )
86 ASM_PFX(InternalSyncCompareExchange32):
87 dmb sy
88
89 InternalSyncCompareExchange32Again:
90 ldxr w3, [x0]
91 cmp w3, w1
92 bne InternalSyncCompareExchange32Fail
93
94 InternalSyncCompareExchange32Exchange:
95 stxr w4, w2, [x0]
96 cbnz w4, InternalSyncCompareExchange32Again
97
98 InternalSyncCompareExchange32Fail:
99 dmb sy
100 mov w0, w3
101 ret
102
103 /**
104 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
105
106 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
107 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
108 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
109 The compare exchange operation must be performed using MP safe mechanisms.
110
111 @param Value A pointer to the 64-bit value for the compare exchange
112 operation.
113 @param CompareValue 64-bit value used in compare operation.
114 @param ExchangeValue 64-bit value used in exchange operation.
115
116 @return The original *Value before exchange.
117
118 **/
119 //UINT64
120 //EFIAPI
121 //InternalSyncCompareExchange64 (
122 // IN volatile UINT64 *Value,
123 // IN UINT64 CompareValue,
124 // IN UINT64 ExchangeValue
125 // )
126 ASM_PFX(InternalSyncCompareExchange64):
127 dmb sy
128
129 InternalSyncCompareExchange64Again:
130 ldxr x3, [x0]
131 cmp x3, x1
132 bne InternalSyncCompareExchange64Fail
133
134 InternalSyncCompareExchange64Exchange:
135 stxr w4, x2, [x0]
136 cbnz w4, InternalSyncCompareExchange64Again
137
138 InternalSyncCompareExchange64Fail:
139 dmb sy
140 mov x0, x3
141 ret
142
143 /**
144 Performs an atomic increment of an 32-bit unsigned integer.
145
146 Performs an atomic increment of the 32-bit unsigned integer specified by
147 Value and returns the incremented value. The increment operation must be
148 performed using MP safe mechanisms. The state of the return value is not
149 guaranteed to be MP safe.
150
151 @param Value A pointer to the 32-bit value to increment.
152
153 @return The incremented value.
154
155 **/
156 //UINT32
157 //EFIAPI
158 //InternalSyncIncrement (
159 // IN volatile UINT32 *Value
160 // )
161 ASM_PFX(InternalSyncIncrement):
162 dmb sy
163 TryInternalSyncIncrement:
164 ldxr w1, [x0]
165 add w1, w1, #1
166 stxr w2, w1, [x0]
167 cbnz w2, TryInternalSyncIncrement
168 mov w0, w1
169 dmb sy
170 ret
171
172 /**
173 Performs an atomic decrement of an 32-bit unsigned integer.
174
175 Performs an atomic decrement of the 32-bit unsigned integer specified by
176 Value and returns the decrement value. The decrement operation must be
177 performed using MP safe mechanisms. The state of the return value is not
178 guaranteed to be MP safe.
179
180 @param Value A pointer to the 32-bit value to decrement.
181
182 @return The decrement value.
183
184 **/
185 //UINT32
186 //EFIAPI
187 //InternalSyncDecrement (
188 // IN volatile UINT32 *Value
189 // )
190 ASM_PFX(InternalSyncDecrement):
191 dmb sy
192 TryInternalSyncDecrement:
193 ldxr w1, [x0]
194 sub w1, w1, #1
195 stxr w2, w1, [x0]
196 cbnz w2, TryInternalSyncDecrement
197 mov w0, w1
198 dmb sy
199 ret