]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/X64/DisablePaging64.asm
Update the copyright notice format
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / DisablePaging64.asm
index 3134e4257150a7d734f85a6a0ac58605e542a03a..4895ba85fa4aed3d248885ed2d6b0599608e1a5f 100644 (file)
@@ -1,7 +1,7 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006, 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
     .code\r
 \r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; InternalX86DisablePaging64 (\r
+;   IN      UINT16                    Cs,\r
+;   IN      UINT32                    EntryPoint,\r
+;   IN      UINT32                    Context1,  OPTIONAL\r
+;   IN      UINT32                    Context2,  OPTIONAL\r
+;   IN      UINT32                    NewStack\r
+;   );\r
+;------------------------------------------------------------------------------\r
 InternalX86DisablePaging64    PROC\r
     cli\r
-    shl     rcx, 32\r
-    lea     ecx, @F\r
-    push    rcx\r
-    mov     ebx, edx\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]\r
-    retf\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                         ; 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
+    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
@@ -45,10 +73,12 @@ InternalX86DisablePaging64    PROC
     mov     rax, cr4\r
     and     al, NOT (1 SHL 5)           ; clear PAE\r
     mov     cr4, rax\r
-    push    rdi\r
-    push    rsi\r
-    call    rbx\r
-    jmp     $\r
+    push    rdi                         ; push Context2\r
+    push    rsi                         ; push Context1\r
+    call    rbx                         ; transfer control to EntryPoint\r
+    hlt                                 ; no one should get here\r
 InternalX86DisablePaging64    ENDP\r
 \r
+mTransitionEnd LABEL    BYTE\r
+\r
     END\r