1 ;------------------------------------------------------------------------------
3 ; Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>
4 ; This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php.
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 ; AsmDisablePaging64 function
22 ;------------------------------------------------------------------------------
27 ;------------------------------------------------------------------------------
30 ; InternalX86DisablePaging64 (
32 ; IN UINT32 EntryPoint,
33 ; IN UINT32 Context1, OPTIONAL
34 ; IN UINT32 Context2, OPTIONAL
37 ;------------------------------------------------------------------------------
38 global ASM_PFX(InternalX86DisablePaging64)
39 ASM_PFX(InternalX86DisablePaging64):
41 lea rsi, [.0] ; rsi <- The start address of transition code
42 mov edi, [rsp + 0x28] ; rdi <- New stack
43 lea rax, [mTransitionEnd] ; rax <- end of transition code
44 sub rax, rsi ; rax <- The size of transition piece code
45 add rax, 4 ; Round RAX up to the next 4 byte boundary
47 sub rdi, rax ; rdi <- Use stack to hold transition code
48 mov r10d, edi ; r10 <- The start address of transicition code below 4G
49 push rcx ; save rcx to stack
50 mov rcx, rax ; rcx <- The size of transition piece code
51 rep movsb ; copy transition code to top of new stack which must be below 4GB
56 mov eax, r10d ; eax <- start of the transition code on the stack
57 sub eax, 4 ; eax <- One slot below transition code on the stack
58 push rcx ; push Cs to stack
59 push r10 ; push address of tansition code on stack
60 DB 0x48 ; prefix to composite "retq" with next "retf"
61 retf ; Use far return to load CS register from stack
63 ; Start of transition code
65 mov esp, eax ; set up new stack
67 btr eax, 31 ; Clear CR0.PG
68 mov cr0, rax ; disable paging and caches
70 mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx
73 and ah, ~ 1 ; clear LME
76 and al, ~ (1 << 5) ; clear PAE
78 push rdi ; push Context2
79 push rsi ; push Context1
80 call rbx ; transfer control to EntryPoint
81 hlt ; no one should get here