]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/BaseLib/X64/DisablePaging64.nasm
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / DisablePaging64.nasm
CommitLineData
464e84f8
JJ
1;------------------------------------------------------------------------------\r
2;\r
3; Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
4; This program and the accompanying materials\r
5; are licensed and made available under the terms and conditions of the BSD License\r
6; which accompanies this distribution. The full text of the license may be found at\r
7; http://opensource.org/licenses/bsd-license.php.\r
8;\r
9; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11;\r
12; Module Name:\r
13;\r
14; DisablePaging64.Asm\r
15;\r
16; Abstract:\r
17;\r
18; AsmDisablePaging64 function\r
19;\r
20; Notes:\r
21;\r
22;------------------------------------------------------------------------------\r
23\r
24 DEFAULT REL\r
25 SECTION .text\r
26\r
27;------------------------------------------------------------------------------\r
28; VOID\r
29; EFIAPI\r
30; InternalX86DisablePaging64 (\r
31; IN UINT16 Cs,\r
32; IN UINT32 EntryPoint,\r
33; IN UINT32 Context1, OPTIONAL\r
34; IN UINT32 Context2, OPTIONAL\r
35; IN UINT32 NewStack\r
36; );\r
37;------------------------------------------------------------------------------\r
38global ASM_PFX(InternalX86DisablePaging64)\r
39ASM_PFX(InternalX86DisablePaging64):\r
40 cli\r
41 lea rsi, [.0] ; rsi <- The start address of transition code\r
42 mov edi, [rsp + 0x28] ; rdi <- New stack\r
43 lea rax, [mTransitionEnd] ; rax <- end of transition code\r
44 sub rax, rsi ; rax <- The size of transition piece code\r
45 add rax, 4 ; Round RAX up to the next 4 byte boundary\r
46 and al, 0xfc\r
47 sub rdi, rax ; rdi <- Use stack to hold transition code\r
48 mov r10d, edi ; r10 <- The start address of transicition code below 4G\r
49 push rcx ; save rcx to stack\r
50 mov rcx, rax ; rcx <- The size of transition piece code\r
51 rep movsb ; copy transition code to top of new stack which must be below 4GB\r
52 pop rcx ; restore rcx\r
53\r
54 mov esi, r8d\r
55 mov edi, r9d\r
56 mov eax, r10d ; eax <- start of the transition code on the stack\r
57 sub eax, 4 ; eax <- One slot below transition code on the stack\r
58 push rcx ; push Cs to stack\r
59 push r10 ; push address of tansition code on stack\r
60 DB 0x48 ; prefix to composite "retq" with next "retf"\r
61 retf ; Use far return to load CS register from stack\r
62\r
63; Start of transition code\r
64.0:\r
65 mov esp, eax ; set up new stack\r
66 mov rax, cr0\r
67 btr eax, 31 ; Clear CR0.PG\r
68 mov cr0, rax ; disable paging and caches\r
69\r
70 mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx\r
71 mov ecx, 0xc0000080\r
72 rdmsr\r
73 and ah, ~ 1 ; clear LME\r
74 wrmsr\r
75 mov rax, cr4\r
76 and al, ~ (1 << 5) ; clear PAE\r
77 mov cr4, rax\r
78 push rdi ; push Context2\r
79 push rsi ; push Context1\r
80 call rbx ; transfer control to EntryPoint\r
81 hlt ; no one should get here\r
82\r
83mTransitionEnd:\r
84\r