]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseLib/Ia32/Thunk16.S
MdePkg: Fix GCC Thunk support for IA32
[mirror_edk2.git] / MdePkg / Library / BaseLib / Ia32 / Thunk16.S
index aad6bbe26ba6ced59f5c41f289d9e20425ae9bae..df205e9a1929c7b970c888550616119e72bbb986 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 - 2010, 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
 #\r
 #------------------------------------------------------------------------------\r
 \r
-.global _m16Start, _m16Size, _mThunk16Attr, _m16Gdt, _m16GdtrBase, _mTransition\r
-.global _InternalAsmThunk16\r
+#include <Library/BaseLib.h>\r
 \r
-_m16Start:\r
+ASM_GLOBAL ASM_PFX(m16Start), ASM_PFX(m16Size), ASM_PFX(mThunk16Attr), ASM_PFX(m16Gdt), ASM_PFX(m16GdtrBase), ASM_PFX(mTransition)\r
+ASM_GLOBAL ASM_PFX(InternalAsmThunk16)\r
+\r
+ASM_PFX(m16Start):\r
 \r
 SavedGdt:     .space  6\r
 \r
-_BackFromUserCode:\r
+ASM_PFX(BackFromUserCode):\r
     push    %ss\r
     push    %cs\r
     .byte   0x66\r
-    call    @Base1                      # push eip\r
-@Base1:\r
+    call    L_Base1                     # push eip\r
+L_Base1:\r
     pushfw                              # pushfd actually\r
     cli                                 # disable interrupts\r
     push    %gs\r
@@ -39,21 +41,21 @@ _BackFromUserCode:
     push    %es\r
     push    %ds\r
     pushaw                              # pushad actually\r
-    .byte   0x66, 0xba                   # mov edx, imm32\r
-_ThunkAttr: .space  4\r
+    .byte   0x66, 0xba                  # mov edx, imm32\r
+ASM_PFX(ThunkAttr): .space  4\r
     testb   $THUNK_ATTRIBUTE_DISABLE_A20_MASK_INT_15, %dl\r
-    jz      @1\r
+    jz      1f\r
     movl    $0x15cd2401, %eax           # mov ax, 2401h & int 15h\r
     cli                                 # disable interrupts\r
-    jnc     @2\r
-@1:\r
+    jnc     2f\r
+1:\r
     testb   $THUNK_ATTRIBUTE_DISABLE_A20_MASK_KBD_CTRL, %dl\r
-    jz      @2\r
+    jz      2f\r
     inb     $0x92, %al\r
     orb     $2, %al\r
     outb    %al, $0x92                  # deactivate A20M#\r
-@2:\r
-    movl    %ss, %eax\r
+2:\r
+    movw    %ss, %ax\r
     .byte   0x67, 0x66, 0x8d, 0x6c, 0x24, 0x34, 0x66\r
     mov     %ebp, 0xffffffd8(%esi)\r
     mov     0xfffffff8(%esi), %ebx\r
@@ -74,14 +76,14 @@ SavedEsp:   .space  4
     .byte   0x66\r
     lret                                # return to protected mode\r
 \r
-_EntryPoint:    .long      _ToUserCode - _m16Start\r
+_EntryPoint:    .long      ASM_PFX(ToUserCode) - ASM_PFX(m16Start)\r
                 .word      0x8\r
 _16Idtr:        .word      0x3ff\r
                 .long      0\r
 _16Gdtr:        .word      GdtEnd - _NullSegDesc - 1\r
-_16GdtrBase:    .long     _NullSegDesc\r
+_16GdtrBase:    .long      _NullSegDesc\r
 \r
-_ToUserCode:\r
+ASM_PFX(ToUserCode):\r
     movl    %ss, %edx\r
     movl    %ecx, %ss                   # set new segment selectors\r
     movl    %ecx, %ds\r
@@ -93,16 +95,16 @@ _ToUserCode:
     movl    %esi, %ss                   # set up 16-bit stack segment\r
     xchgw   %bx, %sp                    # set up 16-bit stack pointer\r
     .byte   0x66\r
