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