]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Set correct DS/ES/FS/GS/SS segment selectors after GDT loaded.
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 22 Aug 2012 08:56:50 +0000 (08:56 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 22 Aug 2012 08:56:50 +0000 (08:56 +0000)
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Rui Sun <rui.sun@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13667 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S [new file with mode: 0644]
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm [new file with mode: 0644]
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S [new file with mode: 0644]
UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm [new file with mode: 0644]

diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S
new file mode 100644 (file)
index 0000000..ede19f2
--- /dev/null
@@ -0,0 +1,38 @@
+#------------------------------------------------------------------------------\r
+#*\r
+#*   Copyright (c) 2012, 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
+#*\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
+#*    AsmFuncs.S\r
+#*\r
+#*   Abstract:\r
+#*\r
+#*     Assembly function to set segment selectors.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+\r
+#------------------------------------------------------------------------------\r
+# \r
+# VOID\r
+# EFIAPI\r
+# AsmSetDataSelectors (\r
+#   IN UINT16   SelectorValue\r
+#   );\r
+#------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(AsmSetDataSelectors)\r
+ASM_PFX(AsmSetDataSelectors):\r
+    movl    4(%esp),  %eax\r
+    movw    %ax, %ss\r
+    movw    %ax, %ds\r
+    movw    %ax, %es\r
+    movw    %ax, %fs\r
+    movw    %ax, %gs \r
+    ret\r
diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm
new file mode 100644 (file)
index 0000000..79496c4
--- /dev/null
@@ -0,0 +1,45 @@
+;------------------------------------------------------------------------------ ;\r
+; Copyright (c) 2012, 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
+;\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
+; Module Name:\r
+;\r
+;   AsmFuncs.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   Assembly function to set segment selectors.\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+.686\r
+.model  flat,C\r
+\r
+.code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmSetDataSelectors (\r
+;   IN UINT16   SelectorValue\r
+;   );\r
+;------------------------------------------------------------------------------\r
+AsmSetDataSelectors   PROC near public\r
+  mov     eax, [esp + 4]\r
+  mov     ds, ax\r
+  mov     es, ax\r
+  mov     fs, ax\r
+  mov     gs, ax\r
+  mov     ss, ax   \r
+  ret\r
+AsmSetDataSelectors   ENDP\r
+\r
+END\r
index 07d83cc87529e4a550b341a89d93fa1891444e96..ad81c19590f34a92e12c5bce96ed8dbc2d463927 100644 (file)
@@ -193,6 +193,18 @@ S3RestoreConfig2 (
   IN EFI_PEI_S3_RESUME2_PPI  *This\r
   );\r
 \r
+/**\r
+  Set data segment selectors value including DS/ES/FS/GS/SS.\r
+\r
+  @param[in]  SelectorValue      Segment selector value to be set.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmSetDataSelectors (\r
+  IN UINT16   SelectorValue\r
+  );\r
+\r
 //\r
 // Globals\r
 //\r
@@ -232,6 +244,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = {
 /* 0x40 */  {{0,      0,  0,  0,    0,  0,  0,  0,    0,  0, 0,  0,  0}},\r
 };\r
 \r
+#define DATA_SEGEMENT_SELECTOR        0x18\r
+\r
 //\r
 // IA32 Gdt register\r
 //\r
