]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / Arm / Synchronization.asm
1 // Implementation of synchronization functions for ARM architecture
2 //
3 // Copyright (c) 2012-2015, ARM Limited. All rights reserved.
4 // Copyright (c) 2015, Linaro Limited. All rights reserved.
5 //
6 // SPDX-License-Identifier: BSD-2-Clause-Patent
7 //
8 //
9
10 EXPORT InternalSyncCompareExchange16
11 EXPORT InternalSyncCompareExchange32
12 EXPORT InternalSyncCompareExchange64
13 EXPORT InternalSyncIncrement
14 EXPORT InternalSyncDecrement
15
16 AREA ArmSynchronization, CODE, READONLY
17
18 /**
19 Performs an atomic compare exchange operation on a 16-bit unsigned integer.
20
21 Performs an atomic compare exchange operation on the 16-bit unsigned integer
22 specified by Value. If Value is equal to CompareValue, then Value is set to
23 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
24 then Value is returned. The compare exchange operation must be performed using
25 MP safe mechanisms.
26
27 @param Value A pointer to the 16-bit value for the compare exchange
28 operation.
29 @param CompareValue 16-bit value used in compare operation.
30 @param ExchangeValue 16-bit value used in exchange operation.
31
32 @return The original *Value before exchange.
33
34 **/
35 //UINT16
36 //EFIAPI
37 //InternalSyncCompareExchange16 (
38 // IN volatile UINT16 *Value,
39 // IN UINT16 CompareValue,
40 // IN UINT16 ExchangeValue
41 // )
42 InternalSyncCompareExchange16
43 dmb
44
45 InternalSyncCompareExchange16Again
46 ldrexh r3, [r0]
47 cmp r3, r1
48 bne InternalSyncCompareExchange16Fail
49
50 InternalSyncCompareExchange16Exchange
51 strexh ip, r2, [r0]
52 cmp ip, #0
53 bne InternalSyncCompareExchange16Again
54
55 InternalSyncCompareExchange16Fail
56 dmb
57 mov r0, r3
58 bx lr
59
60 /**
61 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
62
63 Performs an atomic compare exchange operation on the 32-bit unsigned integer
64 specified by Value. If Value is equal to CompareValue, then Value is set to
65 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
66 then Value is returned. The compare exchange operation must be performed using
67 MP safe mechanisms.
68
69 @param Value A pointer to the 32-bit value for the compare exchange
70 operation.
71 @param CompareValue 32-bit value used in compare operation.
72 @param ExchangeValue 32-bit value used in exchange operation.
73
74 @return The original *Value before exchange.
75
76 **/
77 //UINT32
78 //EFIAPI
79 //InternalSyncCompareExchange32 (
80 // IN volatile UINT32 *Value,
81 // IN UINT32 CompareValue,
82 // IN UINT32 ExchangeValue
83 // )
84 InternalSyncCompareExchange32
85 dmb
86
87 InternalSyncCompareExchange32Again
88 ldrex r3, [r0]
89 cmp r3, r1
90 bne InternalSyncCompareExchange32Fail
91
92 InternalSyncCompareExchange32Exchange
93 strex ip, r2, [r0]
94 cmp ip, #0
95 bne InternalSyncCompareExchange32Again
96
97 InternalSyncCompareExchange32Fail
98 dmb
99 mov r0, r3
100 bx lr
101
102 /**
103 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
104
105 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
106 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
107 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
108 The compare exchange operation must be performed using MP safe mechanisms.
109
110 @param Value A pointer to the 64-bit value for the compare exchange
111 operation.
112 @param CompareValue 64-bit value used in compare operation.
113 @param ExchangeValue 64-bit value used in exchange operation.
114
115 @return The original *Value before exchange.
116
117 **/
118 //UINT64
119 //EFIAPI
120 //InternalSyncCompareExchange64 (
121 // IN volatile UINT64 *Value, // r0
122 // IN UINT64 CompareValue, // r2-r3
123 // IN UINT64 ExchangeValue // stack
124 // )
125 InternalSyncCompareExchange64
126 push { r4-r7 }
127 ldrd r4, r5, [sp, #16]
128 dmb
129
130 InternalSyncCompareExchange64Again
131 ldrexd r6, r7, [r0]
132 cmp r6, r2
133 cmpeq r7, r3
134 bne InternalSyncCompareExchange64Fail
135
136 InternalSyncCompareExchange64Exchange
137 strexd ip, r4, r5, [r0]
138 cmp ip, #0
139 bne InternalSyncCompareExchange64Again
140
141 InternalSyncCompareExchange64Fail
142 dmb
143 mov r0, r6
144 mov r1, r7
145 pop { r4-r7 }
146 bx lr
147
148 /**
149 Performs an atomic increment of an 32-bit unsigned integer.
150
151 Performs an atomic increment of the 32-bit unsigned integer specified by
152 Value and returns the incremented value. The increment operation must be
153 performed using MP safe mechanisms. The state of the return value is not
154 guaranteed to be MP safe.
155
156 @param Value A pointer to the 32-bit value to increment.
157
158 @return The incremented value.
159
160 **/
161 //UINT32
162 //EFIAPI
163 //InternalSyncIncrement (
164 // IN volatile UINT32 *Value
165 // )
166 InternalSyncIncrement
167 dmb
168 TryInternalSyncIncrement
169 ldrex r1, [r0]
170 add r1, r1, #1
171 strex r2, r1, [r0]
172 cmp r2, #0
173 bne TryInternalSyncIncrement
174 dmb
175 mov r0, r1
176 bx lr
177
178 /**
179 Performs an atomic decrement of an 32-bit unsigned integer.
180
181 Performs an atomic decrement of the 32-bit unsigned integer specified by
182 Value and returns the decrement value. The decrement operation must be
183 performed using MP safe mechanisms. The state of the return value is not
184 guaranteed to be MP safe.
185
186 @param Value A pointer to the 32-bit value to decrement.
187
188 @return The decrement value.
189
190 **/
191 //UINT32
192 //EFIAPI
193 //InternalSyncDecrement (
194 // IN volatile UINT32 *Value
195 // )
196 InternalSyncDecrement
197 dmb
198 TryInternalSyncDecrement
199 ldrex r1, [r0]
200 sub r1, r1, #1
201 strex r2, r1, [r0]
202 cmp r2, #0
203 bne TryInternalSyncDecrement
204 dmb
205 mov r0, r1
206 bx lr
207
208 END