]>
Commit | Line | Data |
---|---|---|
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 | |
9344f092 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
cf683fed | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | \r | |
11 | \r | |
cf683fed | 12 | /**\r |
13 | Performs an atomic increment of an 32-bit unsigned integer.\r | |
14 | \r | |
15 | Performs an atomic increment of the 32-bit unsigned integer specified by\r | |
16 | Value and returns the incremented value. The increment operation must be\r | |
17634d02 | 17 | performed using MP safe mechanisms.\r |
cf683fed | 18 | \r |
19 | @param Value A pointer to the 32-bit value to increment.\r | |
20 | \r | |
21 | @return The incremented value.\r | |
22 | \r | |
23 | **/\r | |
24 | UINT32\r | |
25 | EFIAPI\r | |
26 | InternalSyncIncrement (\r | |
27 | IN volatile UINT32 *Value\r | |
28 | )\r | |
29 | {\r | |
30 | UINT32 Result;\r | |
31 | \r | |
32 | __asm__ __volatile__ (\r | |
17634d02 | 33 | "movl $1, %%eax \n\t"\r |
cf683fed | 34 | "lock \n\t"\r |
8a94eb92 | 35 | "xadd %%eax, %1 \n\t"\r |
310ddb63 | 36 | "inc %%eax \n\t"\r |
e6459b9e | 37 | : "=&a" (Result), // %0\r |
8a94eb92 LE |
38 | "+m" (*Value) // %1\r |
39 | : // no inputs that aren't also outputs\r | |
cf683fed | 40 | : "memory",\r |
41 | "cc"\r | |
42 | );\r | |
9095d37b LG |
43 | \r |
44 | return Result;\r | |
cf683fed | 45 | }\r |
46 | \r | |
47 | \r | |
48 | /**\r | |
49 | Performs an atomic decrement of an 32-bit unsigned integer.\r | |
50 | \r | |
51 | Performs an atomic decrement of the 32-bit unsigned integer specified by\r | |
52 | Value and returns the decremented value. The decrement operation must be\r | |
17634d02 | 53 | performed using MP safe mechanisms.\r |
cf683fed | 54 | \r |
55 | @param Value A pointer to the 32-bit value to decrement.\r | |
56 | \r | |
57 | @return The decremented value.\r | |
58 | \r | |
59 | **/\r | |
60 | UINT32\r | |
61 | EFIAPI\r | |
62 | InternalSyncDecrement (\r | |
63 | IN volatile UINT32 *Value\r | |
64 | )\r | |
65 | {\r | |
66 | UINT32 Result;\r | |
9095d37b | 67 | \r |
cf683fed | 68 | __asm__ __volatile__ (\r |
17634d02 RN |
69 | "movl $-1, %%eax \n\t"\r |
70 | "lock \n\t"\r | |
8a94eb92 | 71 | "xadd %%eax, %1 \n\t"\r |
310ddb63 | 72 | "dec %%eax \n\t"\r |
e6459b9e | 73 | : "=&a" (Result), // %0\r |
310ddb63 LE |
74 | "+m" (*Value) // %1\r |
75 | : // no inputs that aren't also outputs\r | |
cf683fed | 76 | : "memory",\r |
77 | "cc"\r | |
78 | );\r | |
9095d37b | 79 | \r |
cf683fed | 80 | return Result;\r |
81 | }\r | |
82 | \r | |
83 | \r | |
9b89163e AB |
84 | /**\r |
85 | Performs an atomic compare exchange operation on a 16-bit unsigned integer.\r | |
86 | \r | |
87 | Performs an atomic compare exchange operation on the 16-bit unsigned integer\r | |
88 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
89 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
90 | then Value is returned. The compare exchange operation must be performed using\r | |
91 | MP safe mechanisms.\r | |
92 | \r | |
93 | \r | |
94 | @param Value A pointer to the 16-bit value for the compare exchange\r | |
95 | operation.\r | |
96 | @param CompareValue 16-bit value used in compare operation.\r | |
97 | @param ExchangeValue 16-bit value used in exchange operation.\r | |
98 | \r | |
99 | @return The original *Value before exchange.\r | |
100 | \r | |
101 | **/\r | |
102 | UINT16\r | |
103 | EFIAPI\r | |
104 | InternalSyncCompareExchange16 (\r | |
105 | IN OUT volatile UINT16 *Value,\r | |
106 | IN UINT16 CompareValue,\r | |
107 | IN UINT16 ExchangeValue\r | |
108 | )\r | |
109 | {\r | |
9b89163e AB |
110 | __asm__ __volatile__ (\r |
111 | "lock \n\t"\r | |
c6fedbd7 LE |
112 | "cmpxchgw %2, %1 \n\t"\r |
113 | : "+a" (CompareValue), // %0\r | |
114 | "+m" (*Value) // %1\r | |
115 | : "r" (ExchangeValue) // %2\r | |
9b89163e AB |
116 | : "memory",\r |
117 | "cc"\r | |
118 | );\r | |
119 | \r | |
120 | return CompareValue;\r | |
121 | }\r | |
122 | \r | |
123 | \r | |
cf683fed | 124 | /**\r |
125 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
126 | \r | |
127 | Performs an atomic compare exchange operation on the 32-bit unsigned integer\r | |
128 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
129 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
130 | then Value is returned. The compare exchange operation must be performed using\r | |
131 | MP safe mechanisms.\r | |
132 | \r | |
133 | \r | |
134 | @param Value A pointer to the 32-bit value for the compare exchange\r | |
135 | operation.\r | |
136 | @param CompareValue 32-bit value used in compare operation.\r | |
137 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
138 | \r | |
139 | @return The original *Value before exchange.\r | |
140 | \r | |
141 | **/\r | |
142 | UINT32\r | |
143 | EFIAPI\r | |
144 | InternalSyncCompareExchange32 (\r | |
145 | IN OUT volatile UINT32 *Value,\r | |
146 | IN UINT32 CompareValue,\r | |
147 | IN UINT32 ExchangeValue\r | |
148 | )\r | |
149 | {\r | |
cf683fed | 150 | __asm__ __volatile__ (\r |
151 | "lock \n\t"\r | |
7149d409 LE |
152 | "cmpxchgl %2, %1 \n\t"\r |
153 | : "+a" (CompareValue), // %0\r | |
154 | "+m" (*Value) // %1\r | |
155 | : "r" (ExchangeValue) // %2\r | |
cf683fed | 156 | : "memory",\r |
157 | "cc"\r | |
158 | );\r | |
9095d37b | 159 | \r |
4e4a5f35 | 160 | return CompareValue;\r |
cf683fed | 161 | }\r |
162 | \r | |
163 | \r | |
164 | /**\r | |
165 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
166 | \r | |
167 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
168 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
169 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
170 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
171 | \r | |
172 | \r | |
173 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
174 | operation.\r | |
175 | @param CompareValue 64-bit value used in compare operation.\r | |
176 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
177 | \r | |
178 | @return The original *Value before exchange.\r | |
179 | \r | |
180 | **/\r | |
181 | UINT64\r | |
182 | EFIAPI\r | |
183 | InternalSyncCompareExchange64 (\r | |
184 | IN OUT volatile UINT64 *Value,\r | |
185 | IN UINT64 CompareValue,\r | |
186 | IN UINT64 ExchangeValue\r | |
187 | )\r | |
188 | {\r | |
cf683fed | 189 | __asm__ __volatile__ (\r |
190 | "lock \n\t"\r | |
e5d4e750 LE |
191 | "cmpxchgq %2, %1 \n\t"\r |
192 | : "+a" (CompareValue), // %0\r | |
193 | "+m" (*Value) // %1\r | |
194 | : "r" (ExchangeValue) // %2\r | |
cf683fed | 195 | : "memory",\r |
196 | "cc"\r | |
197 | );\r | |
9095d37b | 198 | \r |
cf683fed | 199 | return CompareValue;\r |
cf683fed | 200 | }\r |