@@ -701,6 +715,7 @@ S3ResumeExecuteBootScript (
   IA32_DESCRIPTOR            *IdtDescriptor;\r
   VOID                       *IdtBuffer;\r
   PEI_S3_RESUME_STATE        *PeiS3ResumeState;\r
+  BOOLEAN                    InterruptStatus;\r
 \r
   DEBUG ((EFI_D_ERROR, "S3ResumeExecuteBootScript()\n"));\r
 \r
@@ -769,10 +784,19 @@ S3ResumeExecuteBootScript (
     *(UINTN*)(IdtDescriptor->Base - sizeof(UINTN)) = (UINTN)GetPeiServicesTablePointer ();\r
   }\r
 \r
+  InterruptStatus = SaveAndDisableInterrupts ();\r
   //\r
   // Need to make sure the GDT is loaded with values that support long mode and real mode.\r
   //\r
   AsmWriteGdtr (&mGdt);\r
+  //\r
+  // update segment selectors per the new GDT.\r
+  //\r
+  AsmSetDataSelectors (DATA_SEGEMENT_SELECTOR);\r
+  //\r
+  // Restore interrupt state.\r
+  //\r
+  SetInterruptState (InterruptStatus);\r
 \r
   //\r
   // Prepare data for return back\r
@@ -873,6 +897,7 @@ S3RestoreConfig2 (
   SMM_S3_RESUME_STATE                           *SmmS3ResumeState;\r
   VOID                                          *GuidHob;\r
   BOOLEAN                                       Build4GPageTableOnly;\r
+  BOOLEAN                                       InterruptStatus;\r
 \r
   TempAcpiS3Context = 0;\r
   TempEfiBootScriptExecutorVariable = 0;\r
@@ -1002,10 +1027,20 @@ S3RestoreConfig2 (
       // Switch to long mode to complete resume.\r
       //\r
 \r
+      InterruptStatus = SaveAndDisableInterrupts ();\r
       //\r
       // Need to make sure the GDT is loaded with values that support long mode and real mode.\r
       //\r
       AsmWriteGdtr (&mGdt);\r
+      //\r
+      // update segment selectors per the new GDT.\r
+      //      \r
+      AsmSetDataSelectors (DATA_SEGEMENT_SELECTOR);\r
+      //\r
+      // Restore interrupt state.\r
+      //\r
+      SetInterruptState (InterruptStatus);\r
+\r
       AsmWriteCr3 ((UINTN)SmmS3ResumeState->SmmS3Cr3);\r
       AsmEnablePaging64 (\r
         0x38,\r
index 53c66affdecb820d52893cb60181fb863541d3d4..db5d66e7fbd7799d837021ccf7003338687f2f0a 100644 (file)
 [Sources]\r
   S3Resume.c\r
 \r
+[Sources.IA32]\r
+  Ia32/AsmFuncs.asm  | MSFT\r
+  Ia32/AsmFuncs.S    | GCC\r
+\r
+[Sources.X64]\r
+  X64/AsmFuncs.asm   | MSFT\r
+  X64/AsmFuncs.S     | GCC\r
+\r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   MdeModulePkg/MdeModulePkg.dec\r
diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S
new file mode 100644 (file)
index 0000000..2ced09f
--- /dev/null
@@ -0,0 +1,37 @@
+#------------------------------------------------------------------------------\r
+#*\r
+#*   Copyright (c) 2012, 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
+#*\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
+#*    AsmFuncs.S\r
+#*\r
+#*   Abstract:\r
+#*\r
+#*     Assembly function to set segment selectors.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+.text\r
+\r
+#------------------------------------------------------------------------------\r
+# \r
+# VOID\r
+# EFIAPI\r
+# AsmSetDataSelectors (\r
+#   IN UINT16   SelectorValue\r
+#   );\r
+#------------------------------------------------------------------------------\r
+ASM_GLOBAL ASM_PFX(AsmSetDataSelectors)\r
+ASM_PFX(AsmSetDataSelectors):\r
+    movw    %cx, %ss\r
+    movw    %cx, %ds\r
+    movw    %cx, %es\r
+    movw    %cx, %fs\r
+    movw    %cx, %gs \r
+    ret\r
diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm
new file mode 100644 (file)
index 0000000..eb014a5
--- /dev/null
@@ -0,0 +1,41 @@
+;------------------------------------------------------------------------------ ;\r
+; Copyright (c) 2012, 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
+;\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
+; Module Name:\r
+;\r
+;   AsmFuncs.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   Assembly function to set segment selectors.\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+.code\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmSetDataSelectors (\r
+;   IN UINT16   SelectorValue\r
+;   );\r
+;------------------------------------------------------------------------------\r
+AsmSetDataSelectors   PROC\r
+  mov     ds, cx\r
+  mov     es, cx\r
+  mov     fs, cx\r
+  mov     gs, cx\r
+  mov     ss, cx   \r
+  ret\r
+AsmSetDataSelectors   ENDP\r
+\r
+END\r