]>
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 | /**\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 | |
32 | UINT32\r | |
33 | EFIAPI\r | |
34 | InternalSyncIncrement (\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 | |
46 | : "m" (*Value) // %2 \r | |
47 | : "memory",\r | |
48 | "cc"\r | |
49 | );\r | |
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 | |
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 | "mov %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 | |
90 | \r | |
91 | /**\r | |
92 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
93 | \r | |
94 | Performs an atomic compare exchange operation on the 32-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 32-bit value for the compare exchange\r | |
102 | operation.\r | |
103 | @param CompareValue 32-bit value used in compare operation.\r | |
104 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
105 | \r | |
106 | @return The original *Value before exchange.\r | |
107 | \r | |
108 | **/\r | |
109 | UINT32\r | |
110 | EFIAPI\r | |
111 | InternalSyncCompareExchange32 (\r | |
112 | IN OUT volatile UINT32 *Value,\r | |
113 | IN UINT32 CompareValue,\r | |
114 | IN UINT32 ExchangeValue\r | |
115 | )\r | |
116 | {\r | |
cf683fed | 117 | \r |
cf683fed | 118 | \r |
119 | __asm__ __volatile__ (\r | |
120 | "lock \n\t"\r | |
121 | "cmpxchgl %3, %1 "\r | |
122 | : "=a" (CompareValue), // %0\r | |
123 | "=m" (*Value) // %1\r | |
124 | : "a" (CompareValue), // %2\r | |
125 | "r" (ExchangeValue), // %3 \r | |
126 | "m" (*Value)\r | |
127 | : "memory",\r | |
128 | "cc"\r | |
129 | );\r | |
130 | \r | |
4e4a5f35 | 131 | return CompareValue;\r |
cf683fed | 132 | }\r |
133 | \r | |
134 | \r | |
135 | /**\r | |
136 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
137 | \r | |
138 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
139 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
140 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
141 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
142 | \r | |
143 | \r | |
144 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
145 | operation.\r | |
146 | @param CompareValue 64-bit value used in compare operation.\r | |
147 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
148 | \r | |
149 | @return The original *Value before exchange.\r | |
150 | \r | |
151 | **/\r | |
152 | UINT64\r | |
153 | EFIAPI\r | |
154 | InternalSyncCompareExchange64 (\r | |
155 | IN OUT volatile UINT64 *Value,\r | |
156 | IN UINT64 CompareValue,\r | |
157 | IN UINT64 ExchangeValue\r | |
158 | )\r | |
159 | {\r | |
cf683fed | 160 | \r |
161 | __asm__ __volatile__ (\r | |
162 | "lock \n\t"\r | |
163 | "cmpxchgq %3, %1 "\r | |
164 | : "=a" (CompareValue), // %0\r | |
165 | "=m" (*Value) // %1\r | |
166 | : "a" (CompareValue), // %2\r | |
167 | "r" (ExchangeValue), // %3 \r | |
168 | "m" (*Value)\r | |
169 | : "memory",\r | |
170 | "cc"\r | |
171 | );\r | |
172 | \r | |
173 | return CompareValue;\r | |
cf683fed | 174 | }\r |
175 | \r | |
176 | \r |