diff options
Diffstat (limited to 'MdePkg/Library')
-rw-r--r-- | MdePkg/Library/BaseLib/X64/DisablePaging64.S | 15 | ||||
-rw-r--r-- | MdePkg/Library/BaseLib/X64/DisablePaging64.asm | 21 |
2 files changed, 21 insertions, 15 deletions
diff --git a/MdePkg/Library/BaseLib/X64/DisablePaging64.S b/MdePkg/Library/BaseLib/X64/DisablePaging64.S index 017d6ce945..a467fea260 100644 --- a/MdePkg/Library/BaseLib/X64/DisablePaging64.S +++ b/MdePkg/Library/BaseLib/X64/DisablePaging64.S @@ -40,10 +40,12 @@ ASM_PFX(InternalX86DisablePaging64): cli
lea L1(%rip), %rsi # rsi <- The start address of transition code
mov 0x28(%rsp), %edi # rdi <- New stack
- sub $64, %edi # rdi <- use 64 byte in stack to hold transition code
- mov %edi, %r10d # r10 <- The start address of transicition code below 4G
lea _mTransitionEnd(%rip), %rax # rax <- end of transition code
sub %rsi, %rax # rax <- The size of transition piece code
+ add $4, %rax # round rax up to the next 4 byte boundary
+ and $0x0fffffffc, %rax
+ sub %rax, %rdi # rdi <- use stack to hold transition code
+ mov %edi, %r10d # r10 <- The start address of transicition code below 4G
push %rcx # save rcx to stack
mov %rax, %rcx # rcx <- The size of transition piece code
rep
@@ -52,18 +54,19 @@ ASM_PFX(InternalX86DisablePaging64): mov %r8d, %esi
mov %r9d, %edi
- mov 0x28(%rsp), %eax # eax <- New Stack
+ mov %r10d, %eax
+ sub $4, %eax
push %rcx # push Cs to stack
- push %r10
+ push %r10 # push address of transition code on stack
.byte 0x48, 0xcb # retq: Use far return to load CS register from stack
# (Use raw byte code since some GNU assemblers generates incorrect code for "retq")
L1:
mov %eax,%esp # set up new stack
mov %cr0,%rax
- btr $0x1f,%eax
+ btr $0x1f,%eax # clear CR0.PG
mov %rax,%cr0 # disable paging
- mov %rdx,%rbx # save EntryPoint to rbx, for rdmsr will overwrite rdx
+ mov %edx,%ebx # save EntryPoint to ebx, for rdmsr will overwrite edx
mov $0xc0000080,%ecx
rdmsr
and $0xfe,%ah # clear LME
diff --git a/MdePkg/Library/BaseLib/X64/DisablePaging64.asm b/MdePkg/Library/BaseLib/X64/DisablePaging64.asm index a2995daa33..5f556a4ca6 100644 --- a/MdePkg/Library/BaseLib/X64/DisablePaging64.asm +++ b/MdePkg/Library/BaseLib/X64/DisablePaging64.asm @@ -38,20 +38,23 @@ InternalX86DisablePaging64 PROC cli
lea rsi, @F ; rsi <- The start address of transition code
mov edi, [rsp + 28h] ; rdi <- New stack
- sub edi, 64 ; rdi <- use 64 byte in stack to hold transition code
- mov r10d, edi ; r10 <- The start address of transicition code below 4G
lea rax, mTransitionEnd ; rax <- end of transition code
sub rax, rsi ; rax <- The size of transition piece code
+ add rax, 4 ; Round RAX up to the next 4 byte boundary
+ and rax, 0fffffffch
+ sub rdi, rax ; rdi <- Use stack to hold transition code
+ mov r10d, edi ; r10 <- The start address of transicition code below 4G
push rcx ; save rcx to stack
mov rcx, rax ; rcx <- The size of transition piece code
- rep movsb ; copy transition code to (new stack - 64byte) below 4G
+ rep movsb ; copy transition code to top of new stack which must be below 4GB
pop rcx ; restore rcx
mov esi, r8d
mov edi, r9d
- mov eax, [rsp + 28h] ; eax <- New Stack
+ mov eax, r10d ; eax <- start of the transition code on the stack
+ sub eax, 4 ; eax <- One slot below transition code on the stack
push rcx ; push Cs to stack
- push r10
+ push r10 ; push address of tansition code on stack
DB 48h ; prefix to composite "retq" with next "retf"
retf ; Use far return to load CS register from stack
@@ -59,10 +62,10 @@ InternalX86DisablePaging64 PROC @@:
mov esp, eax ; set up new stack
mov rax, cr0
- btr eax, 31
- mov cr0, rax ; disable paging
-
- mov rbx, rdx ; save EntryPoint to rbx, for rdmsr will overwrite rdx
+ btr eax, 31 ; Clear CR0.PG
+ mov cr0, rax ; disable paging and caches
+
+ mov ebx, edx ; save EntryPoint to rbx, for rdmsr will overwrite rdx
mov ecx, 0c0000080h
rdmsr
and ah, NOT 1 ; clear LME
|