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