]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/EnablePaging32.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / EnablePaging32.c
1 /** @file
2 AsmEnablePaging32 function
3
4 Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "BaseLibInternals.h"
10
11 /**
12 Enables the 32-bit paging mode on the CPU.
13
14 Enables the 32-bit paging mode on the CPU. CR0, CR3, CR4, and the page tables
15 must be properly initialized prior to calling this service. This function
16 assumes the current execution mode is 32-bit protected mode. This function is
17 only available on IA-32. After the 32-bit paging mode is enabled, control is
18 transferred to the function specified by EntryPoint using the new stack
19 specified by NewStack and passing in the parameters specified by Context1 and
20 Context2. Context1 and Context2 are optional and may be NULL. The function
21 EntryPoint must never return.
22
23 There are a number of constraints that must be followed before calling this
24 function:
25 1) Interrupts must be disabled.
26 2) The caller must be in 32-bit protected mode with flat descriptors. This
27 means all descriptors must have a base of 0 and a limit of 4GB.
28 3) CR0 and CR4 must be compatible with 32-bit protected mode with flat
29 descriptors.
30 4) CR3 must point to valid page tables that will be used once the transition
31 is complete, and those page tables must guarantee that the pages for this
32 function and the stack are identity mapped.
33
34 @param EntryPoint A pointer to function to call with the new stack after
35 paging is enabled.
36 @param Context1 A pointer to the context to pass into the EntryPoint
37 function as the first parameter after paging is enabled.
38 @param Context2 A pointer to the context to pass into the EntryPoint
39 function as the second parameter after paging is enabled.
40 @param NewStack A pointer to the new stack to use for the EntryPoint
41 function after paging is enabled.
42
43 **/
44 __declspec(naked)
45 VOID
46 EFIAPI
47 InternalX86EnablePaging32 (
48 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
49 IN VOID *Context1 OPTIONAL,
50 IN VOID *Context2 OPTIONAL,
51 IN VOID *NewStack
52 )
53 {
54 _asm {
55 push ebp
56 mov ebp, esp
57 mov ebx, EntryPoint
58 mov ecx, Context1
59 mov edx, Context2
60 pushfd
61 pop edi
62 cli
63 mov eax, cr0
64 bts eax, 31
65 mov esp, NewStack
66 mov cr0, eax
67 push edi
68 popfd
69 push edx
70 push ecx
71 call ebx
72 jmp $
73 }
74 }