]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseSynchronizationLib/X64/GccInline.c
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / BaseSynchronizationLib / X64 / GccInline.c
CommitLineData
cf683fed 1/** @file\r
2 GCC inline implementation of BaseSynchronizationLib processor specific functions.\r
9095d37b
LG
3\r
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5 Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
c9b34b8c 6 This program and the accompanying materials\r
cf683fed 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
2fc59a00 9 http://opensource.org/licenses/bsd-license.php.\r
cf683fed 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\r
17\r
18\r
19/**\r
20 Performs an atomic increment of an 32-bit unsigned integer.\r
21\r
22 Performs an atomic increment of the 32-bit unsigned integer specified by\r
23 Value and returns the incremented value. The increment operation must be\r
24 performed using MP safe mechanisms. The state of the return value is not\r
25 guaranteed to be MP safe.\r
26\r
27 @param Value A pointer to the 32-bit value to increment.\r
28\r
29 @return The incremented value.\r
30\r
31**/\r
32UINT32\r
33EFIAPI\r
34InternalSyncIncrement (\r
35 IN volatile UINT32 *Value\r
36 )\r
37{\r
38 UINT32 Result;\r
39\r
40 __asm__ __volatile__ (\r
41 "lock \n\t"\r
42 "incl %2 \n\t"\r
43 "mov %2, %%eax "\r
44 : "=a" (Result), // %0\r
45 "=m" (*Value) // %1\r
9095d37b 46 : "m" (*Value) // %2\r
cf683fed 47 : "memory",\r
48 "cc"\r
49 );\r
9095d37b
LG
50\r
51 return Result;\r
cf683fed 52}\r
53\r
54\r
55/**\r
56 Performs an atomic decrement of an 32-bit unsigned integer.\r
57\r
58 Performs an atomic decrement of the 32-bit unsigned integer specified by\r
59 Value and returns the decremented value. The decrement operation must be\r
60 performed using MP safe mechanisms. The state of the return value is not\r
61 guaranteed to be MP safe.\r
62\r
63 @param Value A pointer to the 32-bit value to decrement.\r
64\r
65 @return The decremented value.\r
66\r
67**/\r
68UINT32\r
69EFIAPI\r
70InternalSyncDecrement (\r
71 IN volatile UINT32 *Value\r
72 )\r
73{\r
74 UINT32 Result;\r
9095d37b 75\r
cf683fed 76 __asm__ __volatile__ (\r
77 "lock \n\t"\r
78 "decl %2 \n\t"\r
79 "mov %2, %%eax "\r
80 : "=a" (Result), // %0\r
81 "=m" (*Value) // %1\r
9095d37b 82 : "m" (*Value) // %2\r
cf683fed 83 : "memory",\r
84 "cc"\r
85 );\r
9095d37b 86\r
cf683fed 87 return Result;\r
88}\r
89\r
90\r
9b89163e
AB
91/**\r
92 Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r
93\r
94 Performs an atomic compare exchange operation on the 16-bit unsigned integer\r
95 specified by Value. If Value is equal to CompareValue, then Value is set to\r
96 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
97 then Value is returned. The compare exchange operation must be performed using\r
98 MP safe mechanisms.\r
99\r
100\r
101 @param Value A pointer to the 16-bit value for the compare exchange\r
102 operation.\r
103 @param CompareValue 16-bit value used in compare operation.\r
104 @param ExchangeValue 16-bit value used in exchange operation.\r
105\r
106 @return The original *Value before exchange.\r
107\r
108**/\r
109UINT16\r
110EFIAPI\r
111InternalSyncCompareExchange16 (\r
112 IN OUT volatile UINT16 *Value,\r
113 IN UINT16 CompareValue,\r
114 IN UINT16 ExchangeValue\r
115 )\r
116{\r
117\r
118\r
119 __asm__ __volatile__ (\r
120 "lock \n\t"\r
121 "cmpxchgw %3, %1 "\r
122 : "=a" (CompareValue),\r
123 "=m" (*Value)\r
124 : "a" (CompareValue),\r
125 "r" (ExchangeValue),\r
126 "m" (*Value)\r
127 : "memory",\r
128 "cc"\r
129 );\r
130\r
131 return CompareValue;\r
132}\r
133\r
134\r
cf683fed 135/**\r
136 Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r
137\r
138 Performs an atomic compare exchange operation on the 32-bit unsigned integer\r
139 specified by Value. If Value is equal to CompareValue, then Value is set to\r
140 ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r
141 then Value is returned. The compare exchange operation must be performed using\r
142 MP safe mechanisms.\r
143\r
144\r
145 @param Value A pointer to the 32-bit value for the compare exchange\r
146 operation.\r
147 @param CompareValue 32-bit value used in compare operation.\r
148 @param ExchangeValue 32-bit value used in exchange operation.\r
149\r
150 @return The original *Value before exchange.\r
151\r
152**/\r
153UINT32\r
154EFIAPI\r
155InternalSyncCompareExchange32 (\r
156 IN OUT volatile UINT32 *Value,\r
157 IN UINT32 CompareValue,\r
158 IN UINT32 ExchangeValue\r
159 )\r
160{\r
cf683fed 161\r
cf683fed 162\r
163 __asm__ __volatile__ (\r
164 "lock \n\t"\r
165 "cmpxchgl %3, %1 "\r
166 : "=a" (CompareValue), // %0\r
167 "=m" (*Value) // %1\r
168 : "a" (CompareValue), // %2\r
9095d37b 169 "r" (ExchangeValue), // %3\r
cf683fed 170 "m" (*Value)\r
171 : "memory",\r
172 "cc"\r
173 );\r
9095d37b 174\r
4e4a5f35 175 return CompareValue;\r
cf683fed 176}\r
177\r
178\r
179/**\r
180 Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r
181\r
182 Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r
183 by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r
184 CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r
185 The compare exchange operation must be performed using MP safe mechanisms.\r
186\r
187\r
188 @param Value A pointer to the 64-bit value for the compare exchange\r
189 operation.\r
190 @param CompareValue 64-bit value used in compare operation.\r
191 @param ExchangeValue 64-bit value used in exchange operation.\r
192\r
193 @return The original *Value before exchange.\r
194\r
195**/\r
196UINT64\r
197EFIAPI\r
198InternalSyncCompareExchange64 (\r
199 IN OUT volatile UINT64 *Value,\r
200 IN UINT64 CompareValue,\r
201 IN UINT64 ExchangeValue\r
202 )\r
203{\r
cf683fed 204\r
205 __asm__ __volatile__ (\r
206 "lock \n\t"\r
207 "cmpxchgq %3, %1 "\r
208 : "=a" (CompareValue), // %0\r
209 "=m" (*Value) // %1\r
210 : "a" (CompareValue), // %2\r
9095d37b 211 "r" (ExchangeValue), // %3\r
cf683fed 212 "m" (*Value)\r
213 : "memory",\r
214 "cc"\r
215 );\r
9095d37b 216\r
cf683fed 217 return CompareValue;\r
cf683fed 218}\r
219\r
220\r