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