public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jeff Fan <jeff.fan@intel.com>
To: edk2-devel@lists.01.org
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Michael Kinney <michael.d.kinney@intel.com>,
	Feng Tian <feng.tian@intel.com>
Subject: [PATCH 6/9] UefiCpuPkg/CpuExceptionHandlerLib: Display PF Excption Data bit
Date: Sat,  1 Apr 2017 21:25:27 +0800	[thread overview]
Message-ID: <20170401132530.8340-7-jeff.fan@intel.com> (raw)
In-Reply-To: <20170401132530.8340-1-jeff.fan@intel.com>

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



  parent reply	other threads:[~2017-04-01 13:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-01 13:25 [PATCH 0/9] Export Dump CPU Context service Jeff Fan
2017-04-01 13:25 ` [PATCH 1/9] MdePkg/PeCoffGetEntryPointLib: Add PeCoffSerachImageBase() Jeff Fan
2017-04-01 13:25 ` [PATCH 2/9] MdeModulePkg/CpuExceptionHandlerLib: Add DumpCpuContext() Jeff Fan
2017-04-01 13:25 ` [PATCH 3/9] UefiCpuPkg/CpuExceptionHandlerLib: Rename internal DumpCpuContent() Jeff Fan
2017-04-01 13:25 ` [PATCH 4/9] UefiCpuPkg/CpuExceptionHandlerLib: Add DumpModuleImageInfo() Jeff Fan
2017-04-01 13:25 ` [PATCH 5/9] UefiCpuPkg/CpuExceptionHandlerLib: Add DumpCpuContext() implementation Jeff Fan
2017-04-01 13:25 ` Jeff Fan [this message]
2017-04-01 13:25 ` [PATCH 7/9] UefiCpuPkg/PiSmmCpuDxeSmm: Consume PeCoffSerachImageBase() Jeff Fan
2017-04-01 13:25 ` [PATCH 8/9] UefiCpuPkg/PiSmmCpuDxeSmm: Consume DumpCpuContext() Jeff Fan
2017-04-01 13:25 ` [PATCH 9/9] SourceLevelDebugPkg/DebugAgent.c: Consume PeCoffSerachImageBase() Jeff Fan
2017-04-07  0:41 ` [PATCH 0/9] Export Dump CPU Context service Yao, Jiewen
2017-04-07  0:46   ` Fan, Jeff
2017-04-07  0:50     ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170401132530.8340-7-jeff.fan@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox