[edk2] [PATCH 6/9] UefiCpuPkg/CpuExceptionHandlerLib: Display PF Excption Data bit

Jeff Fan posted 9 patches 7 years, 7 months ago
Only 8 patches received!
There is a newer version of this series
[edk2] [PATCH 6/9] UefiCpuPkg/CpuExceptionHandlerLib: Display PF Excption Data bit
Posted by Jeff Fan 7 years, 7 months ago
Page-fault exception data bit displaying is very useful.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
---
 .../CpuExceptionHandlerLib/CpuExceptionCommon.h    | 11 +++++++++
 .../Ia32/ArchExceptionHandler.c                    | 26 ++++++++++++++++------
 .../X64/ArchExceptionHandler.c                     | 26 ++++++++++++++++------
 3 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
index 5b3a9b9..e66a5df 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
@@ -30,6 +30,17 @@
 #define  CPU_INTERRUPT_NUM         256
 #define  HOOKAFTER_STUB_SIZE        16
 
+//
+// Exception Error Code of Page-Fault Exception
+//
+#define IA32_PF_EC_P                BIT0
+#define IA32_PF_EC_WR               BIT1
+#define IA32_PF_EC_US               BIT2
+#define IA32_PF_EC_RSVD             BIT3
+#define IA32_PF_EC_ID               BIT4
+#define IA32_PF_EC_PK               BIT5
+#define IA32_PF_EC_SGX              BIT15
+
 #include "ArchInterruptDefs.h"
 
 #define CPU_EXCEPTION_HANDLER_LIB_HOB_GUID \
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
index 59ed058..013e19b 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
@@ -126,19 +126,31 @@ DumpCpuContext (
     GetExceptionNameStr (ExceptionType),
     GetApicId ()
     );
-
+  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {
+    InternalPrintMessage (
+      "ExceptionData - %08x",
+      SystemContext.SystemContextIa32->ExceptionData
+      );
+    if (ExceptionType == EXCEPT_IA32_PAGE_FAULT) {
+      InternalPrintMessage (
+        "  I:%x R:%x U:%x W:%x P:%x PK:%x S:%x",
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_ID)   != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_RSVD) != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_US)   != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_WR)   != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_P)    != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_PK)   != 0,
+        (SystemContext.SystemContextIa32->ExceptionData & IA32_PF_EC_SGX)  != 0
+        );
+    }
+    InternalPrintMessage ("\n");
+  }
   InternalPrintMessage (
     "EIP  - %08x, CS  - %08x, EFLAGS - %08x\n",
     SystemContext.SystemContextIa32->Eip,
     SystemContext.SystemContextIa32->Cs,
     SystemContext.SystemContextIa32->Eflags
     );
-  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {
-    InternalPrintMessage (
-      "ExceptionData - %08x\n",
-      SystemContext.SystemContextIa32->ExceptionData
-      );
-  }
   InternalPrintMessage (
     "EAX  - %08x, ECX - %08x, EDX - %08x, EBX - %08x\n",
     SystemContext.SystemContextIa32->Eax,
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
index 5199559..98a776f 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
@@ -131,19 +131,31 @@ DumpCpuContext (
     GetExceptionNameStr (ExceptionType),
     GetApicId ()
     );
-
+  if ((mErrorCodeFlag & (1 << ExceptionType)) != 0) {
+    InternalPrintMessage (
+      "ExceptionData - %016lx",
+      SystemContext.SystemContextX64->ExceptionData
+      );
+    if (ExceptionType == EXCEPT_IA32_PAGE_FAULT) {
+      InternalPrintMessage (
+        "  I:%x R:%x U:%x W:%x P:%x PK:%x S:%x",
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_ID)   != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_RSVD) != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_US)   != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_WR)   != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_P)    != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_PK)   != 0,
+        (SystemContext.SystemContextX64->ExceptionData & IA32_PF_EC_SGX)  != 0
+        );
+    }
+    InternalPrintMessage ("\n");
+  }
   InternalPrintMessage (
     "RIP  - %016lx, CS  - %016lx, RFLAGS - %016lx\n",
     SystemContext.SystemContextX64->Rip,
     SystemContext.SystemContextX64->Cs,
     SystemContext.SystemContextX64->Rflags
     );
-  if (mErrorCodeFlag & (1 << ExceptionType)) {
-    InternalPrintMessage (
-      "ExceptionData - %016lx\n",
-      SystemContext.SystemContextX64->ExceptionData
-      );
-  }
   InternalPrintMessage (
     "RAX  - %016lx, RCX - %016lx, RDX - %016lx\n",
     SystemContext.SystemContextX64->Rax,
-- 
2.9.3.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel