]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/EnablePaging64.asm
ArmPkg/ArmDisassemblerLib: fix check for MSR instruction
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / EnablePaging64.asm
index 97d859e966f5add11408dda8bc04463e7ed07505..9ad340494525c1706688e1967ad7144a6a79f981 100644 (file)
@@ -1,10 +1,10 @@
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006, Intel Corporation\r
-; All rights reserved. This program and the accompanying materials\r
+; Copyright (c) 2006, 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
+; http://opensource.org/licenses/bsd-license.php.\r
 ;\r
 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
     .model  flat,C\r
     .code\r
 \r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; InternalX86EnablePaging64 (\r
+;   IN      UINT16                    Cs,\r
+;   IN      UINT64                    EntryPoint,\r
+;   IN      UINT64                    Context1,  OPTIONAL\r
+;   IN      UINT64                    Context2,  OPTIONAL\r
+;   IN      UINT64                    NewStack\r
+;   );\r
+;------------------------------------------------------------------------------\r
 InternalX86EnablePaging64 PROC\r
-    cli
-\r
-    mov     ebx, [esp + 4]              ; save CS
-    mov     eax, OFFSET cs_address
-    mov     word ptr [eax], bx          ; Update CS selector for far jump
-\r
-    mov     eax, cr4 \r
+    cli\r
+    mov     DWORD PTR [esp], @F         ; offset for far retf, seg is the 1st arg\r
+    mov     eax, cr4\r
     or      al, (1 SHL 5)\r
     mov     cr4, eax                    ; enable PAE\r
     mov     ecx, 0c0000080h\r
@@ -40,33 +47,22 @@ InternalX86EnablePaging64 PROC
     or      ah, 1                       ; set LME\r
     wrmsr\r
     mov     eax, cr0\r
-    bts     eax, 31\r
-    mov     cr0, eax                    ; enable paging
-    retf
-    jmp     go_to_long_mode
-go_to_long_mode:
-
-    ;
-    ; This is the next instruction after enabling paging.  Jump to long mode
-    ;
-    db      067h
-    db      0eah                        ;   Far Jump Offset:Selector to reload CS
-    dd      OFFSET in_long_mode         ;   Offset is ensuing instruction boundary
-cs_address:
-    dw      0h                          ;   CS selector will be updated at runtime 
-\r
-in_long_mode:                           ; now in long mode
+    bts     eax, 31                     ; set PG\r
+    mov     cr0, eax                    ; enable paging\r
+    retf                                ; topmost 2 dwords hold the address\r
+@@:                                     ; long mode starts here\r
+    DB      67h, 48h                    ; 32-bit address size, 64-bit operand size\r
+    mov     ebx, [esp]                  ; mov rbx, [esp]\r
     DB      67h, 48h\r
-    mov     ebx, [esp + 8]              ; mov rbx, [esp]\r
-    DB      67h, 48h\r                   
-    mov     ecx, [esp + 10h]            ; mov rcx, [esp + 8]\r
+    mov     ecx, [esp + 8]              ; mov rcx, [esp + 8]\r
     DB      67h, 48h\r
-    mov     edx, [esp + 18h]            ; mov rdx, [esp + 10h]\r
+    mov     edx, [esp + 10h]            ; mov rdx, [esp + 10h]\r
     DB      67h, 48h\r
-    mov     esp, [esp + 20h]            ; mov rsp, [esp + 18h]\r
+    mov     esp, [esp + 18h]            ; mov rsp, [esp + 18h]\r
     DB      48h\r
+    add     esp, -20h                   ; add rsp, -20h\r
     call    ebx                         ; call rbx\r
-    jmp     $\r
+    hlt                                 ; no one should get here\r
 InternalX86EnablePaging64 ENDP\r
 \r
     END\r