]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | GCC inline implementation of BaseSynchronizationLib processor specific functions.\r | |
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 | |
6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
7 | \r | |
8 | **/\r | |
9 | \r | |
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 | |
15 | performed using MP safe mechanisms.\r | |
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 | |
25 | IN volatile UINT32 *Value\r | |
26 | )\r | |
27 | {\r | |
28 | UINT32 Result;\r | |
29 | \r | |
30 | __asm__ __volatile__ (\r | |
31 | "movl $1, %%eax \n\t"\r | |
32 | "lock \n\t"\r | |
33 | "xadd %%eax, %1 \n\t"\r | |
34 | "inc %%eax \n\t"\r | |
35 | : "=&a" (Result), // %0\r | |
36 | "+m" (*Value) // %1\r | |
37 | : // no inputs that aren't also outputs\r | |
38 | : "memory",\r | |
39 | "cc"\r | |
40 | );\r | |
41 | \r | |
42 | return Result;\r | |
43 | }\r | |
44 | \r | |
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 | |
50 | performed using MP safe mechanisms.\r | |
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 | |
60 | IN volatile UINT32 *Value\r | |
61 | )\r | |
62 | {\r | |
63 | UINT32 Result;\r | |
64 | \r | |
65 | __asm__ __volatile__ (\r | |
66 | "movl $-1, %%eax \n\t"\r | |
67 | "lock \n\t"\r | |
68 | "xadd %%eax, %1 \n\t"\r | |
69 | "dec %%eax \n\t"\r | |
70 | : "=&a" (Result), // %0\r | |
71 | "+m" (*Value) // %1\r | |
72 | : // no inputs that aren't also outputs\r | |
73 | : "memory",\r | |
74 | "cc"\r | |
75 | );\r | |
76 | \r | |
77 | return Result;\r | |
78 | }\r | |
79 | \r | |
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 | |
101 | IN OUT volatile UINT16 *Value,\r | |
102 | IN UINT16 CompareValue,\r | |
103 | IN UINT16 ExchangeValue\r | |
104 | )\r | |
105 | {\r | |
106 | __asm__ __volatile__ (\r | |
107 | "lock \n\t"\r | |
108 | "cmpxchgw %2, %1 \n\t"\r | |
109 | : "+a" (CompareValue), // %0\r | |
110 | "+m" (*Value) // %1\r | |
111 | : "q" (ExchangeValue) // %2\r | |
112 | : "memory",\r | |
113 | "cc"\r | |
114 | );\r | |
115 | \r | |
116 | return CompareValue;\r | |
117 | }\r | |
118 | \r | |
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 | |
140 | IN OUT volatile UINT32 *Value,\r | |
141 | IN UINT32 CompareValue,\r | |
142 | IN UINT32 ExchangeValue\r | |
143 | )\r | |
144 | {\r | |
145 | __asm__ __volatile__ (\r | |
146 | "lock \n\t"\r | |
147 | "cmpxchgl %2, %1 \n\t"\r | |
148 | : "+a" (CompareValue), // %0\r | |
149 | "+m" (*Value) // %1\r | |
150 | : "q" (ExchangeValue) // %2\r | |
151 | : "memory",\r | |
152 | "cc"\r | |
153 | );\r | |
154 | \r | |
155 | return CompareValue;\r | |
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 | |
178 | IN OUT volatile UINT64 *Value,\r | |
179 | IN UINT64 CompareValue,\r | |
180 | IN UINT64 ExchangeValue\r | |
181 | )\r | |
182 | {\r | |
183 | __asm__ __volatile__ (\r | |
184 | "lock \n\t"\r | |
185 | "cmpxchg8b (%1) \n\t"\r | |
186 | : "+A" (CompareValue) // %0\r | |
187 | : "S" (Value), // %1\r | |
188 | "b" ((UINT32) ExchangeValue), // %2\r | |
189 | "c" ((UINT32) (ExchangeValue >> 32)) // %3\r | |
190 | : "memory",\r | |
191 | "cc"\r | |
192 | );\r | |
193 | \r | |
194 | return CompareValue;\r | |
195 | }\r |