;------------------------------------------------------------------------------\r
;\r
-; Copyright (c) 2006 - 2008, Intel Corporation\r
-; All rights reserved. This program and the accompanying materials\r
+; Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+; This program and the accompanying materials\r
; are licensed and made available under the terms and conditions of the BSD License\r
; which accompanies this distribution. The full text of the license may be found at\r
; http://opensource.org/licenses/bsd-license.php\r
;------------------------------------------------------------------------------\r
InternalX86DisablePaging64 PROC\r
cli\r
- lea r10, @F\r
+ lea rsi, @F ; rsi <- The start address of transition code\r
+ mov edi, [rsp + 28h] ; rdi <- New stack\r
+ lea rax, mTransitionEnd ; rax <- end of transition code\r
+ sub rax, rsi ; rax <- The size of transition piece code \r
+ add rax, 4 ; Round RAX up to the next 4 byte boundary\r
+ and al, 0fch\r
+ sub rdi, rax ; rdi <- Use stack to hold transition code\r
+ mov r10d, edi ; r10 <- The start address of transicition code below 4G\r
+ push rcx ; save rcx to stack\r
+ mov rcx, rax ; rcx <- The size of transition piece code\r
+ rep movsb ; copy transition code to top of new stack which must be below 4GB\r
+ pop rcx ; restore rcx\r
+ \r
mov esi, r8d\r
mov edi, r9d\r
- mov eax, [rsp + 28h] ; eax <- New Stack\r
+ mov eax, r10d ; eax <- start of the transition code on the stack\r
+ sub eax, 4 ; eax <- One slot below transition code on the stack\r
push rcx ; push Cs to stack\r
- push r10\r
+ push r10 ; push address of tansition code on stack\r
DB 48h ; prefix to composite "retq" with next "retf"\r
retf ; Use far return to load CS register from stack\r
+\r
+; Start of transition code\r
@@:\r
mov esp, eax ; set up new stack\r
mov rax, cr0\r
- btr eax, 31\r
- mov cr0, rax ; disable paging\r
-\r
- mov rbx, rdx ; save EntryPoint to rbx, for rdmsr will overwrite rdx\r
+ btr eax, 31 ; Clear CR0.PG\r
+ mov cr0, rax ; disable paging and caches\r
+ \r
+ mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx\r
mov ecx, 0c0000080h\r
rdmsr\r
and ah, NOT 1 ; clear LME\r
hlt ; no one should get here\r
InternalX86DisablePaging64 ENDP\r
\r
+mTransitionEnd LABEL BYTE\r
+\r
END\r