]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/AArch64/Synchronization.S
MdePkg/BaseSynchronizationLib: Added proper support for ARM architecture
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / AArch64 / Synchronization.S
1 // Implementation of synchronization functions for ARM architecture (AArch64)
2 //
3 // Copyright (c) 2012-2015, ARM Limited. All rights reserved.
4 // Copyright (c) 2015, Linaro Limited. All rights reserved.
5 //
6 // This program and the accompanying materials
7 // are licensed and made available under the terms and conditions of the BSD License
8 // which accompanies this distribution. The full text of the license may be found at
9 // http://opensource.org/licenses/bsd-license.php
10 //
11 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 //
14 //
15
16 .text
17 .align 3
18
19 GCC_ASM_EXPORT(InternalSyncCompareExchange32)
20 GCC_ASM_EXPORT(InternalSyncCompareExchange64)
21 GCC_ASM_EXPORT(InternalSyncIncrement)
22 GCC_ASM_EXPORT(InternalSyncDecrement)
23
24 /**
25 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
26
27 Performs an atomic compare exchange operation on the 32-bit unsigned integer
28 specified by Value. If Value is equal to CompareValue, then Value is set to
29 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
30 then Value is returned. The compare exchange operation must be performed using
31 MP safe mechanisms.
32
33 @param Value A pointer to the 32-bit value for the compare exchange
34 operation.
35 @param CompareValue 32-bit value used in compare operation.
36 @param ExchangeValue 32-bit value used in exchange operation.
37
38 @return The original *Value before exchange.
39
40 **/
41 //UINT32
42 //EFIAPI
43 //InternalSyncCompareExchange32 (
44 // IN volatile UINT32 *Value,
45 // IN UINT32 CompareValue,
46 // IN UINT32 ExchangeValue
47 // )
48 ASM_PFX(InternalSyncCompareExchange32):
49 dmb sy
50
51 InternalSyncCompareExchange32Again:
52 ldxr w3, [x0]
53 cmp w3, w1
54 bne InternalSyncCompareExchange32Fail
55
56 InternalSyncCompareExchange32Exchange:
57 stxr w4, w2, [x0]
58 cbnz w4, InternalSyncCompareExchange32Again
59
60 InternalSyncCompareExchange32Fail:
61 dmb sy
62 mov w0, w3
63 ret
64
65 /**
66 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
67
68 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
69 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
70 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
71 The compare exchange operation must be performed using MP safe mechanisms.
72
73 @param Value A pointer to the 64-bit value for the compare exchange
74 operation.
75 @param CompareValue 64-bit value used in compare operation.
76 @param ExchangeValue 64-bit value used in exchange operation.
77
78 @return The original *Value before exchange.
79
80 **/
81 //UINT64
82 //EFIAPI
83 //InternalSyncCompareExchange64 (
84 // IN volatile UINT64 *Value,
85 // IN UINT64 CompareValue,
86 // IN UINT64 ExchangeValue
87 // )
88 ASM_PFX(InternalSyncCompareExchange64):
89 dmb sy
90
91 InternalSyncCompareExchange64Again:
92 ldxr x3, [x0]
93 cmp x3, x1
94 bne InternalSyncCompareExchange64Fail
95
96 InternalSyncCompareExchange64Exchange:
97 stxr w4, x2, [x0]
98 cbnz w4, InternalSyncCompareExchange64Again
99
100 InternalSyncCompareExchange64Fail:
101 dmb sy
102 mov x0, x3
103 ret
104
105 /**
106 Performs an atomic increment of an 32-bit unsigned integer.
107
108 Performs an atomic increment of the 32-bit unsigned integer specified by
109 Value and returns the incremented value. The increment operation must be
110 performed using MP safe mechanisms. The state of the return value is not
111 guaranteed to be MP safe.
112
113 @param Value A pointer to the 32-bit value to increment.
114
115 @return The incremented value.
116
117 **/
118 //UINT32
119 //EFIAPI
120 //InternalSyncIncrement (
121 // IN volatile UINT32 *Value
122 // )
123 ASM_PFX(InternalSyncIncrement):
124 dmb sy
125 TryInternalSyncIncrement:
126 ldxr w1, [x0]
127 add w1, w1, #1
128 stxr w2, w1, [x0]
129 cbnz w2, TryInternalSyncIncrement
130 dmb sy
131 ret
132
133 /**
134 Performs an atomic decrement of an 32-bit unsigned integer.
135
136 Performs an atomic decrement of the 32-bit unsigned integer specified by
137 Value and returns the decrement value. The decrement operation must be
138 performed using MP safe mechanisms. The state of the return value is not
139 guaranteed to be MP safe.
140
141 @param Value A pointer to the 32-bit value to decrement.
142
143 @return The decrement value.
144
145 **/
146 //UINT32
147 //EFIAPI
148 //InternalSyncDecrement (
149 // IN volatile UINT32 *Value
150 // )
151 ASM_PFX(InternalSyncDecrement):
152 dmb sy
153 TryInternalSyncDecrement:
154 ldxr w1, [x0]
155 sub w1, w1, #1
156 stxr w2, w1, [x0]
157 cbnz w2, TryInternalSyncDecrement
158 dmb sy
159 ret