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