]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/Ia32/DisablePaging32.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / DisablePaging32.c
1 /** @file
2 AsmDisablePaging32 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 Disables the 32-bit paging mode on the CPU.
13
14 Disables the 32-bit paging mode on the CPU and returns to 32-bit protected
15 mode. This function assumes the current execution mode is 32-paged protected
16 mode. This function is only available on IA-32. After the 32-bit paging mode
17 is disabled, control is transferred to the function specified by EntryPoint
18 using the new stack specified by NewStack and passing in the parameters
19 specified by Context1 and Context2. Context1 and Context2 are optional and
20 may be NULL. The function EntryPoint must never return.
21
22 There are a number of constraints that must be followed before calling this
23 function:
24 1) Interrupts must be disabled.
25 2) The caller must be in 32-bit paged mode.
26 3) CR0, CR3, and CR4 must be compatible with 32-bit paged mode.
27 4) CR3 must point to valid page tables that guarantee that the pages for
28 this function and the stack are identity mapped.
29
30 @param EntryPoint A pointer to function to call with the new stack after
31 paging is disabled.
32 @param Context1 A pointer to the context to pass into the EntryPoint
33 function as the first parameter after paging is disabled.
34 @param Context2 A pointer to the context to pass into the EntryPoint
35 function as the second parameter after paging is
36 disabled.
37 @param NewStack A pointer to the new stack to use for the EntryPoint
38 function after paging is disabled.
39
40 **/
41 __declspec (naked)
42 VOID
43 EFIAPI
44 InternalX86DisablePaging32 (
45 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
46 IN VOID *Context1, OPTIONAL
47 IN VOID *Context2, OPTIONAL
48 IN VOID *NewStack
49 )
50 {
51 _asm {
52 push ebp
53 mov ebp, esp
54 mov ebx, EntryPoint
55 mov ecx, Context1
56 mov edx, Context2
57 pushfd
58 pop edi // save EFLAGS to edi
59 cli
60 mov eax, cr0
61 btr eax, 31
62 mov esp, NewStack
63 mov cr0, eax
64 push edi
65 popfd // restore EFLAGS from edi
66 push edx
67 push ecx
68 call ebx
69 jmp $ // EntryPoint() should not return
70 }
71 }