Use CPUID Leaf 01 to detect support for debug extensions and FXSAVE/FXRESTOR
instructions and 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.kin...@intel.com<mailto:michael.d.kin...@intel.com>>
Index: Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c
===================================================================
--- Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c (revision
17201)
+++ Library/DebugAgent/DebugAgentCommon/Ia32/ArchDebugSupport.c (working copy)
@@ -1,7 +1,7 @@
/** @file
Supporting functions for IA32 architecture.
- Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2015, 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
@@ -28,6 +28,7 @@
IA32_DESCRIPTOR IdtDescriptor;
UINTN Index;
UINT16 CodeSegment;
+ UINT32 RegEdx;
AsmReadIdtr (&IdtDescriptor);
@@ -59,9 +60,13 @@
IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType =
IA32_IDT_GATE_TYPE_INTERRUPT_32;
//
+ // If the CPU supports Debug Extensions(CPUID:01 EDX:BIT2), then
// Set DE flag in CR4 to enable IO breakpoint
//
- AsmWriteCr4 (AsmReadCr4 () | BIT3);
+ AsmCpuid (1, NULL, NULL, NULL, &RegEdx);
+ if ((RegEdx & BIT2) != 0) {
+ AsmWriteCr4 (AsmReadCr4 () | BIT3);
+ }
}
/**
Index: Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm
===================================================================
--- Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm
(revision 17201)
+++ Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.asm (working
copy)
@@ -230,9 +230,21 @@
;; UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
;; insure FXSAVE/FXRSTOR is enabled in CR4...
;; ... while we're at it, make sure DE is also enabled...
+ mov eax, 1
+ push ebx ; temporarily save value of ebx on stack
+ cpuid ; use CPUID to determine if FXSAVE/FXRESTOR and
+ ; DE are supported
+ pop ebx ; retore value of ebx that was overwritten by CPUID
mov eax, cr4
- push eax ; push cr4 firstly
- or eax, 208h
+ push eax ; push cr4 firstly
+ test edx, BIT24 ; Test for FXSAVE/FXRESTOR support
+ jz @F
+ or eax, BIT9 ; Set CR4.OSFXSR
+@@:
+ test edx, BIT2 ; Test for Debugging Extensions support
+ jz @F
+ or eax, BIT3 ; Set CR4.DE
+@@:
mov cr4, eax
mov eax, cr3
push eax
@@ -313,7 +325,12 @@
mov ecx, 128 ;= 512 / 4
rep stosd
mov edi, esp
+
+ test edx, BIT24 ; Test for FXSAVE/FXRESTOR support.
+ ; edx still contains result from CPUID above
+ jz @F
db 0fh, 0aeh, 00000111y ;fxsave [edi]
+@@:
;; save the exception data
push dword ptr [ebp + 8]
@@ -329,7 +346,12 @@
;; FX_SAVE_STATE_IA32 FxSaveState;
mov esi, esp
+ mov eax, 1
+ cpuid ; use CPUID to determine if FXSAVE/FXRESTOR are
supported
+ test edx, BIT24 ; Test for FXSAVE/FXRESTOR support
+ jz @F
db 0fh, 0aeh, 00001110y ; fxrstor [esi]
+@@:
add esp, 512
;; UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
Index: Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.S
===================================================================
--- Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.S (revision 17201)
+++ Library/DebugAgent/DebugAgentCommon/Ia32/AsmFuncs.S (working copy)
@@ -1,6 +1,6 @@
#------------------------------------------------------------------------------
#
-# Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2015, 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
@@ -232,10 +232,25 @@
pushl %edi
## UINT32 Cr0, Cr1, Cr2, Cr3, Cr4;
+## insure FXSAVE/FXRSTOR is enabled in CR4...
+## ... while we're at it, make sure DE is also enabled...
+ mov $1, %eax
+ pushl %ebx # temporarily save value of ebx on stack
+ cpuid # use CPUID to determine if
FXSAVE/FXRESTOR
+ # and DE are supported
+ popl %ebx # retore value of ebx that was
overwritten
+ # by CPUID
movl %cr4, %eax
- orl $0x208,%eax
+ pushl %eax # push cr4 firstly
+ testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support
+ jz L1
+ orl $BIT9, %eax # Set CR4.OSFXSR
+L1:
+ testl $BIT2, %edx # Test for Debugging Extensions support
+ jz L2
+ orl $BIT3, %eax # Set CR4.DE
+L2:
movl %eax, %cr4
- pushl %eax
movl %cr3, %eax
pushl %eax
movl %cr2, %eax
@@ -303,7 +318,11 @@
## FX_SAVE_STATE_IA32 FxSaveState;
subl $512,%esp
movl %esp,%edi
+ testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support.
+ # edx still contains result from CPUID above
+ jz L3
.byte 0x0f, 0xae, 0x07 # fxsave [edi]
+L3:
## save the exception data
pushl 8(%esp)
@@ -322,7 +341,13 @@
## FX_SAVE_STATE_IA32 FxSaveState;
movl %esp,%esi
+ movl $1, %eax
+ cpuid # use CPUID to determine if FXSAVE/FXRESTOR
+ # are supported
+ testl $BIT24, %edx # Test for FXSAVE/FXRESTOR support
+ jz L4
.byte 0x0f, 0xae, 0x0e # fxrstor [esi]
+L4:
addl $512,%esp
## UINT32 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
Index: Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c
===================================================================
--- Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c (revision
17201)
+++ Library/DebugAgent/DebugAgentCommon/X64/ArchDebugSupport.c (working copy)
@@ -1,7 +1,7 @@
/** @file
Supporting functions for X64 architecture.
- Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2015, 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
@@ -28,6 +28,7 @@
IA32_DESCRIPTOR IdtDescriptor;
UINTN Index;
UINT16 CodeSegment;
+ UINT32 RegEdx;
AsmReadIdtr (&IdtDescriptor);
@@ -61,9 +62,13 @@
IdtEntry[DEBUG_TIMER_VECTOR].Bits.GateType =
IA32_IDT_GATE_TYPE_INTERRUPT_32;
//
+ // If the CPU supports Debug Extensions(CPUID:01 EDX:BIT2), then
// Set DE flag in CR4 to enable IO breakpoint
//
- AsmWriteCr4 (AsmReadCr4 () | BIT3);
+ AsmCpuid (1, NULL, NULL, NULL, &RegEdx);
+ if ((RegEdx & BIT2) != 0) {
+ AsmWriteCr4 (AsmReadCr4 () | BIT3);
+ }
}
/**
Index: Library/DebugAgent/DxeDebugAgentLib.inf
===================================================================
--- Library/DebugAgent/DxeDebugAgentLib.inf (revision 17201)
+++ Library/DebugAgent/DxeDebugAgentLib.inf (working copy)
@@ -1,7 +1,7 @@
## @file
# Debug Agent library instance for Dxe Core and Dxe modules.
#
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2015, 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
@@ -19,7 +19,7 @@
MODULE_UNI_FILE = DxeDebugAgentLib.uni
FILE_GUID = BA6BAD25-B814-4747-B0B0-0FBB61D40B90
MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 0.7
+ VERSION_STRING = 0.8
LIBRARY_CLASS = DebugAgentLib|DXE_CORE DXE_DRIVER
CONSTRUCTOR = DxeDebugAgentLibConstructor
Index: Library/DebugAgent/SecPeiDebugAgentLib.inf
===================================================================
--- Library/DebugAgent/SecPeiDebugAgentLib.inf (revision 17201)
+++ Library/DebugAgent/SecPeiDebugAgentLib.inf (working copy)
@@ -1,7 +1,7 @@
## @file
# Debug Agent library instance for SEC Core and PEI modules.
#
-# Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2015, 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
@@ -19,7 +19,7 @@
MODULE_UNI_FILE = SecPeiDebugAgentLib.uni
FILE_GUID = 508B7D59-CD4E-4a6b-A45B-6D3B2D90111E
MODULE_TYPE = PEIM
- VERSION_STRING = 0.7
+ VERSION_STRING = 0.8
LIBRARY_CLASS = DebugAgentLib|SEC PEIM
#
Index: Library/DebugAgent/SmmDebugAgentLib.inf
===================================================================
--- Library/DebugAgent/SmmDebugAgentLib.inf (revision 17201)
+++ Library/DebugAgent/SmmDebugAgentLib.inf (working copy)
@@ -19,7 +19,7 @@
MODULE_UNI_FILE = SmmDebugAgentLib.uni
FILE_GUID = CB07D74C-598F-4268-A5D1-644FB4A481E8
MODULE_TYPE = DXE_SMM_DRIVER
- VERSION_STRING = 0.7
+ VERSION_STRING = 0.8
LIBRARY_CLASS = DebugAgentLib|DXE_SMM_DRIVER
#
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel