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