]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/X64/Thunk16.nasm
MdePkg: Clean up source files
[mirror_edk2.git] / MdePkg / Library / BaseLib / X64 / Thunk16.nasm
index 5fa705998e1a8a431e7e28a114cf2e307a9a846c..4678dcc5401455a0fdad25859be653fe51408c63 100644 (file)
@@ -3,7 +3,7 @@
 \r
 ;------------------------------------------------------------------------------\r
 ;\r
-; Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2006 - 2018, 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
@@ -56,8 +56,8 @@ SECTION .data
 ;\r
 ; These are global constant to convey information to C code.\r
 ;\r
-ASM_PFX(m16Size)         DW      InternalAsmThunk16 - ASM_PFX(m16Start)\r
-ASM_PFX(mThunk16Attr)    DW      _BackFromUserCode.ThunkAttr - ASM_PFX(m16Start)\r
+ASM_PFX(m16Size)         DW      ASM_PFX(InternalAsmThunk16) - ASM_PFX(m16Start)\r
+ASM_PFX(mThunk16Attr)    DW      _BackFromUserCode.ThunkAttrEnd - 4 - ASM_PFX(m16Start)\r
 ASM_PFX(m16Gdt)          DW      _NullSeg - ASM_PFX(m16Start)\r
 ASM_PFX(m16GdtrBase)     DW      _16GdtrBase - ASM_PFX(m16Start)\r
 ASM_PFX(mTransition)     DW      _EntryPoint - ASM_PFX(m16Start)\r
@@ -83,7 +83,11 @@ _BackFromUserCode:
 BITS    16\r
     push    ss\r
     push    cs\r
-o32 call    dword .Base                 ; push eip\r
+    ;\r
+    ; Note: We can't use o32 on the next instruction because of a bug\r
+    ; in NASM 2.09.04 through 2.10rc1.\r
+    ;\r
+    call    dword .Base                 ; push eip\r
 .Base:\r
     push    dword 0                     ; reserved high order 32 bits of EFlags\r
     pushfd\r
@@ -93,8 +97,8 @@ o32 call    dword .Base                 ; push eip
     push    es\r
     push    ds\r
     pushad\r
-    DB      66h, 0bah                   ; mov edx, imm32\r
-.ThunkAttr: dd   0\r
+    mov     edx, strict dword 0\r
+.ThunkAttrEnd:\r
     test    dl, THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15\r
     jz      .1\r
     mov     ax, 2401h\r
@@ -117,27 +121,25 @@ o32 call    dword .Base                 ; push eip
     add     ebp, eax                    ; add ebp, eax\r
     mov     eax, cs\r
     shl     eax, 4\r
-    lea     eax, [eax + ebx + (.64BitCode - .Base)]\r
-    mov     [cs:bx + (.64Eip - .Base)], eax\r
-    DB      66h, 0b8h                   ; mov eax, imm32\r
-.SavedCr4:  DD      0\r
+    lea     eax, [eax + ebx + (.X64JmpEnd - .Base)]\r
+    mov     [cs:bx + (.X64JmpEnd - 6 - .Base)], eax\r
+    mov     eax, strict dword 0\r
+.SavedCr4End:\r
     mov     cr4, eax\r
 o32 lgdt [cs:bx + (SavedGdt - .Base)]\r
     mov     ecx, 0c0000080h\r
     rdmsr\r
     or      ah, 1\r
     wrmsr\r
-    DB      66h, 0b8h                   ; mov eax, imm32\r
-.SavedCr0:  DD      0\r
+    mov     eax, strict dword 0\r
+.SavedCr0End:\r
     mov     cr0, eax\r
-    DB      66h, 0eah                   ; jmp far cs:.64Bit\r
-.64Eip:     DD      0\r
-.SavedCs:   DW      0\r
-.64BitCode:\r
+    jmp     0:strict dword 0\r
+.X64JmpEnd:\r
 BITS    64\r
     nop\r
-    db      048h, 0bch                 ; mov rsp, imm64\r
-.SavedSp:   DQ   0                     ; restore stack\r
+    mov rsp, strict qword 0\r
+.SavedSpEnd:\r
     nop\r
     ret\r
 \r
@@ -147,7 +149,7 @@ _EntryPoint:
 _16Gdtr:\r
         DW      GDT_SIZE - 1\r
 _16GdtrBase:\r
-        DQ      _NullSeg\r
+        DQ      0\r
 _16Idtr:\r
         DW      (1 << 10) - 1\r
         DD      0\r
@@ -238,14 +240,14 @@ BITS    64
     push    rbx\r
     push    rsi\r
     push    rdi\r
-    \r
+\r
     mov     ebx, ds\r
     push    rbx          ; Save ds segment register on the stack\r
     mov     ebx, es\r
     push    rbx          ; Save es segment register on the stack\r
     mov     ebx, ss\r
     push    rbx          ; Save ss segment register on the stack\r
-    \r
+\r
     push    fs\r
     push    gs\r
     mov     rsi, rcx\r
