1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
12 ; AsmDisablePaging64 function
16 ;------------------------------------------------------------------------------
21 ;------------------------------------------------------------------------------
24 ; InternalX86DisablePaging64 (
26 ; IN UINT32 EntryPoint,
27 ; IN UINT32 Context1, OPTIONAL
28 ; IN UINT32 Context2, OPTIONAL
31 ;------------------------------------------------------------------------------
32 global ASM_PFX(InternalX86DisablePaging64)
33 ASM_PFX(InternalX86DisablePaging64):
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
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
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 DB 0x48 ; prefix to composite "retq" with next "retf"
55 retf ; Use far return to load CS register from stack
57 ; Start of transition code
59 mov esp, eax ; set up new stack
61 btr eax, 31 ; Clear CR0.PG
62 mov cr0, rax ; disable paging and caches
64 mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx
67 and ah, ~ 1 ; clear LME
70 and al, ~ (1 << 5) ; clear PAE
72 push rdi ; push Context2
73 push rsi ; push Context1
74 call rbx ; transfer control to EntryPoint
75 hlt ; no one should get here