]> git.proxmox.com Git - mirror_edk2.git/commitdiff
SourceLevelDebugPkg/DebugAgent: Support IA32 processors without DE or FXSAVE/FXRESTOR
authorMichael Kinney <michael.d.kinney@intel.com>
Mon, 27 Apr 2015 19:53:36 +0000 (19:53 +0000)
committermdkinney <mdkinney@Edk2>
Mon, 27 Apr 2015 19:53:36 +0000 (19:53 +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>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17220 6f19259b-4bc3-4df7-8a09-765794883524

SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.S
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm
SourceLevelDebugPkg/Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf

index 9bd8fca6b6e361b53e2d1d0e0e8967daf8588721..1aef63f206fd33a5ee109f297d0f856f510d2636 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Supporting functions for IA32 architecture.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -28,6 +28,7 @@ InitializeDebugIdt (
   IA32_DESCRIPTOR            IdtDescriptor;\r
   UINTN                      Index;\r
   UINT16                     CodeSegment;\r
+  UINT32                     RegEdx;\r
 \r
   AsmReadIdtr (&IdtDescriptor);\r
 \r
@@ -59,9 +60,13 @@ InitializeDebugIdt (
   IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType   = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
   \r
   //\r
+  // If the CPU supports Debug Extensions(CPUID:01 EDX:BIT2), then \r
   // Set DE flag in CR4 to enable IO breakpoint\r
   //\r
-  AsmWriteCr4 (AsmReadCr4 () | BIT3);\r
+  AsmCpuid (1, NULL, NULL, NULL, &RegEdx);\r
+  if ((RegEdx & BIT2) != 0) {\r
+    AsmWriteCr4 (AsmReadCr4 () | BIT3);\r
+  }\r
 }\r
 \r
 /**\r
index efeaebc2c84a3b9d85ebc4e1a7c1ce9dd02bfa8d..a6a3da6a6bfd5b49f3cd6a3169bd026ae0574ae7 100644 (file)
@@ -1,6 +1,6 @@
 #------------------------------------------------------------------------------\r
 #\r
-# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2010 - 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
@@ -232,10 +232,25 @@ NoExtrPush:
   pushl   %edi\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
-  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
-  pushl   %eax\r
   movl    %cr3, %eax\r
   pushl   %eax\r
   movl    %cr2, %eax\r
@@ -303,7 +318,11 @@ NoExtrPush:
 ## 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, 0xae, 0x07   # fxsave [edi]\r
+L3:  \r
 \r
 ## save the exception data\r
   pushl   8(%esp)\r
@@ -322,7 +341,13 @@ NoExtrPush:
 \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, 0xae, 0x0e   # fxrstor [esi]\r
+L4:  \r
   addl    $512,%esp\r
 \r
 ## UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
index 377ade7c3b3ed1aae423e5c092e7a9388d4dcae9..44ed6f77102a54a360f3747e8b6679ca0dc61b84 100644 (file)
@@ -230,9 +230,21 @@ NoExtrPush:
     ;; 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     eax, 1\r
+    push    ebx         ; temporarily save value of ebx on stack \r
+    cpuid               ; use CPUID to determine if FXSAVE/FXRESTOR and\r
+                        ; DE are supported\r
+    pop     ebx         ; retore value of ebx that was overwritten by CPUID \r
     mov     eax, cr4\r
-    push    eax       ; push cr4 firstly\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     eax, cr3\r
     push    eax\r
@@ -313,7 +325,12 @@ NoExtrPush:
     mov     ecx, 128 ;= 512 / 4\r
     rep     stosd\r
     mov     edi, esp\r
+\r
+    test    edx, BIT24  ; Test for FXSAVE/FXRESTOR support.\r
+                        ; edx still contains result from CPUID above\r
+    jz      @F\r
     db 0fh, 0aeh, 00000111y ;fxsave [edi]\r
+@@:    \r
 \r
     ;; save the exception data\r
     push    dword ptr [ebp + 8]\r
@@ -329,7 +346,12 @@ NoExtrPush:
 \r
     ;; FX_SAVE_STATE_IA32 FxSaveState;\r
     mov     esi, esp\r
+    mov     eax, 1\r
+    cpuid               ; use CPUID to determine if FXSAVE/FXRESTOR are supported\r
+    test    edx, BIT24  ; Test for FXSAVE/FXRESTOR support\r
+    jz      @F\r
     db 0fh, 0aeh, 00001110y ; fxrstor [esi]\r
+@@:    \r
     add esp, 512\r
 \r
     ;; UINT32  Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;\r
index 60d3eb8bb3de95e3d3978dc132f8ffd828a97501..08cef0154f8b0b10e4695d5f03baf91751b22acb 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Supporting functions for X64 architecture.\r
 \r
-  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 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
@@ -28,6 +28,7 @@ InitializeDebugIdt (
   IA32_DESCRIPTOR            IdtDescriptor;\r
   UINTN                      Index;\r
   UINT16                     CodeSegment;\r
+  UINT32                     RegEdx;\r
 \r
   AsmReadIdtr (&IdtDescriptor);\r
 \r
@@ -61,9 +62,13 @@ InitializeDebugIdt (
   IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType        = IA32_IDT_GATE_TYPE_INTERRUPT_32;\r
 \r
   //\r
+  // If the CPU supports Debug Extensions(CPUID:01 EDX:BIT2), then \r
   // Set DE flag in CR4 to enable IO breakpoint\r
   //\r
-  AsmWriteCr4 (AsmReadCr4 () | BIT3);\r
+  AsmCpuid (1, NULL, NULL, NULL, &RegEdx);\r
+  if ((RegEdx & BIT2) != 0) {\r
+    AsmWriteCr4 (AsmReadCr4 () | BIT3);\r
+  }\r
 }\r
 \r
 /**\r
index 2a67a6b707112825b4bc4fdf5c491aff4e78c5d9..7ed5f5514c004d9529412c55e72a9237cb7c204d 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Debug Agent library instance for Dxe Core and Dxe modules.\r
 #\r
-#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -19,7 +19,7 @@
   MODULE_UNI_FILE                = DxeDebugAgentLib.uni\r
   FILE_GUID                      = BA6BAD25-B814-4747-B0B0-0FBB61D40B90\r
   MODULE_TYPE                    = DXE_DRIVER\r
-  VERSION_STRING                 = 0.7\r
+  VERSION_STRING                 = 0.8\r
   LIBRARY_CLASS                  = DebugAgentLib|DXE_CORE DXE_DRIVER\r
 \r
   CONSTRUCTOR                    = DxeDebugAgentLibConstructor\r
index 793962d507679808e6e07199f741d33c75cc4888..f2569dfaa4948e0bcad26d3e346003646733b8b8 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Debug Agent library instance for SEC Core and PEI modules.\r
 #\r
-#  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -19,7 +19,7 @@
   MODULE_UNI_FILE                = SecPeiDebugAgentLib.uni\r
   FILE_GUID                      = 508B7D59-CD4E-4a6b-A45B-6D3B2D90111E\r
   MODULE_TYPE                    = PEIM\r
-  VERSION_STRING                 = 0.7\r
+  VERSION_STRING                 = 0.8\r
   LIBRARY_CLASS                  = DebugAgentLib|SEC PEIM\r
 \r
 #\r
index b0581a314579a088bc2c9b54d637c936e15ada84..ca99933f3b0b06a750e5b620d315a2df0fd907a2 100644 (file)
@@ -19,7 +19,7 @@
   MODULE_UNI_FILE                = SmmDebugAgentLib.uni\r
   FILE_GUID                      = CB07D74C-598F-4268-A5D1-644FB4A481E8\r
   MODULE_TYPE                    = DXE_SMM_DRIVER\r
-  VERSION_STRING                 = 0.7\r
+  VERSION_STRING                 = 0.8\r
   LIBRARY_CLASS                  = DebugAgentLib|DXE_SMM_DRIVER\r
 \r
 #\r