From abef469fc1969f1142bf8add4275d573b4793e94 Mon Sep 17 00:00:00 2001 From: vanjeff Date: Wed, 22 Aug 2012 08:56:50 +0000 Subject: [PATCH] Set correct DS/ES/FS/GS/SS segment selectors after GDT loaded. Signed-off-by: Jeff Fan Reviewed-by: Rui Sun git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13667 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Acpi/S3Resume2Pei/Ia32/AsmFuncs.S | 38 ++++++++++++++++ .../Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm | 45 +++++++++++++++++++ .../Universal/Acpi/S3Resume2Pei/S3Resume.c | 35 +++++++++++++++ .../Acpi/S3Resume2Pei/S3Resume2Pei.inf | 8 ++++ .../Acpi/S3Resume2Pei/X64/AsmFuncs.S | 37 +++++++++++++++ .../Acpi/S3Resume2Pei/X64/AsmFuncs.asm | 41 +++++++++++++++++ 6 files changed, 204 insertions(+) create mode 100644 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S create mode 100644 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm create mode 100644 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S create mode 100644 UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S new file mode 100644 index 0000000000..ede19f21c3 --- /dev/null +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.S @@ -0,0 +1,38 @@ +#------------------------------------------------------------------------------ +#* +#* Copyright (c) 2012, 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. +#* +#* 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 diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm new file mode 100644 index 0000000000..79496c48d7 --- /dev/null +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/Ia32/AsmFuncs.asm @@ -0,0 +1,45 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2012, 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: +; +; 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 diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c index 07d83cc875..ad81c19590 100644 --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume.c @@ -193,6 +193,18 @@ S3RestoreConfig2 ( 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 @@ GLOBAL_REMOVE_IF_UNREFERENCED IA32_GDT mGdtEntries[] = { /* 0x40 */ {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, }; +#define DATA_SEGEMENT_SELECTOR 0x18 + // // IA32 Gdt register // @@ -701,6 +715,7 @@ S3ResumeExecuteBootScript ( IA32_DESCRIPTOR *IdtDescriptor; VOID *IdtBuffer; PEI_S3_RESUME_STATE *PeiS3ResumeState; + BOOLEAN InterruptStatus; DEBUG ((EFI_D_ERROR, "S3ResumeExecuteBootScript()\n")); @@ -769,10 +784,19 @@ S3ResumeExecuteBootScript ( *(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 @@ -873,6 +897,7 @@ S3RestoreConfig2 ( SMM_S3_RESUME_STATE *SmmS3ResumeState; VOID *GuidHob; BOOLEAN Build4GPageTableOnly; + BOOLEAN InterruptStatus; TempAcpiS3Context = 0; TempEfiBootScriptExecutorVariable = 0; @@ -1002,10 +1027,20 @@ S3RestoreConfig2 ( // 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, diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf index 53c66affde..db5d66e7fb 100644 --- a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf @@ -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 diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S new file mode 100644 index 0000000000..2ced09f35c --- /dev/null +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.S @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------ +#* +#* Copyright (c) 2012, 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. +#* +#* 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 diff --git a/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm new file mode 100644 index 0000000000..eb014a5862 --- /dev/null +++ b/UefiCpuPkg/Universal/Acpi/S3Resume2Pei/X64/AsmFuncs.asm @@ -0,0 +1,41 @@ +;------------------------------------------------------------------------------ ; +; Copyright (c) 2012, 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: +; +; 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