]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add .S file for X64 GCC tool-chain for Thunk16.
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Aug 2008 15:08:59 +0000 (15:08 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Aug 2008 15:08:59 +0000 (15:08 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5751 6f19259b-4bc3-4df7-8a09-765794883524

EdkCompatibilityPkg/Foundation/Library/Thunk16/Thunk16Lib_Edk2.inf
EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Fx.S [new file with mode: 0644]
EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Thunk16.S [new file with mode: 0644]

index aef578e4cdc82224da5fd3467eeaaea0e3849289..86e0da1981bdd04ea3c36dd03167ea9631c5fc28 100644 (file)
@@ -35,8 +35,10 @@ COMPONENT_TYPE       = LIBRARY
 [sources.x64]\r
   X64/Thunk16.asm   | MSFT\r
   X64/Thunk16.asm   | INTEL\r
+  X64/Thunk16.S     | GCC\r
   X64/Fx.asm        | MSFT\r
   X64/Fx.asm        | INTEL\r
+  X64/Fx.S          | GCC\r
 \r
 [includes.common]\r
   .\r
diff --git a/EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Fx.S b/EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Fx.S
new file mode 100644 (file)
index 0000000..7b15f41
--- /dev/null
@@ -0,0 +1,48 @@
+#*****************************************************************************
+#*
+#*   Copyright (c) 2008, Intel Corporation                                                         
+#*   All rights reserved. This program and the accompanying materials                          
+#*   are licensed and made available under the terms and conditions of the BSD License         
+#*   which accompanies this distribution.  The full text of the license may be found at        
+#*   http://opensource.org/licenses/bsd-license.php                                            
+#*                                                                                             
+#*   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+#*   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+#*   
+#*   Module Name:
+#*
+#*    Fx.S
+#*  
+#*   Abstract:
+#*  
+#*    AsmFxRestore and AsmFxSave function
+#*  
+#*****************************************************************************
+#include <EfiBind.h>
+
+.global ASM_PFX(AsmFxSave)
+.global ASM_PFX(AsmFxRestore)
+
+    .text
+
+#------------------------------------------------------------------------------
+# VOID
+# AsmFxSave (
+#   OUT IA32_FX_BUFFER *Buffer
+#   );
+#------------------------------------------------------------------------------
+ASM_PFX(AsmFxSave):
+    fxsave (%rcx)
+    retq
+    
+#------------------------------------------------------------------------------
+# VOID
+# AsmFxRestore (
+#   IN CONST IA32_FX_BUFFER *Buffer
+#   );
+#------------------------------------------------------------------------------
+
+ASM_PFX(AsmFxRestore):
+    fxrstor (%rcx)
+    retq
+    
\ No newline at end of file
diff --git a/EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Thunk16.S b/EdkCompatibilityPkg/Foundation/Library/Thunk16/X64/Thunk16.S
new file mode 100644 (file)
index 0000000..a8a94a4
--- /dev/null
@@ -0,0 +1,236 @@
+#*****************************************************************************
+#*
+#*   Copyright (c) 2008, Intel Corporation                                                         
+#*   All rights reserved. This program and the accompanying materials                          
+#*   are licensed and made available under the terms and conditions of the BSD License         
+#*   which accompanies this distribution.  The full text of the license may be found at        
+#*   http://opensource.org/licenses/bsd-license.php                                            
+#*                                                                                             
+#*   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+#*   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+#*   
+#*   Module Name:
+#*
+#*    Thunk.S
+#*  
+#*   Abstract:
+#*  
+#*    Real mode thunk
+#*  
+#*****************************************************************************
+#include <EfiBind.h>
+
+
+
+    .data
+
+.globl ASM_PFX(mCode16Size)
+
+.data
+mCode16Size:    .long   _Code16End - _Code16Addr
+
+
+NullSegSel:     .quad   0
+_16CsSegSel:    
+                .word   -1
+                .word   0
+                .byte   0
+                .byte   0x9b
+                .byte   0x8f            #16-bit segment
+                .byte   0
+_16DsSegSel:
+                .word   -1
+                .word   0
+                .byte   0
+                .byte   0x93
+                .byte   0x8f           #16-bit segment
+                .byte   0
+
+_16Gdtr:
+                .word      _16Gdtr - NullSegSel - 1
+                .long      NullSegSel
+    .code: 
+
+#IA32_REGS   STRUC   4t\r
+#_EDI        DD      ?\r
+#_ESI        DD      ?\r
+#_EBP        DD      ?\r
+#_ESP        DD      ?\r
+#_EBX        DD      ?\r
+#_EDX        DD      ?\r
+#_ECX        DD      ?\r
+#_EAX        DD      ?\r
+#_DS         DW      ?\r
+#_ES         DW      ?\r
+#_FS         DW      ?\r
+#_GS         DW      ?\r
+#_RFLAGS     DQ      ?\r
+#_EIP        DD      ?\r
+#_CS         DW      ?\r
+#_SS         DW      ?\r
+#IA32_REGS   ENDS\r
+\r
+#_STK16      STRUC   1t\r
+#RetEip      DD      ?\r
+#RetCs       DW      ?\r
+#ThunkFlags  DW      ?\r
+#SavedGdtr   FWORD   ?\r
+#Resvd1      DW      ?\r
+#SavedCr0    DD      ?\r
+#SavedCr4    DD      ?\r
+#_STK16      ENDS\r
+
+ASM_PFX(Thunk16):
+      push   %rbp
+      push   %rbx
+      push   %rsi
+      push   %rdi
+      push   %r12
+      push   %r13
+      push   %r14
+      push   %r15
+      pushq  %fs
+      pushq  %gs
+      movl   %ds,%r12d
+      movl   %es,%r13d
+      movl   %ss,%r14d
+      mov    %rsp,%r15
+      mov    %rcx,%rsi
+      movzwq 0x36(%rsi),%r10            #movzx   r10, (IA32_REGS ptr [rsi])._SS
+      xor    %rdi,%rdi
+      mov    0xc(%rsi),%edi             #mov     edi, (IA32_REGS ptr [rsi])._ESP
+      add    $0xffffffffffffffb0,%rdi   #add     rdi, - sizeof (IA32_REGS) - sizeof (_STK16)
+      push   %rdi
+      imul   $0x10,%r10,%rax
+      add    %rax,%rdi
+      pushq  $0xe                       #push    sizeof (IA32_REGS) / 4
+      pop    %rcx
+      rep movsl %ds:(%rsi),%es:(%rdi)
+      pop    %rbx                       #rbx <- 16-bit stack offset
+      lea    Label,%eax                 #42 <_Thunk16+0x42>
+      stos   %eax,%es:(%rdi)
+      movl   %cs,%eax                   #return segment
+      stos   %ax,%es:(%rdi)
+      mov    %edx,%eax                  #THUNK Flags
+      stos   %ax,%es:(%rdi)
+      sgdt  0x58(%rsp)                  #save GDTR
+      mov    0x58(%rsp),%rax
+      stos   %rax,%es:(%rdi)
+      mov    %cr0,%rax                  #save CR0
+      mov    %eax,%esi                  #esi <- CR0 to set
+      stos   %eax,%es:(%rdi)
+      mov    %cr4,%rax                  #save CR4
+      stos   %eax,%es:(%rdi)
+      sidt   0x58(%rsp)                 #save IDTR
+      and    $0x7ffffffe,%esi           #clear PE & PG bits
+      mov    %r10,%rdi                  #rdi <- 16-bit stack segment
+      shl    $0x10,%r8
+      push   %r8                        #far jmp address
+      lea    Label_16Bit,%eax           
+      push   %rax
+      movw   $0x8,0x4(%rsp)
+      lgdt   _16Gdtr                    #bugbug: may not match.
+      lret   
+Label_16Bit:
+      .byte  0x66
+      movl   $0xc0000080,%ecx
+      mov    %rsi,%cr0                  #disable PE & PG        
+      rdmsr  
+      and    $0xfe,%ah
+      wrmsr                             #clear LME bit
+      mov    %cr4,%rax
+      and    $0xcf,%al                  #clear PAE & PSE
+      mov    %rax,%cr4
+      lret   
+
+Label:
+      xor    %rax,%rax
+      movl   %ss,%eax
+      shl    $0x4,%eax
+      add    %esp,%eax
+      mov    %r15,%rsp
+      lidt   0x58(%rsp)
+      movl   %r12d,%ds
+      movl   %r13d,%es
+      movl   %r14d,%ss
+      popq   %gs
+      popq   %fs
+      pop    %r15
+      pop    %r14
+      pop    %r13
+      pop    %r12
+      pop    %rdi
+      pop    %rsi
+      pop    %rbx
+      pop    %rbp
+      retq   
+
+
+    .align 0x10
+
+_Code16Addr:
+ASM_PFX(RealMode):
+    movl   %edi,%ss
+    mov    %bx,%sp                     #set up 16-bit stack
+   .byte   0x2e 
+   .byte   0x0f 
+   .byte   0x01
+   .byte   0x1e\r
+   .word   _16Idtr - _Code16Addr       #lidt _16Idtr\r
+   .byte   0x66
+   .byte   0x61                        #popad\r
+   .byte   0x1f                        #pop ds\r
+   .byte   0x07                        #pop es
+    popq   %fs\r
+    popq   %gs\r
+    add    $0x8,%esp                   #skip RFLAGS\r
+   .byte   0x67                        #test [esp + 0eh], 1
+   .byte   0xf7    
+   .byte   0x44
+   .byte   0x24
+   .byte   0x0e
+   .byte   0x01
+   .byte   0x00
+    jz      1f
+    pushfq                             #pushf, actually
+1:
+   .byte   0x0e                        #push cs
+   .byte   0x68                        #push /iw
+   .word   FarCallRet - _Code16Addr
+    jz     2f
+   .byte   0x66
+    ljmp   *6(%esp)
+2:    
+   .byte   0x66
+    ljmp   *4(%esp)
+FarCallRet: 
+   .byte   0x66
+    push   $0x00                       #push a dword of zero
+   .byte   0x66
+    pushf                              #pushfd, actually
+    pushq  %gs
+    pushq  %fs
+   .byte   0x06                        #push %es
+   .byte   0x1e                        #push %ds
+   .byte   0x66
+   .byte   0x60
+    cli
+   .byte   0x66                        #sizeof (IA32_REGS) = 13 * 4 = 52
+    lgdt   64(%esp)                    #lgdt    (_STK16 ptr [esp + sizeof (IA32_REGS)]).SavedGdtr
+   .byte   0x66
+    mov    76(%esp), %eax
+    mov    %rax, %cr4
+   .byte   0x66
+    mov    $0xc0000080, %ecx
+    rdmsr
+    orb    $1, %ah
+    wrmsr
+   .byte   0x66
+    mov    72(%esp), %eax
+    mov    %rax, %cr0                   #restore CR0
+   .byte   0x66
+    ljmpl  *52(%esp)                    
+
+_16Idtr:
+   .word 0x3ff                          #FWORD   (1 SHL 10) - 1
+   .byte 0x00