Revision: 14635
          http://sourceforge.net/p/edk2/code/14635
Author:   vanjeff
Date:     2013-09-10 03:07:41 +0000 (Tue, 10 Sep 2013)
Log Message:
-----------
Sync patch r13667 from main trunk.
Set correct DS/ES/FS/GS/SS segment selectors after GDT loaded.

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/13667

Modified Paths:
--------------
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf

Added Paths:
-----------
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S
    
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S
    branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm

Added: 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S
===================================================================
--- branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S 
                        (rev 0)
+++ branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S 
2013-09-10 03:07:41 UTC (rev 14635)
@@ -0,0 +1,38 @@
+#------------------------------------------------------------------------------
+#*
+#*   Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+#*   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.
+#*
+#*    AsmFuncs.S
+#*
+#*   Abstract:
+#*
+#*     Assembly function to set segment selectors.
+#
+#------------------------------------------------------------------------------
+
+.text
+
+#------------------------------------------------------------------------------
+# 
+# VOID
+# EFIAPI
+# AsmSetDataSelectors (
+#   IN UINT16   SelectorValue
+#   );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmSetDataSelectors)
+ASM_PFX(AsmSetDataSelectors):
+    movl    4(%esp),  %eax
+    movw    %ax, %ss
+    movw    %ax, %ds
+    movw    %ax, %es
+    movw    %ax, %fs
+    movw    %ax, %gs 
+    ret

Added: 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm
===================================================================
--- 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm   
                            (rev 0)
+++ 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm   
    2013-09-10 03:07:41 UTC (rev 14635)
@@ -0,0 +1,45 @@
+;------------------------------------------------------------------------------
 ;
+; Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+; 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:
+;
+;   AsmFuncs.Asm
+;
+; Abstract:
+;
+;   Assembly function to set segment selectors.
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+.686
+.model  flat,C
+
+.code
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmSetDataSelectors (
+;   IN UINT16   SelectorValue
+;   );
+;------------------------------------------------------------------------------
+AsmSetDataSelectors   PROC near public
+  mov     eax, [esp + 4]
+  mov     ds, ax
+  mov     es, ax
+  mov     fs, ax
+  mov     gs, ax
+  mov     ss, ax   
+  ret
+AsmSetDataSelectors   ENDP
+
+END

Modified: branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
===================================================================
--- branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c      
2013-09-10 00:31:09 UTC (rev 14634)
+++ branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c      
2013-09-10 03:07:41 UTC (rev 14635)
@@ -193,6 +193,18 @@
   IN EFI_PEI_S3_RESUME2_PPI  *This
   );
 
+/**
+  Set data segment selectors value including DS/ES/FS/GS/SS.
+
+  @param[in]  SelectorValue      Segment selector value to be set.
+
+**/
+VOID
+EFIAPI
+AsmSetDataSelectors (
+  IN UINT16   SelectorValue
+  );
+
 //
 // Globals
 //
