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