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