@@ -232,6 +244,8 @@
 /* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},
 };
 
+#define DATA_SEGEMENT_SELECTOR        0x18
+
 //
 // IA32 Gdt register
 //
@@ -733,6 +747,7 @@
   IA32_DESCRIPTOR            *IdtDescriptor;
   VOID                       *IdtBuffer;
   PEI_S3_RESUME_STATE        *PeiS3ResumeState;
+  BOOLEAN                    InterruptStatus;
 
   DEBUG ((EFI_D_ERROR, "S3ResumeExecuteBootScript()\n"));
 
@@ -794,10 +809,19 @@
     *(UINTN*)(IdtDescriptor->Base - sizeof(UINTN)) = 
(UINTN)GetPeiServicesTablePointer ();
   }
 
+  InterruptStatus = SaveAndDisableInterrupts ();
   //
   // Need to make sure the GDT is loaded with values that support long mode 
and real mode.
   //
   AsmWriteGdtr (&mGdt);
+  //
+  // update segment selectors per the new GDT.
+  //
+  AsmSetDataSelectors (DATA_SEGEMENT_SELECTOR);
+  //
+  // Restore interrupt state.
+  //
+  SetInterruptState (InterruptStatus);
 
   //
   // Prepare data for return back
@@ -904,6 +928,7 @@
   SMM_S3_RESUME_STATE                           *SmmS3ResumeState;
   VOID                                          *GuidHob;
   BOOLEAN                                       Build4GPageTableOnly;
+  BOOLEAN                                       InterruptStatus;
 
   DEBUG ((EFI_D_ERROR, "Enter S3 PEIM\r\n"));
 
@@ -1039,10 +1064,20 @@
       // Switch to long mode to complete resume.
       //
 
+      InterruptStatus = SaveAndDisableInterrupts ();
       //
       // Need to make sure the GDT is loaded with values that support long 
mode and real mode.
       //
       AsmWriteGdtr (&mGdt);
+      //
+      // update segment selectors per the new GDT.
+      //      
+      AsmSetDataSelectors (DATA_SEGEMENT_SELECTOR);
+      //
+      // Restore interrupt state.
+      //
+      SetInterruptState (InterruptStatus);
+
       AsmWriteCr3 ((UINTN)SmmS3ResumeState->SmmS3Cr3);
       AsmEnablePaging64 (
         0x38,

Modified: 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
===================================================================
--- 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf    
    2013-09-10 00:31:09 UTC (rev 14634)
+++ 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf    
    2013-09-10 03:07:41 UTC (rev 14635)
@@ -33,6 +33,14 @@
 [Sources]
   S3Resume.c
 
+[Sources.IA32]
+  Ia32/AsmFuncs.asm  | MSFT
+  Ia32/AsmFuncs.S    | GCC
+
+[Sources.X64]
+  X64/AsmFuncs.asm   | MSFT
+  X64/AsmFuncs.S     | GCC
+
 [Packages]
   MdePkg/MdePkg.dec
   MdeModulePkg/MdeModulePkg.dec

Added: 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S
===================================================================
--- branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S  
                        (rev 0)
+++ branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S  
2013-09-10 03:07:41 UTC (rev 14635)
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------
+#*
+#*   Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+#*   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.
+#*
+#*    AsmFuncs.S
+#*
+#*   Abstract:
+#*
+#*     Assembly function to set segment selectors.
+#
+#------------------------------------------------------------------------------
+
+.text
+
+#------------------------------------------------------------------------------
+# 
+# VOID
+# EFIAPI
+# AsmSetDataSelectors (
+#   IN UINT16   SelectorValue
+#   );
+#------------------------------------------------------------------------------
+ASM_GLOBAL ASM_PFX(AsmSetDataSelectors)
+ASM_PFX(AsmSetDataSelectors):
+    movw    %cx, %ss
+    movw    %cx, %ds
+    movw    %cx, %es
+    movw    %cx, %fs
+    movw    %cx, %gs 
+    ret

Added: 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm
===================================================================
--- 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm    
                            (rev 0)
+++ 
branches/UDK2010.SR1/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm    
    2013-09-10 03:07:41 UTC (rev 14635)
@@ -0,0 +1,41 @@
+;------------------------------------------------------------------------------
 ;
+; Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>
+; 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:
+;
+;   AsmFuncs.Asm
+;
+; Abstract:
+;
+;   Assembly function to set segment selectors.
+;
+; Notes:
+;
+;------------------------------------------------------------------------------
+
+.code
+
+;------------------------------------------------------------------------------
+; VOID
+; EFIAPI
+; AsmSetDataSelectors (
+;   IN UINT16   SelectorValue
+;   );
+;------------------------------------------------------------------------------
+AsmSetDataSelectors   PROC
+  mov     ds, cx
+  mov     es, cx
+  mov     fs, cx
+  mov     gs, cx
+  mov     ss, cx   
+  ret
+AsmSetDataSelectors   ENDP
+
+END

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to