-    call    @Base                       # push eip\r
-@Base:\r
-    popw    %bp                         # ebp <- offset @Base\r
-    addr16  pushl 36(%si)\r
-    .byte   0x36\r
+    call    L_Base                      # push eip\r
+L_Base:\r
+    popw    %bp                         # ebp <- offset L_Base\r
+    .byte   0x67;                       # address size override\r
+    push    54(%esp)\r
     lea     0xc(%esi), %eax\r
     push    %eax\r
     lret\r
 \r
-@RealMode:\r
+L_RealMode:\r
     mov     %edx, %cs:0xffffffc5(%esi)\r
     mov     %bx, %cs:0xffffffcb(%esi)\r
     lidtw   %cs:0xffffffd7(%esi)\r
@@ -132,11 +134,11 @@ _16DsDesc:
 GdtEnd:\r
 \r
 #\r
-#   @param  RegSet  Pointer to a IA32_DWORD_REGS structure\r
-#   @param  Transition  Pointer to the transition code\r
+#   @param  RegSet  The pointer to a IA32_DWORD_REGS structure\r
+#   @param  Transition  The pointer to the transition code\r
 #   @return The address of the 16-bit stack after returning from user code\r
 #\r
-_InternalAsmThunk16:\r
+ASM_PFX(InternalAsmThunk16):\r
     push    %ebp\r
     push    %ebx\r
     push    %esi\r
@@ -158,14 +160,14 @@ _InternalAsmThunk16:
     movsl                               # copy RegSet\r
     movl    40(%esp), %eax              # eax <- address of transition code\r
     movl    %edx, %esi                  # esi <- 16-bit stack segment\r
-    lea     0x5e(%eax), %edx\r
+    lea     0x5f(%eax), %edx\r
     movl    %eax, %ecx\r
     andl    $0xf, %ecx\r
     shll    $12, %eax\r
     lea     0x6(%ecx), %ecx\r
     movw    %cx, %ax\r
     stosl                               # [edi] <- return address of user code\r
-    sgdtl   0xffffffa2(%edx)\r
+    sgdtl   0xffffffa1(%edx)\r
     sidtl   0x24(%esp)\r
     movl    %cr0, %eax\r
     movl    %eax, (%edx)                # save CR0 in SavedCr0\r
@@ -181,20 +183,20 @@ _InternalAsmThunk16:
     popfl\r
     lidtl   0x24(%esp)\r
     lea     0xffffffcc(%ebp), %eax\r
-       pop     %gs\r
-       pop     %fs\r
-       pop     %es\r
-       pop     %ds\r
-       pop     %edi\r
-       pop     %esi\r
-       pop     %ebx\r
-       pop     %ebp\r
+    pop     %gs\r
+    pop     %fs\r
+    pop     %es\r
+    pop     %ds\r
+    pop     %edi\r
+    pop     %esi\r
+    pop     %ebx\r
+    pop     %ebp\r
     ret\r
 \r
     .const:\r
 \r
-_m16Size:        .word      _InternalAsmThunk16 - _m16Start\r
-_mThunk16Attr:   .word      _ThunkAttr          - _m16Start\r
-_m16Gdt:         .word      _NullSegDesc        - _m16Start\r
-_m16GdtrBase:    .word      _16GdtrBase         - _m16Start\r
-_mTransition:    .word      _EntryPoint         - _m16Start\r
+ASM_PFX(m16Size):        .word      ASM_PFX(InternalAsmThunk16)  - ASM_PFX(m16Start)\r
+ASM_PFX(mThunk16Attr):   .word      ASM_PFX(ThunkAttr)          - ASM_PFX(m16Start)\r
+ASM_PFX(m16Gdt):         .word      _NullSegDesc        - ASM_PFX(m16Start)\r
+ASM_PFX(m16GdtrBase):    .word      _16GdtrBase         - ASM_PFX(m16Start)\r
+ASM_PFX(mTransition):    .word      _EntryPoint         - ASM_PFX(m16Start)\r