summaryrefslogtreecommitdiff
path: root/MdePkg/Library/BaseLib/X64/Thunk16.asm
diff options
context:
space:
mode:
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-26 11:41:12 +0000
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>2009-05-26 11:41:12 +0000
commita1487801142ea23a2aed51f5e2875b8391787dc9 (patch)
treeb8aaa1fdcc7a05c014d5dea539ce3b0b9b0c8aef /MdePkg/Library/BaseLib/X64/Thunk16.asm
parent57ee276f16c99a3851b3ced4043d7b31097c1988 (diff)
downloadedk2-platforms-a1487801142ea23a2aed51f5e2875b8391787dc9.tar.xz
Fix the bug in x64 thunk code that it cannot handle the case when GDT is loaded in above 4G table memory.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8390 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/BaseLib/X64/Thunk16.asm')
-rw-r--r--MdePkg/Library/BaseLib/X64/Thunk16.asm19
1 files changed, 18 insertions, 1 deletions
diff --git a/MdePkg/Library/BaseLib/X64/Thunk16.asm b/MdePkg/Library/BaseLib/X64/Thunk16.asm
index cef63d98e1..7d9136d4ab 100644
--- a/MdePkg/Library/BaseLib/X64/Thunk16.asm
+++ b/MdePkg/Library/BaseLib/X64/Thunk16.asm
@@ -258,7 +258,23 @@ InternalAsmThunk16 PROC USES rbp rbx rsi rdi
shl eax, 12 ; segment address in high order 16 bits
lea ax, [rdx + (_BackFromUserCode - m16Start)] ; offset address
stosd ; [edi] <- return address of user code
- sgdt fword ptr [rcx + (SavedGdt - SavedCr4)]
+
+ sgdt fword ptr [rsp + 60h] ; save GDT stack in argument space
+ movzx r10, word ptr [rsp + 60h] ; r10 <- GDT limit
+ lea r11, [rcx + (InternalAsmThunk16 - SavedCr4) + 0xf]
+ and r11, 0xfffffff0 ; r11 <- 16-byte aligned shadowed GDT table in real mode buffer
+
+ mov word ptr [rcx + (SavedGdt - SavedCr4)], r10w ; save the limit of shadowed GDT table
+ mov qword ptr [rcx + (SavedGdt - SavedCr4) + 2], r11 ; save the base address of shadowed GDT table
+
+ mov rsi, qword ptr [rsp + 62h] ; rsi <- the original GDT base address
+ xchg rcx, r10 ; save rcx to r10 and initialize rcx to be the limit of GDT table
+ inc rcx ; rcx <- the size of memory to copy
+ xchg rdi, r11 ; save rdi to r11 and initialize rdi to the base address of shadowed GDT table
+ rep movsb ; perform memory copy to shadow GDT table
+ mov rcx, r10 ; restore the orignal rcx before memory copy
+ mov rdi, r11 ; restore the original rdi before memory copy
+
sidt fword ptr [rsp + 50h] ; save IDT stack in argument space
mov rax, cr0
mov [rcx + (SavedCr0 - SavedCr4)], eax
@@ -281,6 +297,7 @@ InternalAsmThunk16 PROC USES rbp rbx rsi rdi
jmp fword ptr [rcx + (_EntryPoint - SavedCr4)]
@RetFromRealMode:
popfq
+ lgdt fword ptr [rsp + 60h] ; restore protected mode GDTR
lidt fword ptr [rsp + 50h] ; restore protected mode IDTR
lea eax, [rbp - sizeof (IA32_REGS)]
pop gs