]>
Commit | Line | Data |
---|---|---|
e1f414b6 | 1 | /** @file\r |
2 | Declaration of internal functions in BaseLib.\r | |
3 | \r | |
24dcb5e5 | 4 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r |
e1f414b6 | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
e1f414b6 | 13 | **/\r |
14 | \r | |
15 | #ifndef __BASE_LIB_INTERNALS__\r | |
16 | #define __BASE_LIB_INTERNALS__\r | |
17 | \r | |
f734a10a A |
18 | #include <Base.h>\r |
19 | #include <Library/BaseLib.h>\r | |
20 | #include <Library/BaseMemoryLib.h>\r | |
21 | #include <Library/DebugLib.h>\r | |
22 | #include <Library/TimerLib.h>\r | |
23 | #include <Library/PcdLib.h>\r | |
24 | \r | |
e1f414b6 | 25 | //\r |
26 | // Math functions\r | |
27 | //\r | |
28 | \r | |
29 | /**\r | |
30 | Shifts a 64-bit integer left between 0 and 63 bits. The low bits\r | |
31 | are filled with zeros. The shifted value is returned.\r | |
32 | \r | |
33 | This function shifts the 64-bit value Operand to the left by Count bits. The\r | |
34 | low Count bits are set to zero. The shifted value is returned.\r | |
35 | \r | |
36 | @param Operand The 64-bit operand to shift left.\r | |
37 | @param Count The number of bits to shift left.\r | |
38 | \r | |
39 | @return Operand << Count\r | |
40 | \r | |
41 | **/\r | |
42 | UINT64\r | |
43 | EFIAPI\r | |
44 | InternalMathLShiftU64 (\r | |
45 | IN UINT64 Operand,\r | |
46 | IN UINTN Count\r | |
47 | );\r | |
48 | \r | |
49 | /**\r | |
50 | Shifts a 64-bit integer right between 0 and 63 bits. This high bits\r | |
51 | are filled with zeros. The shifted value is returned.\r | |
52 | \r | |
53 | This function shifts the 64-bit value Operand to the right by Count bits. The\r | |
54 | high Count bits are set to zero. The shifted value is returned.\r | |
55 | \r | |
56 | @param Operand The 64-bit operand to shift right.\r | |
57 | @param Count The number of bits to shift right.\r | |
58 | \r | |
59 | @return Operand >> Count\r | |
60 | \r | |
61 | **/\r | |
62 | UINT64\r | |
63 | EFIAPI\r | |
64 | InternalMathRShiftU64 (\r | |
65 | IN UINT64 Operand,\r | |
66 | IN UINTN Count\r | |
67 | );\r | |
68 | \r | |
69 | /**\r | |
70 | Shifts a 64-bit integer right between 0 and 63 bits. The high bits\r | |
71 | are filled with original integer's bit 63. The shifted value is returned.\r | |
72 | \r | |
73 | This function shifts the 64-bit value Operand to the right by Count bits. The\r | |
74 | high Count bits are set to bit 63 of Operand. The shifted value is returned.\r | |
75 | \r | |
76 | @param Operand The 64-bit operand to shift right.\r | |
77 | @param Count The number of bits to shift right.\r | |
78 | \r | |
79 | @return Operand arithmetically shifted right by Count\r | |
80 | \r | |
81 | **/\r | |
82 | UINT64\r | |
83 | EFIAPI\r | |
84 | InternalMathARShiftU64 (\r | |
85 | IN UINT64 Operand,\r | |
86 | IN UINTN Count\r | |
87 | );\r | |
88 | \r | |
89 | /**\r | |
90 | Rotates a 64-bit integer left between 0 and 63 bits, filling\r | |
91 | the low bits with the high bits that were rotated.\r | |
92 | \r | |
93 | This function rotates the 64-bit value Operand to the left by Count bits. The\r | |
94 | low Count bits are fill with the high Count bits of Operand. The rotated\r | |
95 | value is returned.\r | |
96 | \r | |
97 | @param Operand The 64-bit operand to rotate left.\r | |
98 | @param Count The number of bits to rotate left.\r | |
99 | \r | |
100 | @return Operand <<< Count\r | |
101 | \r | |
102 | **/\r | |
103 | UINT64\r | |
104 | EFIAPI\r | |
105 | InternalMathLRotU64 (\r | |
106 | IN UINT64 Operand,\r | |
107 | IN UINTN Count\r | |
108 | );\r | |
109 | \r | |
110 | /**\r | |
111 | Rotates a 64-bit integer right between 0 and 63 bits, filling\r | |
112 | the high bits with the high low bits that were rotated.\r | |
113 | \r | |
114 | This function rotates the 64-bit value Operand to the right by Count bits.\r | |
115 | The high Count bits are fill with the low Count bits of Operand. The rotated\r | |
116 | value is returned.\r | |
117 | \r | |
118 | @param Operand The 64-bit operand to rotate right.\r | |
119 | @param Count The number of bits to rotate right.\r | |
120 | \r | |
121 | @return Operand >>> Count\r | |
122 | \r | |
123 | **/\r | |
124 | UINT64\r | |
125 | EFIAPI\r | |
126 | InternalMathRRotU64 (\r | |
127 | IN UINT64 Operand,\r | |
128 | IN UINTN Count\r | |
129 | );\r | |
130 | \r | |
131 | /**\r | |
132 | Switches the endianess of a 64-bit integer.\r | |
133 | \r | |
134 | This function swaps the bytes in a 64-bit unsigned value to switch the value\r | |
135 | from little endian to big endian or vice versa. The byte swapped value is\r | |
136 | returned.\r | |
137 | \r | |
138 | @param Operand A 64-bit unsigned value.\r | |
139 | \r | |
24dcb5e5 | 140 | @return The byte swapped Operand.\r |
e1f414b6 | 141 | \r |
142 | **/\r | |
143 | UINT64\r | |
144 | EFIAPI\r | |
145 | InternalMathSwapBytes64 (\r | |
146 | IN UINT64 Operand\r | |
147 | );\r | |
148 | \r | |
149 | /**\r | |
150 | Multiples a 64-bit unsigned integer by a 32-bit unsigned integer\r | |
151 | and generates a 64-bit unsigned result.\r | |
152 | \r | |
153 | This function multiples the 64-bit unsigned value Multiplicand by the 32-bit\r | |
154 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r | |
155 | bit unsigned result is returned.\r | |
156 | \r | |
157 | @param Multiplicand A 64-bit unsigned value.\r | |
158 | @param Multiplier A 32-bit unsigned value.\r | |
159 | \r | |
160 | @return Multiplicand * Multiplier\r | |
161 | \r | |
162 | **/\r | |
163 | UINT64\r | |
164 | EFIAPI\r | |
165 | InternalMathMultU64x32 (\r | |
166 | IN UINT64 Multiplicand,\r | |
167 | IN UINT32 Multiplier\r | |
168 | );\r | |
169 | \r | |
170 | /**\r | |
171 | Multiples a 64-bit unsigned integer by a 64-bit unsigned integer\r | |
172 | and generates a 64-bit unsigned result.\r | |
173 | \r | |
174 | This function multiples the 64-bit unsigned value Multiplicand by the 64-bit\r | |
175 | unsigned value Multiplier and generates a 64-bit unsigned result. This 64-\r | |
176 | bit unsigned result is returned.\r | |
177 | \r | |
178 | @param Multiplicand A 64-bit unsigned value.\r | |
179 | @param Multiplier A 64-bit unsigned value.\r | |
180 | \r | |
181 | @return Multiplicand * Multiplier\r | |
182 | \r | |
183 | **/\r | |
184 | UINT64\r | |
185 | EFIAPI\r | |
186 | InternalMathMultU64x64 (\r | |
187 | IN UINT64 Multiplicand,\r | |
188 | IN UINT64 Multiplier\r | |
189 | );\r | |
190 | \r | |
191 | /**\r | |
192 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
193 | generates a 64-bit unsigned result.\r | |
194 | \r | |
195 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
196 | unsigned value Divisor and generates a 64-bit unsigned quotient. This\r | |
197 | function returns the 64-bit unsigned quotient.\r | |
198 | \r | |
24dcb5e5 | 199 | @param Dividend A 64-bit unsigned value.\r |
e1f414b6 | 200 | @param Divisor A 32-bit unsigned value.\r |
201 | \r | |
202 | @return Dividend / Divisor\r | |
203 | \r | |
204 | **/\r | |
205 | UINT64\r | |
206 | EFIAPI\r | |
207 | InternalMathDivU64x32 (\r | |
208 | IN UINT64 Dividend,\r | |
209 | IN UINT32 Divisor\r | |
210 | );\r | |
211 | \r | |
212 | /**\r | |
213 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
214 | generates a 32-bit unsigned remainder.\r | |
215 | \r | |
216 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
217 | unsigned value Divisor and generates a 32-bit remainder. This function\r | |
218 | returns the 32-bit unsigned remainder.\r | |
219 | \r | |
220 | @param Dividend A 64-bit unsigned value.\r | |
221 | @param Divisor A 32-bit unsigned value.\r | |
222 | \r | |
223 | @return Dividend % Divisor\r | |
224 | \r | |
225 | **/\r | |
226 | UINT32\r | |
227 | EFIAPI\r | |
228 | InternalMathModU64x32 (\r | |
229 | IN UINT64 Dividend,\r | |
230 | IN UINT32 Divisor\r | |
231 | );\r | |
232 | \r | |
233 | /**\r | |
234 | Divides a 64-bit unsigned integer by a 32-bit unsigned integer and\r | |
235 | generates a 64-bit unsigned result and an optional 32-bit unsigned remainder.\r | |
236 | \r | |
237 | This function divides the 64-bit unsigned value Dividend by the 32-bit\r | |
238 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r | |
239 | is not NULL, then the 32-bit unsigned remainder is returned in Remainder.\r | |
240 | This function returns the 64-bit unsigned quotient.\r | |
241 | \r | |
242 | @param Dividend A 64-bit unsigned value.\r | |
243 | @param Divisor A 32-bit unsigned value.\r | |
244 | @param Remainder A pointer to a 32-bit unsigned value. This parameter is\r | |
245 | optional and may be NULL.\r | |
246 | \r | |
247 | @return Dividend / Divisor\r | |
248 | \r | |
249 | **/\r | |
250 | UINT64\r | |
251 | EFIAPI\r | |
252 | InternalMathDivRemU64x32 (\r | |
253 | IN UINT64 Dividend,\r | |
254 | IN UINT32 Divisor,\r | |
42eedea9 | 255 | OUT UINT32 *Remainder OPTIONAL\r |
e1f414b6 | 256 | );\r |
257 | \r | |
258 | /**\r | |
259 | Divides a 64-bit unsigned integer by a 64-bit unsigned integer and\r | |
260 | generates a 64-bit unsigned result and an optional 64-bit unsigned remainder.\r | |
261 | \r | |
262 | This function divides the 64-bit unsigned value Dividend by the 64-bit\r | |
263 | unsigned value Divisor and generates a 64-bit unsigned quotient. If Remainder\r | |
264 | is not NULL, then the 64-bit unsigned remainder is returned in Remainder.\r | |
265 | This function returns the 64-bit unsigned quotient.\r | |
266 | \r | |
267 | @param Dividend A 64-bit unsigned value.\r | |
268 | @param Divisor A 64-bit unsigned value.\r | |
269 | @param Remainder A pointer to a 64-bit unsigned value. This parameter is\r | |
270 | optional and may be NULL.\r | |
271 | \r | |
272 | @return Dividend / Divisor\r | |
273 | \r | |
274 | **/\r | |
275 | UINT64\r | |
276 | EFIAPI\r | |
277 | InternalMathDivRemU64x64 (\r | |
278 | IN UINT64 Dividend,\r | |
279 | IN UINT64 Divisor,\r | |
42eedea9 | 280 | OUT UINT64 *Remainder OPTIONAL\r |
e1f414b6 | 281 | );\r |
282 | \r | |
283 | /**\r | |
284 | Divides a 64-bit signed integer by a 64-bit signed integer and\r | |
24dcb5e5 | 285 | generates a 64-bit signed result and an optional 64-bit signed remainder.\r |
e1f414b6 | 286 | \r |
24dcb5e5 | 287 | This function divides the 64-bit signed value Dividend by the 64-bit\r |
288 | signed value Divisor and generates a 64-bit signed quotient. If Remainder\r | |
289 | is not NULL, then the 64-bit signed remainder is returned in Remainder.\r | |
290 | This function returns the 64-bit signed quotient.\r | |
e1f414b6 | 291 | \r |
292 | @param Dividend A 64-bit signed value.\r | |
293 | @param Divisor A 64-bit signed value.\r | |
294 | @param Remainder A pointer to a 64-bit signed value. This parameter is\r | |
295 | optional and may be NULL.\r | |
296 | \r | |
297 | @return Dividend / Divisor\r | |
298 | \r | |
299 | **/\r | |
300 | INT64\r | |
38bbd3d9 | 301 | EFIAPI\r |
e1f414b6 | 302 | InternalMathDivRemS64x64 (\r |
303 | IN INT64 Dividend,\r | |
304 | IN INT64 Divisor,\r | |
305 | OUT INT64 *Remainder OPTIONAL\r | |
306 | );\r | |
307 | \r | |
308 | /**\r | |
309 | Transfers control to a function starting with a new stack.\r | |
310 | \r | |
311 | Transfers control to the function specified by EntryPoint using the\r | |
312 | new stack specified by NewStack and passing in the parameters specified\r | |
313 | by Context1 and Context2. Context1 and Context2 are optional and may\r | |
314 | be NULL. The function EntryPoint must never return.\r | |
315 | Marker will be ignored on IA-32, x64, and EBC.\r | |
316 | IPF CPUs expect one additional parameter of type VOID * that specifies\r | |
317 | the new backing store pointer.\r | |
318 | \r | |
319 | If EntryPoint is NULL, then ASSERT().\r | |
320 | If NewStack is NULL, then ASSERT().\r | |
321 | \r | |
322 | @param EntryPoint A pointer to function to call with the new stack.\r | |
323 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
324 | function.\r | |
325 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
326 | function.\r | |
327 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
328 | function.\r | |
329 | @param Marker VA_LIST marker for the variable argument list.\r | |
330 | \r | |
331 | **/\r | |
332 | VOID\r | |
333 | EFIAPI\r | |
334 | InternalSwitchStack (\r | |
335 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
336 | IN VOID *Context1, OPTIONAL\r | |
337 | IN VOID *Context2, OPTIONAL\r | |
338 | IN VOID *NewStack,\r | |
339 | IN VA_LIST Marker\r | |
340 | );\r | |
341 | \r | |
342 | \r | |
343 | /**\r | |
24dcb5e5 | 344 | Worker function that locates the Node in the List.\r |
e1f414b6 | 345 | \r |
346 | By searching the List, finds the location of the Node in List. At the same time,\r | |
347 | verifies the validity of this list.\r | |
348 | \r | |
349 | If List is NULL, then ASSERT().\r | |
350 | If List->ForwardLink is NULL, then ASSERT().\r | |
351 | If List->backLink is NULL, then ASSERT().\r | |
352 | If Node is NULL, then ASSERT();\r | |
353 | If PcdMaximumLinkedListLenth is not zero, and prior to insertion the number\r | |
354 | of nodes in ListHead, including the ListHead node, is greater than or\r | |
355 | equal to PcdMaximumLinkedListLength, then ASSERT().\r | |
356 | \r | |
357 | @param List A pointer to a node in a linked list.\r | |
358 | @param Node A pointer to one nod.\r | |
359 | \r | |
360 | @retval TRUE Node is in List\r | |
361 | @retval FALSE Node isn't in List, or List is invalid\r | |
362 | \r | |
363 | **/\r | |
364 | BOOLEAN\r | |
38bbd3d9 | 365 | EFIAPI\r |
e1f414b6 | 366 | IsNodeInList (\r |
367 | IN CONST LIST_ENTRY *List,\r | |
368 | IN CONST LIST_ENTRY *Node\r | |
369 | );\r | |
370 | \r | |
371 | \r | |
372 | /**\r | |
373 | Performs an atomic increment of an 32-bit unsigned integer.\r | |
374 | \r | |
375 | Performs an atomic increment of the 32-bit unsigned integer specified by\r | |
376 | Value and returns the incremented value. The increment operation must be\r | |
377 | performed using MP safe mechanisms. The state of the return value is not\r | |
378 | guaranteed to be MP safe.\r | |
379 | \r | |
380 | @param Value A pointer to the 32-bit value to increment.\r | |
381 | \r | |
382 | @return The incremented value.\r | |
383 | \r | |
384 | **/\r | |
385 | UINT32\r | |
386 | EFIAPI\r | |
387 | InternalSyncIncrement (\r | |
388 | IN volatile UINT32 *Value\r | |
389 | );\r | |
390 | \r | |
391 | \r | |
392 | /**\r | |
393 | Performs an atomic decrement of an 32-bit unsigned integer.\r | |
394 | \r | |
395 | Performs an atomic decrement of the 32-bit unsigned integer specified by\r | |
396 | Value and returns the decrement value. The decrement operation must be\r | |
397 | performed using MP safe mechanisms. The state of the return value is not\r | |
398 | guaranteed to be MP safe.\r | |
399 | \r | |
400 | @param Value A pointer to the 32-bit value to decrement.\r | |
401 | \r | |
402 | @return The decrement value.\r | |
403 | \r | |
404 | **/\r | |
405 | UINT32\r | |
406 | EFIAPI\r | |
407 | InternalSyncDecrement (\r | |
408 | IN volatile UINT32 *Value\r | |
409 | );\r | |
410 | \r | |
411 | \r | |
412 | /**\r | |
413 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
414 | \r | |
415 | Performs an atomic compare exchange operation on the 32-bit unsigned integer\r | |
416 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
417 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
418 | then Value is returned. The compare exchange operation must be performed using\r | |
419 | MP safe mechanisms.\r | |
420 | \r | |
421 | @param Value A pointer to the 32-bit value for the compare exchange\r | |
422 | operation.\r | |
423 | @param CompareValue 32-bit value used in compare operation.\r | |
424 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
425 | \r | |
426 | @return The original *Value before exchange.\r | |
427 | \r | |
428 | **/\r | |
429 | UINT32\r | |
430 | EFIAPI\r | |
431 | InternalSyncCompareExchange32 (\r | |
432 | IN volatile UINT32 *Value,\r | |
433 | IN UINT32 CompareValue,\r | |
434 | IN UINT32 ExchangeValue\r | |
435 | );\r | |
436 | \r | |
437 | \r | |
438 | /**\r | |
439 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
440 | \r | |
441 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
442 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
443 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
444 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
445 | \r | |
446 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
447 | operation.\r | |
448 | @param CompareValue 64-bit value used in compare operation.\r | |
449 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
450 | \r | |
451 | @return The original *Value before exchange.\r | |
452 | \r | |
453 | **/\r | |
454 | UINT64\r | |
455 | EFIAPI\r | |
456 | InternalSyncCompareExchange64 (\r | |
457 | IN volatile UINT64 *Value,\r | |
458 | IN UINT64 CompareValue,\r | |
459 | IN UINT64 ExchangeValue\r | |
460 | );\r | |
461 | \r | |
462 | \r | |
463 | /**\r | |
24dcb5e5 | 464 | Worker function that returns a bit field from Operand.\r |
e1f414b6 | 465 | \r |
466 | Returns the bitfield specified by the StartBit and the EndBit from Operand.\r | |
467 | \r | |
468 | @param Operand Operand on which to perform the bitfield operation.\r | |
469 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
470 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
471 | \r | |
472 | @return The bit field read.\r | |
473 | \r | |
474 | **/\r | |
28ca72bc | 475 | UINTN\r |
38bbd3d9 | 476 | EFIAPI\r |
e1f414b6 | 477 | BitFieldReadUint (\r |
28ca72bc | 478 | IN UINTN Operand,\r |
e1f414b6 | 479 | IN UINTN StartBit,\r |
480 | IN UINTN EndBit\r | |
481 | );\r | |
482 | \r | |
483 | \r | |
484 | /**\r | |
485 | Worker function that reads a bit field from Operand, performs a bitwise OR,\r | |
486 | and returns the result.\r | |
487 | \r | |
488 | Performs a bitwise OR between the bit field specified by StartBit and EndBit\r | |
489 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
490 | preserved. The new value is returned.\r | |
491 | \r | |
492 | @param Operand Operand on which to perform the bitfield operation.\r | |
493 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
494 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
495 | @param OrData The value to OR with the read value from the value\r | |
496 | \r | |
497 | @return The new value.\r | |
498 | \r | |
499 | **/\r | |
28ca72bc | 500 | UINTN\r |
38bbd3d9 | 501 | EFIAPI\r |
e1f414b6 | 502 | BitFieldOrUint (\r |
28ca72bc | 503 | IN UINTN Operand,\r |
e1f414b6 | 504 | IN UINTN StartBit,\r |
505 | IN UINTN EndBit,\r | |
28ca72bc | 506 | IN UINTN OrData\r |
e1f414b6 | 507 | );\r |
508 | \r | |
509 | \r | |
510 | /**\r | |
511 | Worker function that reads a bit field from Operand, performs a bitwise AND,\r | |
512 | and returns the result.\r | |
513 | \r | |
514 | Performs a bitwise AND between the bit field specified by StartBit and EndBit\r | |
515 | in Operand and the value specified by AndData. All other bits in Operand are\r | |
516 | preserved. The new value is returned.\r | |
517 | \r | |
518 | @param Operand Operand on which to perform the bitfield operation.\r | |
519 | @param StartBit The ordinal of the least significant bit in the bit field.\r | |
520 | @param EndBit The ordinal of the most significant bit in the bit field.\r | |
521 | @param AndData The value to And with the read value from the value\r | |
522 | \r | |
523 | @return The new value.\r | |
524 | \r | |
525 | **/\r | |
28ca72bc | 526 | UINTN\r |
38bbd3d9 | 527 | EFIAPI\r |
e1f414b6 | 528 | BitFieldAndUint (\r |
28ca72bc | 529 | IN UINTN Operand,\r |
e1f414b6 | 530 | IN UINTN StartBit,\r |
531 | IN UINTN EndBit,\r | |
28ca72bc | 532 | IN UINTN AndData\r |
e1f414b6 | 533 | );\r |
534 | \r | |
535 | \r | |
536 | /**\r | |
537 | Worker function that checks ASSERT condition for JumpBuffer\r | |
538 | \r | |
539 | Checks ASSERT condition for JumpBuffer.\r | |
540 | \r | |
541 | If JumpBuffer is NULL, then ASSERT().\r | |
542 | For IPF CPUs, if JumpBuffer is not aligned on a 16-byte boundary, then ASSERT().\r | |
543 | \r | |
544 | @param JumpBuffer A pointer to CPU context buffer.\r | |
545 | \r | |
546 | **/\r | |
547 | VOID\r | |
38bbd3d9 | 548 | EFIAPI\r |
e1f414b6 | 549 | InternalAssertJumpBuffer (\r |
550 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer\r | |
551 | );\r | |
552 | \r | |
553 | \r | |
554 | /**\r | |
555 | Restores the CPU context that was saved with SetJump().\r | |
556 | \r | |
557 | Restores the CPU context from the buffer specified by JumpBuffer.\r | |
558 | This function never returns to the caller.\r | |
559 | Instead is resumes execution based on the state of JumpBuffer.\r | |
560 | \r | |
561 | @param JumpBuffer A pointer to CPU context buffer.\r | |
562 | @param Value The value to return when the SetJump() context is restored.\r | |
563 | \r | |
564 | **/\r | |
565 | VOID\r | |
566 | EFIAPI\r | |
567 | InternalLongJump (\r | |
568 | IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer,\r | |
569 | IN UINTN Value\r | |
570 | );\r | |
571 | \r | |
572 | \r | |
573 | //\r | |
574 | // Ia32 and x64 specific functions\r | |
575 | //\r | |
576 | #if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)\r | |
577 | \r | |
578 | /**\r | |
579 | Reads the current Global Descriptor Table Register(GDTR) descriptor.\r | |
580 | \r | |
581 | Reads and returns the current GDTR descriptor and returns it in Gdtr. This\r | |
582 | function is only available on IA-32 and X64.\r | |
583 | \r | |
584 | @param Gdtr Pointer to a GDTR descriptor.\r | |
585 | \r | |
586 | **/\r | |
587 | VOID\r | |
588 | EFIAPI\r | |
589 | InternalX86ReadGdtr (\r | |
590 | OUT IA32_DESCRIPTOR *Gdtr\r | |
591 | );\r | |
592 | \r | |
593 | /**\r | |
594 | Writes the current Global Descriptor Table Register (GDTR) descriptor.\r | |
595 | \r | |
596 | Writes and the current GDTR descriptor specified by Gdtr. This function is\r | |
597 | only available on IA-32 and X64.\r | |
598 | \r | |
599 | @param Gdtr Pointer to a GDTR descriptor.\r | |
600 | \r | |
601 | **/\r | |
602 | VOID\r | |
603 | EFIAPI\r | |
604 | InternalX86WriteGdtr (\r | |
605 | IN CONST IA32_DESCRIPTOR *Gdtr\r | |
606 | );\r | |
607 | \r | |
608 | /**\r | |
609 | Reads the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
610 | \r | |
611 | Reads and returns the current IDTR descriptor and returns it in Idtr. This\r | |
612 | function is only available on IA-32 and X64.\r | |
613 | \r | |
614 | @param Idtr Pointer to a IDTR descriptor.\r | |
615 | \r | |
616 | **/\r | |
617 | VOID\r | |
618 | EFIAPI\r | |
619 | InternalX86ReadIdtr (\r | |
620 | OUT IA32_DESCRIPTOR *Idtr\r | |
621 | );\r | |
622 | \r | |
623 | /**\r | |
624 | Writes the current Interrupt Descriptor Table Register(GDTR) descriptor.\r | |
625 | \r | |
626 | Writes the current IDTR descriptor and returns it in Idtr. This function is\r | |
627 | only available on IA-32 and X64.\r | |
628 | \r | |
629 | @param Idtr Pointer to a IDTR descriptor.\r | |
630 | \r | |
631 | **/\r | |
632 | VOID\r | |
633 | EFIAPI\r | |
634 | InternalX86WriteIdtr (\r | |
635 | IN CONST IA32_DESCRIPTOR *Idtr\r | |
636 | );\r | |
637 | \r | |
638 | /**\r | |
639 | Save the current floating point/SSE/SSE2 context to a buffer.\r | |
640 | \r | |
641 | Saves the current floating point/SSE/SSE2 state to the buffer specified by\r | |
642 | Buffer. Buffer must be aligned on a 16-byte boundary. This function is only\r | |
643 | available on IA-32 and X64.\r | |
644 | \r | |
645 | @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.\r | |
646 | \r | |
647 | **/\r | |
648 | VOID\r | |
649 | EFIAPI\r | |
650 | InternalX86FxSave (\r | |
651 | OUT IA32_FX_BUFFER *Buffer\r | |
652 | );\r | |
653 | \r | |
654 | /**\r | |
655 | Restores the current floating point/SSE/SSE2 context from a buffer.\r | |
656 | \r | |
657 | Restores the current floating point/SSE/SSE2 state from the buffer specified\r | |
658 | by Buffer. Buffer must be aligned on a 16-byte boundary. This function is\r | |
659 | only available on IA-32 and X64.\r | |
660 | \r | |
661 | @param Buffer Pointer to a buffer to save the floating point/SSE/SSE2 context.\r | |
662 | \r | |
663 | **/\r | |
664 | VOID\r | |
665 | EFIAPI\r | |
666 | InternalX86FxRestore (\r | |
667 | IN CONST IA32_FX_BUFFER *Buffer\r | |
668 | );\r | |
669 | \r | |
670 | /**\r | |
671 | Enables the 32-bit paging mode on the CPU.\r | |
672 | \r | |
673 | Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
674 | must be properly initialized prior to calling this service. This function\r | |
675 | assumes the current execution mode is 32-bit protected mode. This function is\r | |
676 | only available on IA-32. After the 32-bit paging mode is enabled, control is\r | |
677 | transferred to the function specified by EntryPoint using the new stack\r | |
678 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
679 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
680 | EntryPoint must never return.\r | |
681 | \r | |
682 | There are a number of constraints that must be followed before calling this\r | |
683 | function:\r | |
684 | 1) Interrupts must be disabled.\r | |
685 | 2) The caller must be in 32-bit protected mode with flat descriptors. This\r | |
686 | means all descriptors must have a base of 0 and a limit of 4GB.\r | |
687 | 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat\r | |
688 | descriptors.\r | |
689 | 4) CR3 must point to valid page tables that will be used once the transition\r | |
690 | is complete, and those page tables must guarantee that the pages for this\r | |
691 | function and the stack are identity mapped.\r | |
692 | \r | |
693 | @param EntryPoint A pointer to function to call with the new stack after\r | |
694 | paging is enabled.\r | |
695 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
696 | function as the first parameter after paging is enabled.\r | |
697 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
698 | function as the second parameter after paging is enabled.\r | |
699 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
700 | function after paging is enabled.\r | |
701 | \r | |
702 | **/\r | |
703 | VOID\r | |
704 | EFIAPI\r | |
705 | InternalX86EnablePaging32 (\r | |
706 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
707 | IN VOID *Context1, OPTIONAL\r | |
708 | IN VOID *Context2, OPTIONAL\r | |
709 | IN VOID *NewStack\r | |
710 | );\r | |
711 | \r | |
712 | /**\r | |
713 | Disables the 32-bit paging mode on the CPU.\r | |
714 | \r | |
715 | Disables the 32-bit paging mode on the CPU and returns to 32-bit protected\r | |
716 | mode. This function assumes the current execution mode is 32-paged protected\r | |
717 | mode. This function is only available on IA-32. After the 32-bit paging mode\r | |
718 | is disabled, control is transferred to the function specified by EntryPoint\r | |
719 | using the new stack specified by NewStack and passing in the parameters\r | |
720 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
721 | may be NULL. The function EntryPoint must never return.\r | |
722 | \r | |
723 | There are a number of constraints that must be followed before calling this\r | |
724 | function:\r | |
725 | 1) Interrupts must be disabled.\r | |
726 | 2) The caller must be in 32-bit paged mode.\r | |
727 | 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.\r | |
728 | 4) CR3 must point to valid page tables that guarantee that the pages for\r | |
729 | this function and the stack are identity mapped.\r | |
730 | \r | |
731 | @param EntryPoint A pointer to function to call with the new stack after\r | |
732 | paging is disabled.\r | |
733 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
734 | function as the first parameter after paging is disabled.\r | |
735 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
736 | function as the second parameter after paging is\r | |
737 | disabled.\r | |
738 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
739 | function after paging is disabled.\r | |
740 | \r | |
741 | **/\r | |
742 | VOID\r | |
743 | EFIAPI\r | |
744 | InternalX86DisablePaging32 (\r | |
745 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
746 | IN VOID *Context1, OPTIONAL\r | |
747 | IN VOID *Context2, OPTIONAL\r | |
748 | IN VOID *NewStack\r | |
749 | );\r | |
750 | \r | |
751 | /**\r | |
752 | Enables the 64-bit paging mode on the CPU.\r | |
753 | \r | |
754 | Enables the 64-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables\r | |
755 | must be properly initialized prior to calling this service. This function\r | |
756 | assumes the current execution mode is 32-bit protected mode with flat\r | |
757 | descriptors. This function is only available on IA-32. After the 64-bit\r | |
758 | paging mode is enabled, control is transferred to the function specified by\r | |
759 | EntryPoint using the new stack specified by NewStack and passing in the\r | |
760 | parameters specified by Context1 and Context2. Context1 and Context2 are\r | |
761 | optional and may be 0. The function EntryPoint must never return.\r | |
762 | \r | |
763 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
764 | is called. The descriptor in the GDT that this selector\r | |
765 | references must be setup for long mode.\r | |
766 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
767 | the new stack after paging is enabled.\r | |
768 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
769 | the EntryPoint function as the first parameter after\r | |
770 | paging is enabled.\r | |
771 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
772 | the EntryPoint function as the second parameter after\r | |
773 | paging is enabled.\r | |
774 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
775 | the EntryPoint function after paging is enabled.\r | |
776 | \r | |
777 | **/\r | |
778 | VOID\r | |
779 | EFIAPI\r | |
780 | InternalX86EnablePaging64 (\r | |
781 | IN UINT16 Cs,\r | |
782 | IN UINT64 EntryPoint,\r | |
783 | IN UINT64 Context1, OPTIONAL\r | |
784 | IN UINT64 Context2, OPTIONAL\r | |
785 | IN UINT64 NewStack\r | |
786 | );\r | |
787 | \r | |
788 | /**\r | |
789 | Disables the 64-bit paging mode on the CPU.\r | |
790 | \r | |
791 | Disables the 64-bit paging mode on the CPU and returns to 32-bit protected\r | |
792 | mode. This function assumes the current execution mode is 64-paging mode.\r | |
793 | This function is only available on X64. After the 64-bit paging mode is\r | |
794 | disabled, control is transferred to the function specified by EntryPoint\r | |
795 | using the new stack specified by NewStack and passing in the parameters\r | |
796 | specified by Context1 and Context2. Context1 and Context2 are optional and\r | |
797 | may be 0. The function EntryPoint must never return.\r | |
798 | \r | |
799 | @param Cs The 16-bit selector to load in the CS before EntryPoint\r | |
800 | is called. The descriptor in the GDT that this selector\r | |
801 | references must be setup for 32-bit protected mode.\r | |
802 | @param EntryPoint The 64-bit virtual address of the function to call with\r | |
803 | the new stack after paging is disabled.\r | |
804 | @param Context1 The 64-bit virtual address of the context to pass into\r | |
805 | the EntryPoint function as the first parameter after\r | |
806 | paging is disabled.\r | |
807 | @param Context2 The 64-bit virtual address of the context to pass into\r | |
808 | the EntryPoint function as the second parameter after\r | |
809 | paging is disabled.\r | |
810 | @param NewStack The 64-bit virtual address of the new stack to use for\r | |
811 | the EntryPoint function after paging is disabled.\r | |
812 | \r | |
813 | **/\r | |
814 | VOID\r | |
815 | EFIAPI\r | |
816 | InternalX86DisablePaging64 (\r | |
817 | IN UINT16 Cs,\r | |
818 | IN UINT32 EntryPoint,\r | |
819 | IN UINT32 Context1, OPTIONAL\r | |
820 | IN UINT32 Context2, OPTIONAL\r | |
821 | IN UINT32 NewStack\r | |
822 | );\r | |
823 | \r | |
824 | \r | |
825 | #elif defined (MDE_CPU_IPF)\r | |
826 | //\r | |
827 | //\r | |
828 | // IPF specific functions\r | |
829 | //\r | |
830 | \r | |
831 | /**\r | |
832 | Transfers control to a function starting with a new stack.\r | |
833 | \r | |
834 | Transfers control to the function specified by EntryPoint using the new stack\r | |
835 | specified by NewStack and passing in the parameters specified by Context1 and\r | |
836 | Context2. Context1 and Context2 are optional and may be NULL. The function\r | |
837 | EntryPoint must never return.\r | |
838 | \r | |
839 | If EntryPoint is NULL, then ASSERT().\r | |
840 | If NewStack is NULL, then ASSERT().\r | |
841 | \r | |
842 | @param EntryPoint A pointer to function to call with the new stack.\r | |
843 | @param Context1 A pointer to the context to pass into the EntryPoint\r | |
844 | function.\r | |
845 | @param Context2 A pointer to the context to pass into the EntryPoint\r | |
846 | function.\r | |
847 | @param NewStack A pointer to the new stack to use for the EntryPoint\r | |
848 | function.\r | |
849 | @param NewBsp A pointer to the new memory location for RSE backing\r | |
850 | store.\r | |
851 | \r | |
852 | **/\r | |
853 | VOID\r | |
854 | EFIAPI\r | |
855 | AsmSwitchStackAndBackingStore (\r | |
856 | IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r | |
857 | IN VOID *Context1, OPTIONAL\r | |
858 | IN VOID *Context2, OPTIONAL\r | |
859 | IN VOID *NewStack,\r | |
860 | IN VOID *NewBsp\r | |
861 | );\r | |
862 | #else\r | |
863 | \r | |
864 | #endif\r | |
865 | \r | |
866 | #endif\r |