]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BaseLib/X64/DisablePaging64.nasm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / DisablePaging64.nasm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2006 - 2022, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
5 ;
6 ; Module Name:
7 ;
8 ; DisablePaging64.Asm
9 ;
10 ; Abstract:
11 ;
12 ; AsmDisablePaging64 function
13 ;
14 ; Notes:
15 ;
16 ;------------------------------------------------------------------------------
17
18 DEFAULT REL
19 SECTION .text
20
21 ;------------------------------------------------------------------------------
22 ; VOID
23 ; EFIAPI
24 ; InternalX86DisablePaging64 (
25 ; IN UINT16 Cs,
26 ; IN UINT32 EntryPoint,
27 ; IN UINT32 Context1, OPTIONAL
28 ; IN UINT32 Context2, OPTIONAL
29 ; IN UINT32 NewStack
30 ; );
31 ;------------------------------------------------------------------------------
32 global ASM_PFX(InternalX86DisablePaging64)
33 ASM_PFX(InternalX86DisablePaging64):
34 cli
35 lea rsi, [.0] ; rsi <- The start address of transition code
36 mov edi, [rsp + 0x28] ; rdi <- New stack
37 lea rax, [mTransitionEnd] ; rax <- end of transition code
38 sub rax, rsi ; rax <- The size of transition piece code
39 add rax, 4 ; Round RAX up to the next 4 byte boundary
40 and al, 0xfc
41 sub rdi, rax ; rdi <- Use stack to hold transition code
42 mov r10d, edi ; r10 <- The start address of transicition code below 4G
43 push rcx ; save rcx to stack
44 mov rcx, rax ; rcx <- The size of transition piece code
45 rep movsb ; copy transition code to top of new stack which must be below 4GB
46 pop rcx ; restore rcx
47
48 mov esi, r8d
49 mov edi, r9d
50 mov eax, r10d ; eax <- start of the transition code on the stack
51 sub eax, 4 ; eax <- One slot below transition code on the stack
52 push rcx ; push Cs to stack
53 push r10 ; push address of tansition code on stack
54 retfq
55
56 ; Start of transition code
57 .0:
58 mov esp, eax ; set up new stack
59 mov rax, cr0
60 btr eax, 31 ; Clear CR0.PG
61 mov cr0, rax ; disable paging and caches
62
63 mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx
64 mov ecx, 0xc0000080
65 rdmsr
66 and ah, ~ 1 ; clear LME
67 wrmsr
68 mov rax, cr4
69 and al, ~ (1 << 5) ; clear PAE
70 mov cr4, rax
71 push rdi ; push Context2
72 push rsi ; push Context1
73 call rbx ; transfer control to EntryPoint
74 hlt ; no one should get here
75
76 mTransitionEnd:
77