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