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