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