Brian, In DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 mode, is there any difference in behavior if DR7 is always restored without checking state of BIT10?
Thanks, Mike -----Original Message----- From: Brian J. Johnson [mailto:bjohn...@sgi.com] Sent: Monday, March 16, 2015 8:26 AM To: edk2-devel@lists.sourceforge.net Cc: Fan, Jeff Subject: [edk2] [PATCH v2] PeCoffExtraActionLibDebug: Restore debug registers in PeCoffExtraActionLibDebug PeCoffExtraActionLibDebug uses the debug registers to pass module load information to the DebugAgent, then restores the old register values. However, it was missing code to restore Dr7 in the DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 case. This broke hardware breakpoints and watchpoints. It could also lose modifications the debugger made to Cr4. Restore the Dr7 and Cr4 values correctly in the DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3 case, as well as the DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT case. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brian J. Johnson <bjohn...@sgi.com> --- This fix has been built with OvmfPkg/OvmfPkgIa32X64.dsc, using the GCC48 toolchain under Ubuntu. It has been tested (32- and 64-bit mode) using qemu with tcg and a proprietary DebugAgentLib. We've also used it on hardware in a proprietary BIOS with various Intel CPUs, using the SourceLevelDebugPkg DebugAgentLib (an older version). It's been built successfully with the WINDDK compilers, but I'm not really in a position to build with MSVC. A note on Dr7 bit 10: the Intel SDM says that this bit always reads as 1, and that's the behavior I see on hardware. However, on simulators (including qemu in tcg mode) it often reads as 0. So I just ignore it in the patch below when determining if Dr7 needs to be restored. Changes in v2: - Generalized comment wording - Properly restore Cr4 as well Thanks, Brian .../PeCoffExtraActionLib.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c index 9bf76bf..2289a63 100644 --- a/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c +++ b/SourceLevelDebugPkg/Library/PeCoffExtraActionLibDebug/PeCoffExtraActionLib.c @@ -161,11 +161,17 @@ PeCoffLoaderExtraActionCommon ( if (!IsDrxEnabled (3, NewDr7) && (AsmReadDr3 () == IO_PORT_BREAKPOINT_ADDRESS)) { AsmWriteDr3 (Dr3); } - if (AsmReadCr4 () == (Cr4 | BIT3)) { - AsmWriteCr4 (Cr4); - } - if (NewDr7 == 0x20000480) { - AsmWriteDr7 (Dr7); + if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_IO_HW_BREAKPOINT) { + if (AsmReadCr4 () == (Cr4 | BIT3)) { + AsmWriteCr4 (Cr4); + } + if (NewDr7 == 0x20000480) { + AsmWriteDr7 (Dr7); + } + } else if (LoadImageMethod == DEBUG_LOAD_IMAGE_METHOD_SOFT_INT3) { + if ((NewDr7 & ~BIT10) == 0) { // H/w sets bit 10, some simulators don't + AsmWriteDr7 (Dr7); + } } // // Restore original IDT entry for INT1 if it was hooked. ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel