]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/CpuExceptionHandlerLib: Support IA32 processors without DE or FXSAVE/FXRESTOR
authorMichael Kinney <michael.d.kinney@intel.com>
Mon, 27 Apr 2015 19:54:52 +0000 (19:54 +0000)
committermdkinney <mdkinney@Edk2>
Mon, 27 Apr 2015 19:54:52 +0000 (19:54 +0000)
Use CPUID Leaf 01 to detect support for debug extensions and FXSAVE/FXRESTOR instructions.
Do not enable those features in CR4 if they are not supported.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Jeff Fan <jeff.fan@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17221 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.S
UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.asm
UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf

index 85e01aad1e1430eca58f6e67f56e743022ef0573..316ed55b2ad28e626e9664eee7a5d55287f70461 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  CPU Exception Handler library instance for DXE modules.\r
 #\r
 ## @file\r
 #  CPU Exception Handler library instance for DXE modules.\r
 #\r
-#  Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2013 - 2015, 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
 #  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
@@ -18,7 +18,7 @@
   MODULE_UNI_FILE                = DxeCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = B6E9835A-EDCF-4748-98A8-27D3C722E02D\r
   MODULE_TYPE                    = DXE_DRIVER\r
   MODULE_UNI_FILE                = DxeCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = B6E9835A-EDCF-4748-98A8-27D3C722E02D\r
   MODULE_TYPE                    = DXE_DRIVER\r
-  VERSION_STRING                 = 1.0\r
+  VERSION_STRING                 = 1.1\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_CORE DXE_DRIVER UEFI_APPLICATION\r
 \r
 #\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_CORE DXE_DRIVER UEFI_APPLICATION\r
 \r
 #\r
index 627f3e513c072d0f43222296237d56d24a8bba9b..3676809b4bbf5555ac46eebfd9f32b1013069aef 100644 (file)
@@ -1,6 +1,6 @@
 #------------------------------------------------------------------------------\r
 #*\r
 #------------------------------------------------------------------------------\r
 #*\r
-#*   Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r
+#*   Copyright (c) 2012 - 2015, 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
 #*   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
@@ -447,10 +447,25 @@ ErrorCodeAndVectorOnStack:
     pushl   %eax\r
 \r
 #; UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
     pushl   %eax\r
 \r
 #; UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
+## insure FXSAVE/FXRSTOR is enabled in CR4...\r
+## ... while we're at it, make sure DE is also enabled...\r
+    mov     $1, %eax\r
+    pushl   %ebx                         # temporarily save value of ebx on stack \r
+    cpuid                                # use CPUID to determine if FXSAVE/FXRESTOR\r
+                                         # and DE are supported\r
+    popl    %ebx                         # retore value of ebx that was overwritten\r
+                                         # by CPUID \r
     movl    %cr4, %eax\r
     movl    %cr4, %eax\r
-    orl     $0x208, %eax\r
+    pushl   %eax                         # push cr4 firstly\r
+    testl   $BIT24, %edx                 # Test for FXSAVE/FXRESTOR support\r
+    jz      L1\r
+    orl     $BIT9, %eax                  # Set CR4.OSFXSR\r
+L1:    \r
+    testl   $BIT2, %edx                  # Test for Debugging Extensions support\r
+    jz      L2\r
+    orl     $BIT3, %eax                  # Set CR4.DE\r
+L2:    \r
     movl    %eax, %cr4\r
     movl    %eax, %cr4\r
-    pushl   %eax\r
     movl    %cr3, %eax\r
     pushl   %eax\r
     movl    %cr2, %eax\r
     movl    %cr3, %eax\r
     pushl   %eax\r
     movl    %cr2, %eax\r
@@ -477,7 +492,11 @@ ErrorCodeAndVectorOnStack:
 #; FX_SAVE_STATE_IA32 FxSaveState;\r
     subl    $512, %esp\r
     movl    %esp, %edi\r
 #; FX_SAVE_STATE_IA32 FxSaveState;\r
     subl    $512, %esp\r
     movl    %esp, %edi\r
+    testl   $BIT24, %edx     # Test for FXSAVE/FXRESTOR support.  \r
+                             # edx still contains result from CPUID above\r
+    jz      L3\r
     .byte      0x0f, 0x0ae, 0x07 #fxsave [edi]\r
     .byte      0x0f, 0x0ae, 0x07 #fxsave [edi]\r
+L3:  \r
 \r
 #; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear\r
     cld\r
 \r
 #; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear\r
     cld\r
@@ -503,7 +522,13 @@ ErrorCodeAndVectorOnStack:
 \r
 #; FX_SAVE_STATE_IA32 FxSaveState;\r
     movl    %esp, %esi\r
 \r
 #; FX_SAVE_STATE_IA32 FxSaveState;\r
     movl    %esp, %esi\r
+    movl    $1, %eax\r
+    cpuid                    # use CPUID to determine if FXSAVE/FXRESTOR \r
+                             # are supported\r
+    testl   $BIT24, %edx     # Test for FXSAVE/FXRESTOR support\r
+    jz      L4\r
     .byte      0x0f, 0x0ae, 0x0e # fxrstor [esi]\r
     .byte      0x0f, 0x0ae, 0x0e # fxrstor [esi]\r
+L4:  \r
     addl    $512, %esp\r
 \r
 #; UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
     addl    $512, %esp\r
 \r
 #; UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
index 3ff01b2a0c1112c7ca207f0a2ccf95fe246d89af..12bbec06909b2066a0608f6e13fbe5028cdcde84 100644 (file)
@@ -1,5 +1,5 @@
 ;------------------------------------------------------------------------------ ;\r
 ;------------------------------------------------------------------------------ ;\r
-; Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r
+; Copyright (c) 2012 - 2015, 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
 ; 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
@@ -250,10 +250,22 @@ ErrorCodeAndVectorOnStack:
     push    eax\r
 \r
 ;; UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
     push    eax\r
 \r
 ;; UINT32  Cr0, Cr1, Cr2, Cr3, Cr4;\r
+    mov     eax, 1\r
+    push    ebx         ; temporarily save value of ebx on stack \r
+    cpuid               ; use CPUID to determine if FXSAVE/FXRESTOR and DE \r
+                        ; are supported\r
+    pop     ebx         ; retore value of ebx that was overwritten by CPUID \r
     mov     eax, cr4\r
     mov     eax, cr4\r
-    or      eax, 208h\r
+    push    eax         ; push cr4 firstly\r
+    test    edx, BIT24  ; Test for FXSAVE/FXRESTOR support\r
+    jz      @F\r
+    or      eax, BIT9   ; Set CR4.OSFXSR\r
+@@:    \r
+    test    edx, BIT2   ; Test for Debugging Extensions support\r
+    jz      @F\r
+    or      eax, BIT3   ; Set CR4.DE\r
+@@:    \r
     mov     cr4, eax\r
     mov     cr4, eax\r
-    push    eax\r
     mov     eax, cr3\r
     push    eax\r
     mov     eax, cr2\r
     mov     eax, cr3\r
     push    eax\r
     mov     eax, cr2\r
@@ -280,7 +292,11 @@ ErrorCodeAndVectorOnStack:
 ;; FX_SAVE_STATE_IA32 FxSaveState;\r
     sub     esp, 512\r
     mov     edi, esp\r
 ;; FX_SAVE_STATE_IA32 FxSaveState;\r
     sub     esp, 512\r
     mov     edi, esp\r
+    test    edx, BIT24  ; Test for FXSAVE/FXRESTOR support.\r
+                        ; edx still contains result from CPUID above\r
+    jz      @F\r
     db      0fh, 0aeh, 07h ;fxsave [edi]\r
     db      0fh, 0aeh, 07h ;fxsave [edi]\r
+@@:    \r
 \r
 ;; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear\r
     cld\r
 \r
 ;; UEFI calling convention for IA32 requires that Direction flag in EFLAGs is clear\r
     cld\r
@@ -307,7 +323,13 @@ ErrorCodeAndVectorOnStack:
 \r
 ;; FX_SAVE_STATE_IA32 FxSaveState;\r
     mov     esi, esp\r
 \r
 ;; FX_SAVE_STATE_IA32 FxSaveState;\r
     mov     esi, esp\r
+    mov     eax, 1\r
+    cpuid               ; use CPUID to determine if FXSAVE/FXRESTOR\r
+                        ; are supported\r
+    test    edx, BIT24  ; Test for FXSAVE/FXRESTOR support\r
+    jz      @F\r
     db      0fh, 0aeh, 0eh ; fxrstor [esi]\r
     db      0fh, 0aeh, 0eh ; fxrstor [esi]\r
+@@:    \r
     add     esp, 512\r
 \r
 ;; UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
     add     esp, 512\r
 \r
 ;; UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
index 0530a15024ea7ccf12f69b2aa0e148570f0a78d2..951a6fe62cd2f0c36742726b6e2822a5b5e70da2 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  CPU Exception Handler library instance for SEC/PEI modules.\r
 #\r
 ## @file\r
 #  CPU Exception Handler library instance for SEC/PEI modules.\r
 #\r
-#  Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2012 - 2015, 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
 #  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
@@ -18,7 +18,7 @@
   MODULE_UNI_FILE                = SecPeiCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = CA4BBC99-DFC6-4234-B553-8B6586B7B113\r
   MODULE_TYPE                    = PEIM\r
   MODULE_UNI_FILE                = SecPeiCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = CA4BBC99-DFC6-4234-B553-8B6586B7B113\r
   MODULE_TYPE                    = PEIM\r
-  VERSION_STRING                 = 1.0\r
+  VERSION_STRING                 = 1.1\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|SEC PEI_CORE PEIM\r
 \r
 #\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|SEC PEI_CORE PEIM\r
 \r
 #\r
index 582fc8a9cf4539d663b48155b797f53d17b7f8c6..59f2d4d26d1cc2340823a618e7d963923fb5d655 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  CPU Exception Handler library instance for SMM modules.\r
 #\r
 ## @file\r
 #  CPU Exception Handler library instance for SMM modules.\r
 #\r
-#  Copyright (c) 2013 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2013 - 2015, 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
 #  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
@@ -18,7 +18,7 @@
   MODULE_UNI_FILE                = SmmCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = 8D2C439B-3981-42ff-9CE5-1B50ECA502D6\r
   MODULE_TYPE                    = DXE_SMM_DRIVER\r
   MODULE_UNI_FILE                = SmmCpuExceptionHandlerLib.uni\r
   FILE_GUID                      = 8D2C439B-3981-42ff-9CE5-1B50ECA502D6\r
   MODULE_TYPE                    = DXE_SMM_DRIVER\r
-  VERSION_STRING                 = 1.0\r
+  VERSION_STRING                 = 1.1\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_SMM_DRIVER\r
 \r
 #\r
   LIBRARY_CLASS                  = CpuExceptionHandlerLib|DXE_SMM_DRIVER\r
 \r
 #\r