]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Arm / Synchronization.asm
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
9b89163e 10 EXPORT InternalSyncCompareExchange16\r
cc310428
OM
11 EXPORT InternalSyncCompareExchange32\r
12 EXPORT InternalSyncCompareExchange64\r
13 EXPORT InternalSyncIncrement\r
14 EXPORT InternalSyncDecrement\r
15\r
16 AREA ArmSynchronization, CODE, READONLY\r
17\r
9b89163e
AB
18/**\r
19 Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
20\r
21 Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
22 specified by Value. If Value is equal to CompareValue, then Value is set to\r
23 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
24 then Value is returned. The compare exchange operation must be performed using\r
25 MP safe mechanisms.\r
26\r
27 @param Value A pointer to the 16-bit value for the compare exchange\r
28 operation.\r
29 @param CompareValue 16-bit value used in compare operation.\r
30 @param ExchangeValue 16-bit value used in exchange operation.\r
31\r
32 @return The original *Value before exchange.\r
33\r
34**/\r
35//UINT16\r
36//EFIAPI\r
37//InternalSyncCompareExchange16 (\r
38// IN volatile UINT16 *Value,\r
39// IN UINT16 CompareValue,\r
40// IN UINT16 ExchangeValue\r
41// )\r
42InternalSyncCompareExchange16\r
43 dmb\r
44\r
45InternalSyncCompareExchange16Again\r
46 ldrexh r3, [r0]\r
47 cmp r3, r1\r
48 bne InternalSyncCompareExchange16Fail\r
49\r
50InternalSyncCompareExchange16Exchange\r
51 strexh ip, r2, [r0]\r
52 cmp ip, #0\r
53 bne InternalSyncCompareExchange16Again\r
54\r
55InternalSyncCompareExchange16Fail\r
56 dmb\r
57 mov r0, r3\r
58 bx lr\r
59\r
cc310428
OM
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\r
86\r
87InternalSyncCompareExchange32Again\r
88 ldrex r3, [r0]\r
89 cmp r3, r1\r
90 bne InternalSyncCompareExchange32Fail\r
91\r
92InternalSyncCompareExchange32Exchange\r
93 strex ip, r2, [r0]\r
94 cmp ip, #0\r
95 bne InternalSyncCompareExchange32Again\r
96\r
97InternalSyncCompareExchange32Fail\r
98 dmb\r
99 mov r0, r3\r
100 bx lr\r
101\r
102/**\r
103 Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
104\r
105 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
106 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
107 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
108 The compare exchange operation must be performed using MP safe mechanisms.\r
109\r
110 @param Value A pointer to the 64-bit value for the compare exchange\r
111 operation.\r
112 @param CompareValue 64-bit value used in compare operation.\r
113 @param ExchangeValue 64-bit value used in exchange operation.\r
114\r
115 @return The original *Value before exchange.\r
116\r
117**/\r
118//UINT64\r
119//EFIAPI\r
120//InternalSyncCompareExchange64 (\r
121// IN volatile UINT64 *Value, // r0\r
122// IN UINT64 CompareValue, // r2-r3\r
123// IN UINT64 ExchangeValue // stack\r
124// )\r
125InternalSyncCompareExchange64\r
126 push { r4-r7 }\r
127 ldrd r4, r5, [sp, #16]\r
128 dmb\r
129\r
130InternalSyncCompareExchange64Again\r
131 ldrexd r6, r7, [r0]\r
132 cmp r6, r2\r
133 cmpeq r7, r3\r
134 bne InternalSyncCompareExchange64Fail\r
135\r
136InternalSyncCompareExchange64Exchange\r
137 strexd ip, r4, r5, [r0]\r
138 cmp ip, #0\r
139 bne InternalSyncCompareExchange64Again\r
140\r
141InternalSyncCompareExchange64Fail\r
142 dmb\r
143 mov r0, r6\r
144 mov r1, r7\r
145 pop { r4-r7 }\r
146 bx lr\r
147\r
148/**\r
149 Performs an atomic increment of an 32-bit unsigned integer.\r
150\r
151 Performs an atomic increment of the 32-bit unsigned integer specified by\r
152 Value and returns the incremented value. The increment operation must be\r
153 performed using MP safe mechanisms. The state of the return value is not\r
154 guaranteed to be MP safe.\r
155\r
156 @param Value A pointer to the 32-bit value to increment.\r
157\r
158 @return The incremented value.\r
159\r
160**/\r
161//UINT32\r
162//EFIAPI\r
163//InternalSyncIncrement (\r
164// IN volatile UINT32 *Value\r
165// )\r
166InternalSyncIncrement\r
167 dmb\r
168TryInternalSyncIncrement\r
169 ldrex r1, [r0]\r
170 add r1, r1, #1\r
171 strex r2, r1, [r0]\r
172 cmp r2, #0\r
173 bne TryInternalSyncIncrement\r
174 dmb\r
f61762d0 175 mov r0, r1\r
cc310428
OM
176 bx lr\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
196InternalSyncDecrement\r
197 dmb\r
198TryInternalSyncDecrement\r
199 ldrex r1, [r0]\r
200 sub r1, r1, #1\r
201 strex r2, r1, [r0]\r
202 cmp r2, #0\r
203 bne TryInternalSyncDecrement\r
204 dmb\r
f61762d0 205 mov r0, r1\r
cc310428
OM
206 bx lr\r
207\r
208 END\r