]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S
MdePkg/BaseSynchronizationLib: Added proper support for ARM architecture
[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
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(InternalSyncCompareExchange32)\r
20GCC_ASM_EXPORT(InternalSyncCompareExchange64)\r
21GCC_ASM_EXPORT(InternalSyncIncrement)\r
22GCC_ASM_EXPORT(InternalSyncDecrement)\r
23\r
24/**\r
25 Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
26\r
27 Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
28 specified by Value. If Value is equal to CompareValue, then Value is set to\r
29 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
30 then Value is returned. The compare exchange operation must be performed using\r
31 MP safe mechanisms.\r
32\r
33 @param Value A pointer to the 32-bit value for the compare exchange\r
34 operation.\r
35 @param CompareValue 32-bit value used in compare operation.\r
36 @param ExchangeValue 32-bit value used in exchange operation.\r
37\r
38 @return The original *Value before exchange.\r
39\r
40**/\r
41//UINT32\r
42//EFIAPI\r
43//InternalSyncCompareExchange32 (\r
44// IN volatile UINT32 *Value,\r
45// IN UINT32 CompareValue,\r
46// IN UINT32 ExchangeValue\r
47// )\r
48ASM_PFX(InternalSyncCompareExchange32):\r
49 dmb sy\r
50\r
51InternalSyncCompareExchange32Again:\r
52 ldxr w3, [x0]\r
53 cmp w3, w1\r
54 bne InternalSyncCompareExchange32Fail\r
55\r
56InternalSyncCompareExchange32Exchange:\r
57 stxr w4, w2, [x0]\r
58 cbnz w4, InternalSyncCompareExchange32Again\r
59\r
60InternalSyncCompareExchange32Fail:\r
61 dmb sy\r
62 mov w0, w3\r
63 ret\r
64\r
65/**\r
66 Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
67\r
68 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
69 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
70 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
71 The compare exchange operation must be performed using MP safe mechanisms.\r
72\r
73 @param Value A pointer to the 64-bit value for the compare exchange\r
74 operation.\r
75 @param CompareValue 64-bit value used in compare operation.\r
76 @param ExchangeValue 64-bit value used in exchange operation.\r
77\r
78 @return The original *Value before exchange.\r
79\r
80**/\r
81//UINT64\r
82//EFIAPI\r
83//InternalSyncCompareExchange64 (\r
84// IN volatile UINT64 *Value,\r
85// IN UINT64 CompareValue,\r
86// IN UINT64 ExchangeValue\r
87// )\r
88ASM_PFX(InternalSyncCompareExchange64):\r
89 dmb sy\r
90\r
91InternalSyncCompareExchange64Again:\r
92 ldxr x3, [x0]\r
93 cmp x3, x1\r
94 bne InternalSyncCompareExchange64Fail\r
95\r
96InternalSyncCompareExchange64Exchange:\r
97 stxr w4, x2, [x0]\r
98 cbnz w4, InternalSyncCompareExchange64Again\r
99\r
100InternalSyncCompareExchange64Fail:\r
101 dmb sy\r
102 mov x0, x3\r
103 ret\r
104\r
105/**\r
106 Performs an atomic increment of an 32-bit unsigned integer.\r
107\r
108 Performs an atomic increment of the 32-bit unsigned integer specified by\r
109 Value and returns the incremented value. The increment operation must be\r
110 performed using MP safe mechanisms. The state of the return value is not\r
111 guaranteed to be MP safe.\r
112\r
113 @param Value A pointer to the 32-bit value to increment.\r
114\r
115 @return The incremented value.\r
116\r
117**/\r
118//UINT32\r
119//EFIAPI\r
120//InternalSyncIncrement (\r
121// IN volatile UINT32 *Value\r
122// )\r
123ASM_PFX(InternalSyncIncrement):\r
124 dmb sy\r
125TryInternalSyncIncrement:\r
126 ldxr w1, [x0]\r
127 add w1, w1, #1\r
128 stxr w2, w1, [x0]\r
129 cbnz w2, TryInternalSyncIncrement\r
130 dmb sy\r
131 ret\r
132\r
133/**\r
134 Performs an atomic decrement of an 32-bit unsigned integer.\r
135\r
136 Performs an atomic decrement of the 32-bit unsigned integer specified by\r
137 Value and returns the decrement value. The decrement operation must be\r
138 performed using MP safe mechanisms. The state of the return value is not\r
139 guaranteed to be MP safe.\r
140\r
141 @param Value A pointer to the 32-bit value to decrement.\r
142\r
143 @return The decrement value.\r
144\r
145**/\r
146//UINT32\r
147//EFIAPI\r
148//InternalSyncDecrement (\r
149// IN volatile UINT32 *Value\r
150// )\r
151ASM_PFX(InternalSyncDecrement):\r
152 dmb sy\r
153TryInternalSyncDecrement:\r
154 ldxr w1, [x0]\r
155 sub w1, w1, #1\r
156 stxr w2, w1, [x0]\r
157 cbnz w2, TryInternalSyncDecrement\r
158 dmb sy\r
159 ret\r