]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseSynchronizationLib/Arm/Synchronization.asm
MdePkg/BaseSynchronizationLib: Added proper support for ARM architecture
[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 //
5 // This program and the accompanying materials
6 // are licensed and made available under the terms and conditions of the BSD License
7 // which accompanies this distribution. The full text of the license may be found at
8 // http://opensource.org/licenses/bsd-license.php
9 //
10 // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 //
13 //
14
15 EXPORT InternalSyncCompareExchange32
16 EXPORT InternalSyncCompareExchange64
17 EXPORT InternalSyncIncrement
18 EXPORT InternalSyncDecrement
19
20 AREA ArmSynchronization, CODE, READONLY
21
22 /**
23 Performs an atomic compare exchange operation on a 32-bit unsigned integer.
24
25 Performs an atomic compare exchange operation on the 32-bit unsigned integer
26 specified by Value. If Value is equal to CompareValue, then Value is set to
27 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,
28 then Value is returned. The compare exchange operation must be performed using
29 MP safe mechanisms.
30
31 @param Value A pointer to the 32-bit value for the compare exchange
32 operation.
33 @param CompareValue 32-bit value used in compare operation.
34 @param ExchangeValue 32-bit value used in exchange operation.
35
36 @return The original *Value before exchange.
37
38 **/
39 //UINT32
40 //EFIAPI
41 //InternalSyncCompareExchange32 (
42 // IN volatile UINT32 *Value,
43 // IN UINT32 CompareValue,
44 // IN UINT32 ExchangeValue
45 // )
46 InternalSyncCompareExchange32
47 dmb
48
49 InternalSyncCompareExchange32Again
50 ldrex r3, [r0]
51 cmp r3, r1
52 bne InternalSyncCompareExchange32Fail
53
54 InternalSyncCompareExchange32Exchange
55 strex ip, r2, [r0]
56 cmp ip, #0
57 bne InternalSyncCompareExchange32Again
58
59 InternalSyncCompareExchange32Fail
60 dmb
61 mov r0, r3
62 bx lr
63
64 /**
65 Performs an atomic compare exchange operation on a 64-bit unsigned integer.
66
67 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified
68 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and
69 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.
70 The compare exchange operation must be performed using MP safe mechanisms.
71
72 @param Value A pointer to the 64-bit value for the compare exchange
73 operation.
74 @param CompareValue 64-bit value used in compare operation.
75 @param ExchangeValue 64-bit value used in exchange operation.
76
77 @return The original *Value before exchange.
78
79 **/
80 //UINT64
81 //EFIAPI
82 //InternalSyncCompareExchange64 (
83 // IN volatile UINT64 *Value, // r0
84 // IN UINT64 CompareValue, // r2-r3
85 // IN UINT64 ExchangeValue // stack
86 // )
87 InternalSyncCompareExchange64
88 push { r4-r7 }
89 ldrd r4, r5, [sp, #16]
90 dmb
91
92 InternalSyncCompareExchange64Again
93 ldrexd r6, r7, [r0]
94 cmp r6, r2
95 cmpeq r7, r3
96 bne InternalSyncCompareExchange64Fail
97
98 InternalSyncCompareExchange64Exchange
99 strexd ip, r4, r5, [r0]
100 cmp ip, #0
101 bne InternalSyncCompareExchange64Again
102
103 InternalSyncCompareExchange64Fail
104 dmb
105 mov r0, r6
106 mov r1, r7
107 pop { r4-r7 }
108 bx lr
109
110 /**
111 Performs an atomic increment of an 32-bit unsigned integer.
112
113 Performs an atomic increment of the 32-bit unsigned integer specified by
114 Value and returns the incremented value. The increment operation must be
115 performed using MP safe mechanisms. The state of the return value is not
116 guaranteed to be MP safe.
117
118 @param Value A pointer to the 32-bit value to increment.
119
120 @return The incremented value.
121
122 **/
123 //UINT32
124 //EFIAPI
125 //InternalSyncIncrement (
126 // IN volatile UINT32 *Value
127 // )
128 InternalSyncIncrement
129 dmb
130 TryInternalSyncIncrement
131 ldrex r1, [r0]
132 add r1, r1, #1
133 strex r2, r1, [r0]
134 cmp r2, #0
135 bne TryInternalSyncIncrement
136 dmb
137 bx lr
138
139 /**
140 Performs an atomic decrement of an 32-bit unsigned integer.
141
142 Performs an atomic decrement of the 32-bit unsigned integer specified by
143 Value and returns the decrement value. The decrement operation must be
144 performed using MP safe mechanisms. The state of the return value is not
145 guaranteed to be MP safe.
146
147 @param Value A pointer to the 32-bit value to decrement.
148
149 @return The decrement value.
150
151 **/
152 //UINT32
153 //EFIAPI
154 //InternalSyncDecrement (
155 // IN volatile UINT32 *Value
156 // )
157 InternalSyncDecrement
158 dmb
159 TryInternalSyncDecrement
160 ldrex r1, [r0]
161 sub r1, r1, #1
162 strex r2, r1, [r0]
163 cmp r2, #0
164 bne TryInternalSyncDecrement
165 dmb
166 bx lr
167
168 END