@@ -258,21 +260,21 @@ BITS    64
     add     edi, eax                    ; edi <- linear address of 16-bit stack\r
     pop     rcx\r
     rep     movsd                       ; copy RegSet\r
-    lea     ecx, [rdx + (_BackFromUserCode.SavedCr4 - ASM_PFX(m16Start))]\r
+    lea     ecx, [rdx + (_BackFromUserCode.SavedCr4End - ASM_PFX(m16Start))]\r
     mov     eax, edx                    ; eax <- transition code address\r
     and     edx, 0fh\r
     shl     eax, 12                     ; segment address in high order 16 bits\r
     lea     ax, [rdx + (_BackFromUserCode - ASM_PFX(m16Start))]  ; offset address\r
     stosd                               ; [edi] <- return address of user code\r
-  \r
+\r
     sgdt    [rsp + 60h]       ; save GDT stack in argument space\r
-    movzx   r10, word [rsp + 60h]   ; r10 <- GDT limit \r
-    lea     r11, [rcx + (InternalAsmThunk16 - _BackFromUserCode.SavedCr4) + 0xf]\r
+    movzx   r10, word [rsp + 60h]   ; r10 <- GDT limit\r
+    lea     r11, [rcx + (ASM_PFX(InternalAsmThunk16) - _BackFromUserCode.SavedCr4End) + 0xf]\r
     and     r11, ~0xf            ; r11 <- 16-byte aligned shadowed GDT table in real mode buffer\r
-    \r
-    mov     [rcx + (SavedGdt - _BackFromUserCode.SavedCr4)], r10w      ; save the limit of shadowed GDT table\r
-    mov     [rcx + (SavedGdt - _BackFromUserCode.SavedCr4) + 2], r11  ; save the base address of shadowed GDT table\r
-    \r
+\r
+    mov     [rcx + (SavedGdt - _BackFromUserCode.SavedCr4End)], r10w      ; save the limit of shadowed GDT table\r
+    mov     [rcx + (SavedGdt - _BackFromUserCode.SavedCr4End) + 2], r11  ; save the base address of shadowed GDT table\r
+\r
     mov     rsi, [rsp + 62h]  ; rsi <- the original GDT base address\r
     xchg    rcx, r10                    ; save rcx to r10 and initialize rcx to be the limit of GDT table\r
     inc     rcx                         ; rcx <- the size of memory to copy\r
@@ -280,27 +282,27 @@ BITS    64
     rep     movsb                       ; perform memory copy to shadow GDT table\r
     mov     rcx, r10                    ; restore the orignal rcx before memory copy\r
     mov     rdi, r11                    ; restore the original rdi before memory copy\r
-    \r
+\r
     sidt    [rsp + 50h]       ; save IDT stack in argument space\r
     mov     rax, cr0\r
-    mov     [rcx + (_BackFromUserCode.SavedCr0 - _BackFromUserCode.SavedCr4)], eax\r
+    mov     [rcx + (_BackFromUserCode.SavedCr0End - 4 - _BackFromUserCode.SavedCr4End)], eax\r
     and     eax, 7ffffffeh              ; clear PE, PG bits\r
     mov     rbp, cr4\r
-    mov     [rcx], ebp                  ; save CR4 in _BackFromUserCode.SavedCr4\r
+    mov     [rcx - 4], ebp              ; save CR4 in _BackFromUserCode.SavedCr4End - 4\r
     and     ebp, ~30h                ; clear PAE, PSE bits\r
     mov     esi, r8d                    ; esi <- 16-bit stack segment\r
     push    DATA32\r
     pop     rdx                         ; rdx <- 32-bit data segment selector\r
-    lgdt    [rcx + (_16Gdtr - _BackFromUserCode.SavedCr4)]\r
+    lgdt    [rcx + (_16Gdtr - _BackFromUserCode.SavedCr4End)]\r
     mov     ss, edx\r
     pushfq\r
     lea     edx, [rdx + DATA16 - DATA32]\r
     lea     r8, [REL .RetFromRealMode]\r
     push    r8\r
     mov     r8d, cs\r
-    mov     [rcx + (_BackFromUserCode.SavedCs - _BackFromUserCode.SavedCr4)], r8w\r
-    mov     [rcx + (_BackFromUserCode.SavedSp - _BackFromUserCode.SavedCr4)], rsp\r
-    jmp     dword far [rcx + (_EntryPoint - _BackFromUserCode.SavedCr4)]\r
+    mov     [rcx + (_BackFromUserCode.X64JmpEnd - 2 - _BackFromUserCode.SavedCr4End)], r8w\r
+    mov     [rcx + (_BackFromUserCode.SavedSpEnd - 8 - _BackFromUserCode.SavedCr4End)], rsp\r
+    jmp     dword far [rcx + (_EntryPoint - _BackFromUserCode.SavedCr4End)]\r
 .RetFromRealMode:\r
     popfq\r
     lgdt    [rsp + 60h]       ; restore protected mode GDTR\r