]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.S
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Arm / Synchronization.S
CommitLineData
cc310428
OM
1// Implementation of synchronization functions for ARM architecture\r
2//\r
3// Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r
9b89163e 4// Copyright (c) 2015, Linaro Limited. All rights reserved.\r
cc310428 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 dmb\r
45\r
46InternalSyncCompareExchange16Again:\r
47 ldrexh r3, [r0]\r
48 cmp r3, r1\r
49 bne InternalSyncCompareExchange16Fail\r
50\r
51InternalSyncCompareExchange16Exchange:\r
52 strexh ip, r2, [r0]\r
53 cmp ip, #0\r
54 bne InternalSyncCompareExchange16Again\r
55\r
56InternalSyncCompareExchange16Fail:\r
57 dmb\r
58 mov r0, r3\r
59 bx lr\r
60\r
cc310428
OM
61/**\r
62 Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
63\r
64 Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
65 specified by Value. If Value is equal to CompareValue, then Value is set to\r
66 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
67 then Value is returned. The compare exchange operation must be performed using\r
68 MP safe mechanisms.\r
69\r
70 @param Value A pointer to the 32-bit value for the compare exchange\r
71 operation.\r
72 @param CompareValue 32-bit value used in compare operation.\r
73 @param ExchangeValue 32-bit value used in exchange operation.\r
74\r
75 @return The original *Value before exchange.\r
76\r
77**/\r
78//UINT32\r
79//EFIAPI\r
80//InternalSyncCompareExchange32 (\r
81// IN volatile UINT32 *Value,\r
82// IN UINT32 CompareValue,\r
83// IN UINT32 ExchangeValue\r
84// )\r
85ASM_PFX(InternalSyncCompareExchange32):\r
86 dmb\r
87\r
88InternalSyncCompareExchange32Again:\r
89 ldrex r3, [r0]\r
90 cmp r3, r1\r
91 bne InternalSyncCompareExchange32Fail\r
92\r
93InternalSyncCompareExchange32Exchange:\r
94 strex ip, r2, [r0]\r
95 cmp ip, #0\r
96 bne InternalSyncCompareExchange32Again\r
97\r
98InternalSyncCompareExchange32Fail:\r
99 dmb\r
100 mov r0, r3\r
101 bx lr\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, // r0\r
123// IN UINT64 CompareValue, // r2-r3\r
124// IN UINT64 ExchangeValue // stack\r
125// )\r
126ASM_PFX(InternalSyncCompareExchange64):\r
127 push { r4-r7 }\r
128 ldrd r4, r5, [sp, #16]\r
129 dmb\r
130\r
131InternalSyncCompareExchange64Again:\r
132 ldrexd r6, r7, [r0]\r
133 cmp r6, r2\r
134 cmpeq r7, r3\r
135 bne InternalSyncCompareExchange64Fail\r
136\r
137InternalSyncCompareExchange64Exchange:\r
138 strexd ip, r4, r5, [r0]\r
139 cmp ip, #0\r
140 bne InternalSyncCompareExchange64Again\r
141\r
142InternalSyncCompareExchange64Fail:\r
143 dmb\r
144 mov r0, r6\r
145 mov r1, r7\r
146 pop { r4-r7 }\r
147 bx lr\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\r
169TryInternalSyncIncrement:\r
170 ldrex r1, [r0]\r
171 add r1, r1, #1\r
172 strex r2, r1, [r0]\r
173 cmp r2, #0\r
174 bne TryInternalSyncIncrement\r
175 dmb\r
f61762d0 176 mov r0, r1\r
cc310428
OM
177 bx lr\r
178\r
179/**\r
180 Performs an atomic decrement of an 32-bit unsigned integer.\r
181\r
182 Performs an atomic decrement of the 32-bit unsigned integer specified by\r
183 Value and returns the decrement value. The decrement operation must be\r
184 performed using MP safe mechanisms. The state of the return value is not\r
185 guaranteed to be MP safe.\r
186\r
187 @param Value A pointer to the 32-bit value to decrement.\r
188\r
189 @return The decrement value.\r
190\r
191**/\r
192//UINT32\r
193//EFIAPI\r
194//InternalSyncDecrement (\r
195// IN volatile UINT32 *Value\r
196// )\r
197ASM_PFX(InternalSyncDecrement):\r
198 dmb\r
199TryInternalSyncDecrement:\r
200 ldrex r1, [r0]\r
201 sub r1, r1, #1\r
202 strex r2, r1, [r0]\r
203 cmp r2, #0\r
204 bne TryInternalSyncDecrement\r
205 dmb\r
f61762d0 206 mov r0, r1\r
cc310428 207 bx lr\r