public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib
@ 2019-03-28  8:09 Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
                   ` (16 more replies)
  0 siblings, 17 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:09 UTC (permalink / raw)
  To: edk2-devel
  Cc: Michael D Kinney, Leif Lindholm, Ard Biesheuvel, Jordan Justen,
	Laszlo Ersek, Chasel Chiu, Nate DeSimone, Star Zeng, Jian J Wang,
	Hao Wu, Ray Ni, Liming Gao, Sean Brogan, Michael Turner,
	Bret Barkelew

Add a new API DebugVPrint to all the instances of DebugLib.
This API is added to provide a function who want to implement
special debug function with '...' parameter.
Add a PEIM to install gEdkiiDebugPpiGuid, and implement a PEI
debug library instance base on it. All PEIMs except pei core
type can use the PeiDebugLibDebugPpi to reduce its image size.

V2: 
Remove redundant code in DebugPrint.
Fix some coding sytle issues.
Remove some unenforced descirption in the comments of DebugVPrint.

V3:
Add the new API DebugBPrint, it is more useful for consumers which
are care of compatible issue.
Change the interface in gEdkiiDebugPpiGuid. VA_LIST is inappropriate
to appeared in protocol or ppi because different compilers compile
it to different type. It may be a pointer or a structure.

V4:
Sync the implement on MdeModulePkg/PeiDxeDebugLibReportStatusCode to
IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode. While the format
string is too long just truncate it instead of return.
Fix and update some functions' comments.

V5:
Correct some comments of inf file.
Put all implement into one C file for DebugServicePei.
Use the directly return instead of CpuDeadLoop in PeiDebugLibDebugPpi.
Rename the mDebugPpi to mEdkiiDebugPpi because it has a same name in DeubServicePpi.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>

Bret Barkelew (13):
  MdePkg/DebugLib.h: Add new APIs for DebugLib
  MdePkg/BaseDebugLibNull: Add new APIs for DebugLib
  MdePkg/BaseDebugLibSerialPort: Add new APIs
  MdePkg/UefidebugLibConOut: Add new APIs
  MdePkg/UefiDebugLibStdErr: Add new APIs
  MdePkg/DxeRuntimeDebugLibSerialPort: Add new APIs
  MdePkg/UefiDebuglibDebugPortProtocol: Add new APIs
  ArmPkg/SemiHostingDebugLib: Add new APIs
  OvmfPkg/PlatformDebugLibIoPort: Add new APIs
  IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs
  IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  MdeModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs

Liming Gao (1):
  MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib

Zhichao Gao (3):
  MdeModulePkg: Add definitions for EDKII DEBUG PPI
  MdeModulePkg: Add a PEIM to install Debug PPI
  MdeModulePkg: Add PEIM and lib to dsc file

 ArmPkg/Library/SemiHostingDebugLib/DebugLib.c | 106 +++-
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c | 179 +++++--
 .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++-
 .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++-
 MdeModulePkg/Include/Ppi/Debug.h              |  82 ++++
 .../Library/PeiDebugLibDebugPpi/DebugLib.c    | 456 ++++++++++++++++++
 .../PeiDebugLibDebugPpi.inf                   |  56 +++
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c | 177 +++++--
 MdeModulePkg/MdeModulePkg.dec                 |   3 +
 MdeModulePkg/MdeModulePkg.dsc                 |   3 +
 .../Universal/DebugServicePei/DebugService.h  |  56 +++
 .../DebugServicePei/DebugServicePei.c         | 100 ++++
 .../DebugServicePei/DebugServicePei.inf       |  51 ++
 .../DebugServicePei/DebugServicePei.uni       |  20 +
 MdePkg/Include/Library/DebugLib.h             |  52 +-
 MdePkg/Library/BaseDebugLibNull/DebugLib.c    |  56 ++-
 .../Library/BaseDebugLibSerialPort/DebugLib.c | 106 +++-
 .../DxeRuntimeDebugLibSerialPort/DebugLib.c   | 106 +++-
 MdePkg/Library/UefiDebugLibConOut/DebugLib.c  | 106 +++-
 .../UefiDebugLibDebugPortProtocol/DebugLib.c  | 106 +++-
 MdePkg/Library/UefiDebugLibStdErr/DebugLib.c  | 107 +++-
 .../Library/PlatformDebugLibIoPort/DebugLib.c | 106 +++-
 22 files changed, 2132 insertions(+), 108 deletions(-)
 create mode 100644 MdeModulePkg/Include/Ppi/Debug.h
 create mode 100644 MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
 create mode 100644 MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugService.h
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.uni

-- 
2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH V5 01/17] MdePkg/DebugLib.h: Add new APIs for DebugLib
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 02/17] MdePkg/BaseDebugLibNull: " Zhichao Gao
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs DebugVPrint and DebugBPrint prototype
definition in the DebugLib header file. These APIs
would expose a print routine with VaList parameter
and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 MdePkg/Include/Library/DebugLib.h | 52 ++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index e6a7a357b2..77fb1ee259 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -8,7 +8,7 @@
   of size reduction when compiler optimization is disabled. If MDEPKG_NDEBUG is
   defined, then debug and assert related macros wrapped by it are the NULL implementations.
 
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2019, 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 that accompanies this distribution.
 The full text of the license may be found at
@@ -101,6 +101,56 @@ DebugPrint (
   );
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  );
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  );
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 02/17] MdePkg/BaseDebugLibNull: Add new APIs for DebugLib
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 03/17] MdePkg/BaseDebugLibSerialPort: Add new APIs Zhichao Gao
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 MdePkg/Library/BaseDebugLibNull/DebugLib.c | 56 +++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Library/BaseDebugLibNull/DebugLib.c b/MdePkg/Library/BaseDebugLibNull/DebugLib.c
index 1a7d4aba79..f9c9ac7189 100644
--- a/MdePkg/Library/BaseDebugLibNull/DebugLib.c
+++ b/MdePkg/Library/BaseDebugLibNull/DebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   Null Base Debug Library instance with empty functions.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -41,6 +41,60 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 03/17] MdePkg/BaseDebugLibSerialPort: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 02/17] MdePkg/BaseDebugLibNull: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 04/17] MdePkg/UefidebugLibConOut: " Zhichao Gao
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 .../Library/BaseDebugLibSerialPort/DebugLib.c | 106 +++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c b/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
index ffb84b39e5..d875050371 100644
--- a/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
+++ b/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
@@ -7,7 +7,7 @@
   being blocked.  This may occur if a key(s) are pressed in a terminal emulator
   used to monitor the DEBUG() and ASSERT() messages.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -32,6 +32,12 @@
 //
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   The constructor function initialize the Serial Port Library
 
@@ -70,9 +76,41 @@ DebugPrint (
   ...
   )
 {
-  CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
   VA_LIST  Marker;
 
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
+
   //
   // If Format is NULL, then ASSERT().
   //
@@ -88,9 +126,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to a Serial Port
@@ -99,6 +139,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 04/17] MdePkg/UefidebugLibConOut: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (2 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 03/17] MdePkg/BaseDebugLibSerialPort: Add new APIs Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 05/17] MdePkg/UefiDebugLibStdErr: " Zhichao Gao
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 MdePkg/Library/UefiDebugLibConOut/DebugLib.c | 106 ++++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/UefiDebugLibConOut/DebugLib.c b/MdePkg/Library/UefiDebugLibConOut/DebugLib.c
index f04207c93f..c60ac04a24 100644
--- a/MdePkg/Library/UefiDebugLibConOut/DebugLib.c
+++ b/MdePkg/Library/UefiDebugLibConOut/DebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   UEFI Debug Library that sends messages to the Console Output Device in the EFI System Table.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -27,6 +27,12 @@
 //
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Prints a debug message to the debug output device if the specified error level is enabled.
 
@@ -50,9 +56,41 @@ DebugPrint (
   ...
   )
 {
-  CHAR16   Buffer[MAX_DEBUG_MESSAGE_LENGTH];
   VA_LIST  Marker;
 
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  CHAR16   Buffer[MAX_DEBUG_MESSAGE_LENGTH];
+
   //
   // If Format is NULL, then ASSERT().
   //
@@ -68,9 +106,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to a Unicode String
   //
-  VA_START (Marker, Format);
-  UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH,  Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH,  Format, VaListMarker);
+  } else {
+    UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH,  Format, BaseListMarker);
+  }
 
 
   //
@@ -82,6 +122,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 05/17] MdePkg/UefiDebugLibStdErr: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (3 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 04/17] MdePkg/UefidebugLibConOut: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 06/17] MdePkg/DxeRuntimeDebugLibSerialPort: " Zhichao Gao
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 MdePkg/Library/UefiDebugLibStdErr/DebugLib.c | 107 ++++++++++++++++++-
 1 file changed, 102 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c b/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
index 6830a3caa1..81fcf168e5 100644
--- a/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
+++ b/MdePkg/Library/UefiDebugLibStdErr/DebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   UEFI Debug Lib that sends messages to the Standard Error Device in the EFI System Table.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -29,6 +29,13 @@
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
+
 /**
   Prints a debug message to the debug output device if the specified error level is enabled.
 
@@ -51,9 +58,41 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR16   Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
 
   //
   // If Format is NULL, then ASSERT().
@@ -70,9 +109,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to a Unicode String
   //
-  VA_START (Marker, Format);
-  UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    UnicodeVSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, VaListMarker);
+  } else {
+    UnicodeBSPrintAsciiFormat (Buffer, MAX_DEBUG_MESSAGE_LENGTH, Format, BaseListMarker);
+  }
 
   //
   // Send the print string to the Standard Error device
@@ -83,6 +124,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 06/17] MdePkg/DxeRuntimeDebugLibSerialPort: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (4 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 05/17] MdePkg/UefiDebugLibStdErr: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 07/17] MdePkg/UefiDebuglibDebugPortProtocol: " Zhichao Gao
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 .../DxeRuntimeDebugLibSerialPort/DebugLib.c   | 106 +++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c b/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
index e1266f77fa..4af1cde488 100644
--- a/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
+++ b/MdePkg/Library/DxeRuntimeDebugLibSerialPort/DebugLib.c
@@ -4,7 +4,7 @@
   been called, to prevent touching hardware that is no longer owned by the
   firmware.
 
-  Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
   Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
 
   This program and the accompanying materials
@@ -34,6 +34,12 @@ STATIC BOOLEAN        mEfiAtRuntime = FALSE;
 //
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Set AtRuntime flag as TRUE after ExitBootServices.
 
@@ -125,9 +131,41 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
 
   if (mEfiAtRuntime) {
     return;
@@ -148,9 +186,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to a Serial Port
@@ -159,6 +199,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 07/17] MdePkg/UefiDebuglibDebugPortProtocol: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (5 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 06/17] MdePkg/DxeRuntimeDebugLibSerialPort: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 08/17] ArmPkg/SemiHostingDebugLib: " Zhichao Gao
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Michael D Kinney, Liming Gao, Sean Brogan,
	Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 .../UefiDebugLibDebugPortProtocol/DebugLib.c  | 106 +++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c b/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
index c2209f4123..b1ad2af20a 100644
--- a/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
+++ b/MdePkg/Library/UefiDebugLibDebugPortProtocol/DebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   UEFI Debug Library that sends messages to EFI_DEBUGPORT_PROTOCOL.Write.
 
-  Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015 - 2019, 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
@@ -37,6 +37,12 @@
 
 EFI_DEBUGPORT_PROTOCOL *mDebugPort = NULL;
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Send message to DebugPort Protocol.
 
@@ -106,9 +112,41 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8      Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST    Marker;
 
   //
   // If Format is NULL, then ASSERT().
@@ -125,9 +163,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to EFI_DEBUGPORT_PROTOCOL.Write.
@@ -136,6 +176,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 08/17] ArmPkg/SemiHostingDebugLib: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (6 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 07/17] MdePkg/UefiDebuglibDebugPortProtocol: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 09/17] OvmfPkg/PlatformDebugLibIoPort: " Zhichao Gao
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Leif Lindholm, Ard Biesheuvel, Liming Gao,
	Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
 ArmPkg/Library/SemiHostingDebugLib/DebugLib.c | 106 +++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/ArmPkg/Library/SemiHostingDebugLib/DebugLib.c b/ArmPkg/Library/SemiHostingDebugLib/DebugLib.c
index ec03edb774..a368dd43b8 100644
--- a/ArmPkg/Library/SemiHostingDebugLib/DebugLib.c
+++ b/ArmPkg/Library/SemiHostingDebugLib/DebugLib.c
@@ -1,7 +1,7 @@
 /** @file
   UEFI Debug Library that uses PrintLib to send messages to STDERR.
 
-  Copyright (c) 2006 - 2007, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
   Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -27,6 +27,12 @@
 //
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
 
   Prints a debug message to the debug output device if the specified error level is enabled.
@@ -48,9 +54,41 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8    AsciiBuffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
 
   //
   // If Format is NULL, then ASSERT().
@@ -67,14 +105,72 @@ DebugPrint (
   //
   // Convert the DEBUG() message to a Unicode String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (AsciiBuffer, sizeof (AsciiBuffer), Format, BaseListMarker);
+  }
 
   SemihostWriteString (AsciiBuffer);
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
 
   Prints an assert message containing a filename, line number, and description.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 09/17] OvmfPkg/PlatformDebugLibIoPort: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (7 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 08/17] ArmPkg/SemiHostingDebugLib: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Jordan Justen, Laszlo Ersek, Ard Biesheuvel,
	Liming Gao, Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
---
 .../Library/PlatformDebugLibIoPort/DebugLib.c | 106 +++++++++++++++++-
 1 file changed, 101 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
index 36cde54976..cda35faf66 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
@@ -2,7 +2,7 @@
   Base Debug library instance for QEMU debug port.
   It uses PrintLib to send debug messages to a fixed I/O port.
 
-  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
   Copyright (c) 2012, Red Hat, Inc.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -29,6 +29,12 @@
 //
 #define MAX_DEBUG_MESSAGE_LENGTH  0x100
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Prints a debug message to the debug output device if the specified error level is enabled.
 
@@ -51,9 +57,41 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
   UINTN    Length;
 
   //
@@ -72,9 +110,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to the debug I/O port
@@ -83,6 +123,62 @@ DebugPrint (
 }
 
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (8 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 09/17] OvmfPkg/PlatformDebugLibIoPort: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:44   ` Chiu, Chasel
  2019-03-28  8:10 ` [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Chasel Chiu, Nate DeSimone, Star Zeng, Liming Gao,
	Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
---
 .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++++++++++++++++-
 1 file changed, 98 insertions(+), 5 deletions(-)

diff --git a/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c b/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
index 73bb08e357..8b322c038e 100644
--- a/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
+++ b/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2019, 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,12 @@
 
 CONST CHAR8  *mHexTable = "0123456789ABCDEF";
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Get stack frame pointer of function call.
 
@@ -62,9 +68,40 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
 
   //
   // If Format is NULL, then ASSERT().
@@ -88,9 +125,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to a Serial Port
@@ -98,6 +137,60 @@ DebugPrint (
   SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
 }
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
 /**
   Convert an UINT32 value into HEX string sepcified by Buffer.
 
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (9 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:44   ` Chiu, Chasel
  2019-03-28  8:10 ` [PATCH V5 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
                   ` (5 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Chasel Chiu, Nate DeSimone, Star Zeng, Liming Gao,
	Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
---
 .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++++++++++++++++-
 1 file changed, 98 insertions(+), 5 deletions(-)

diff --git a/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c b/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
index 73bb08e357..8b322c038e 100644
--- a/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
+++ b/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2014 - 2019, 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,12 @@
 
 CONST CHAR8  *mHexTable = "0123456789ABCDEF";
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Get stack frame pointer of function call.
 
@@ -62,9 +68,40 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
-  VA_LIST  Marker;
 
   //
   // If Format is NULL, then ASSERT().
@@ -88,9 +125,11 @@ DebugPrint (
   //
   // Convert the DEBUG() message to an ASCII String
   //
-  VA_START (Marker, Format);
-  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
-  VA_END (Marker);
+  if (BaseListMarker == NULL) {
+    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
 
   //
   // Send the print string to a Serial Port
@@ -98,6 +137,60 @@ DebugPrint (
   SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
 }
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
 /**
   Convert an UINT32 value into HEX string sepcified by Buffer.
 
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (10 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel; +Cc: Bret Barkelew, Liming Gao, Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
---
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c | 179 +++++++++++++++---
 1 file changed, 148 insertions(+), 31 deletions(-)

diff --git a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index b0445115a9..3f3778d84a 100644
--- a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
+++ b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
@@ -4,7 +4,7 @@
   Note that if the debug message length is larger than the maximum allowable
   record length, then the debug message will be ignored directly.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -27,6 +27,12 @@
 #include <Library/PcdLib.h>
 #include <Library/DebugPrintErrorLevelLib.h>
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Prints a debug message to the debug output device if the specified error level is enabled.
 
@@ -52,13 +58,49 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  Only one list type is used.
+  If BaseListMarker == NULL, then use VaListMarker.
+  Otherwise use BaseListMarker and the VaListMarker should be initilized as
+  mVaListNull.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   UINT64          Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];
   EFI_DEBUG_INFO  *DebugInfo;
   UINTN           TotalSize;
   UINTN           DestBufferSize;
-  VA_LIST         VaListMarker;
-  BASE_LIST       BaseListMarker;
+  BASE_LIST       BaseListMarkerPointer;
   CHAR8           *FormatString;
   BOOLEAN         Long;
 
@@ -79,38 +121,38 @@ DebugPrint (
   // Note that the passing-in format string and variable parameters will be constructed to
   // the following layout:
   //
-  //         Buffer->|------------------------|
-  //                 |         Padding        | 4 bytes
-  //      DebugInfo->|------------------------|
-  //                 |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)
-  // BaseListMarker->|------------------------|
-  //                 |           ...          |
-  //                 |   variable arguments   | 12 * sizeof (UINT64)
-  //                 |           ...          |
-  //                 |------------------------|
-  //                 |       Format String    |
-  //                 |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
+  //                Buffer->|------------------------|
+  //                        |         Padding        | 4 bytes
+  //             DebugInfo->|------------------------|
+  //                        |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)
+  // BaseListMarkerPointer->|------------------------|
+  //                        |           ...          |
+  //                        |   variable arguments   | 12 * sizeof (UINT64)
+  //                        |           ...          |
+  //                        |------------------------|
+  //                        |       Format String    |
+  //                        |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
   //
   TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);
 
   //
-  // If the TotalSize is larger than the maximum record size, then return
+  // If the TotalSize is larger than the maximum record size, then truncate it.
   //
   if (TotalSize > sizeof (Buffer)) {
-    return;
+    TotalSize = sizeof (Buffer);
   }
 
   //
   // Fill in EFI_DEBUG_INFO
   //
-  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is
-  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause
+  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarkerPointer is
+  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarkerPointer will cause
   // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))
-  // just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned.
+  // just makes address of BaseListMarkerPointer, which follows DebugInfo, 64-bit aligned.
   //
   DebugInfo             = (EFI_DEBUG_INFO *)(Buffer) + 1;
   DebugInfo->ErrorLevel = (UINT32)ErrorLevel;
-  BaseListMarker        = (BASE_LIST)(DebugInfo + 1);
+  BaseListMarkerPointer = (BASE_LIST)(DebugInfo + 1);
   FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
 
   //
@@ -129,7 +171,6 @@ DebugPrint (
   // of format in DEBUG string, which is followed by the DEBUG format string.
   // Here we will process the variable arguments and pack them in this area.
   //
-  VA_START (VaListMarker, Format);
   for (; *Format != '\0'; Format++) {
     //
     // Only format with prefix % is processed.
@@ -166,7 +207,11 @@ DebugPrint (
         // '*' in format field means the precision of the field is specified by
         // a UINTN argument in the argument list.
         //
-        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);
+        }
         continue;
       }
       if (*Format == '\0') {
@@ -191,16 +236,36 @@ DebugPrint (
     }
     if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') {
       if (Long) {
-        BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, INT64) = VA_ARG (VaListMarker, INT64);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, INT64) = BASE_ARG (BaseListMarker, INT64);
+        }
       } else {
-        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, int) = VA_ARG (VaListMarker, int);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, int) = BASE_ARG (BaseListMarker, int);
+        }
       }
     } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {
-      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, VOID *) = VA_ARG (VaListMarker, VOID *);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, VOID *) = BASE_ARG (BaseListMarker, VOID *);
+      }
     } else if (*Format == 'c') {
-      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);
+      }
     } else if (*Format == 'r') {
-      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = BASE_ARG (BaseListMarker, RETURN_STATUS);
+      }
     }
 
     //
@@ -208,17 +273,15 @@ DebugPrint (
     // This indicates that the DEBUG() macro is passing in more argument than can be handled by
     // the EFI_DEBUG_INFO record
     //
-    ASSERT ((CHAR8 *)BaseListMarker <= FormatString);
+    ASSERT ((CHAR8 *)BaseListMarkerPointer <= FormatString);
 
     //
     // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return
     //
-    if ((CHAR8 *)BaseListMarker > FormatString) {
-      VA_END (VaListMarker);
+    if ((CHAR8 *)BaseListMarkerPointer > FormatString) {
       return;
     }
   }
-  VA_END (VaListMarker);
 
   //
   // Send the DebugInfo record
@@ -234,6 +297,60 @@ DebugPrint (
     );
 }
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (11 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Bret Barkelew, Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao,
	Sean Brogan, Michael Turner

From: Bret Barkelew <Bret.Barkelew@microsoft.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395

Add new APIs' implementation (DebugVPrint, DebugBPrint)
in the DebugLib instance. These APIs would expose print
routines with VaList parameter and BaseList parameter.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
---
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c | 177 +++++++++++++++---
 1 file changed, 147 insertions(+), 30 deletions(-)

diff --git a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index 6f0f416273..6290481173 100644
--- a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
+++ b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
@@ -4,7 +4,7 @@
   Note that if the debug message length is larger than the maximum allowable
   record length, then the debug message will be ignored directly.
 
-  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2019, 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
@@ -27,6 +27,12 @@
 #include <Library/PcdLib.h>
 #include <Library/DebugPrintErrorLevelLib.h>
 
+//
+// VA_LIST can not initialize to NULL for all compiler, so we use this to
+// indicate a null VA_LIST
+//
+VA_LIST     mVaListNull;
+
 /**
   Prints a debug message to the debug output device if the specified error level is enabled.
 
@@ -52,12 +58,48 @@ DebugPrint (
   IN  CONST CHAR8  *Format,
   ...
   )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled base on Null-terminated format string and a
+  VA_LIST argument list or a BASE_LIST argument list.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  Only one list type is used.
+  If BaseListMarker == NULL, then use VaListMarker.
+  Otherwise use BaseListMarker and the VaListMarker should be initilized as
+  mVaListNull.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  VaListMarker    VA_LIST marker for the variable argument list.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+DebugPrintMarker (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker,
+  IN  BASE_LIST     BaseListMarker
+  )
 {
   UINT64          Buffer[(EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)) + 1];
   EFI_DEBUG_INFO  *DebugInfo;
   UINTN           TotalSize;
-  VA_LIST         VaListMarker;
-  BASE_LIST       BaseListMarker;
+  BASE_LIST       BaseListMarkerPointer;
   CHAR8           *FormatString;
   BOOLEAN         Long;
 
@@ -78,22 +120,22 @@ DebugPrint (
   // Note that the passing-in format string and variable parameters will be constructed to
   // the following layout:
   //
-  //         Buffer->|------------------------|
-  //                 |         Padding        | 4 bytes
-  //      DebugInfo->|------------------------|
-  //                 |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)
-  // BaseListMarker->|------------------------|
-  //                 |           ...          |
-  //                 |   variable arguments   | 12 * sizeof (UINT64)
-  //                 |           ...          |
-  //                 |------------------------|
-  //                 |       Format String    |
-  //                 |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
+  //                Buffer->|------------------------|
+  //                        |         Padding        | 4 bytes
+  //             DebugInfo->|------------------------|
+  //                        |      EFI_DEBUG_INFO    | sizeof(EFI_DEBUG_INFO)
+  // BaseListMarkerPointer->|------------------------|
+  //                        |           ...          |
+  //                        |   variable arguments   | 12 * sizeof (UINT64)
+  //                        |           ...          |
+  //                        |------------------------|
+  //                        |       Format String    |
+  //                        |------------------------|<- (UINT8 *)Buffer + sizeof(Buffer)
   //
   TotalSize = 4 + sizeof (EFI_DEBUG_INFO) + 12 * sizeof (UINT64) + AsciiStrSize (Format);
 
   //
-  // If the TotalSize is larger than the maximum record size, then return
+  // If the TotalSize is larger than the maximum record size, then truncate it.
   //
   if (TotalSize > sizeof (Buffer)) {
     TotalSize = sizeof (Buffer);
@@ -102,14 +144,14 @@ DebugPrint (
   //
   // Fill in EFI_DEBUG_INFO
   //
-  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarker is
-  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarker will cause
+  // Here we skip the first 4 bytes of Buffer, because we must ensure BaseListMarkerPointer is
+  // 64-bit aligned, otherwise retrieving 64-bit parameter from BaseListMarkerPointer will cause
   // exception on IPF. Buffer starts at 64-bit aligned address, so skipping 4 types (sizeof(EFI_DEBUG_INFO))
-  // just makes address of BaseListMarker, which follows DebugInfo, 64-bit aligned.
+  // just makes address of BaseListMarkerPointer, which follows DebugInfo, 64-bit aligned.
   //
   DebugInfo             = (EFI_DEBUG_INFO *)(Buffer) + 1;
   DebugInfo->ErrorLevel = (UINT32)ErrorLevel;
-  BaseListMarker        = (BASE_LIST)(DebugInfo + 1);
+  BaseListMarkerPointer = (BASE_LIST)(DebugInfo + 1);
   FormatString          = (CHAR8 *)((UINT64 *)(DebugInfo + 1) + 12);
 
   //
@@ -125,7 +167,6 @@ DebugPrint (
   // of format in DEBUG string, which is followed by the DEBUG format string.
   // Here we will process the variable arguments and pack them in this area.
   //
-  VA_START (VaListMarker, Format);
 
   //
   // Use the actual format string.
@@ -167,7 +208,11 @@ DebugPrint (
         // '*' in format field means the precision of the field is specified by
         // a UINTN argument in the argument list.
         //
-        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);
+        }
         continue;
       }
       if (*Format == '\0') {
@@ -192,16 +237,36 @@ DebugPrint (
     }
     if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') {
       if (Long) {
-        BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, INT64) = VA_ARG (VaListMarker, INT64);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, INT64) = BASE_ARG (BaseListMarker, INT64);
+        }
       } else {
-        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
+        if (BaseListMarker == NULL) {
+          BASE_ARG (BaseListMarkerPointer, int) = VA_ARG (VaListMarker, int);
+        } else {
+          BASE_ARG (BaseListMarkerPointer, int) = BASE_ARG (BaseListMarker, int);
+        }
       }
     } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {
-      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, VOID *) = VA_ARG (VaListMarker, VOID *);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, VOID *) = BASE_ARG (BaseListMarker, VOID *);
+      }
     } else if (*Format == 'c') {
-      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, UINTN) = VA_ARG (VaListMarker, UINTN);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, UINTN) = BASE_ARG (BaseListMarker, UINTN);
+      }
     } else if (*Format == 'r') {
-      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
+      if (BaseListMarker == NULL) {
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
+      } else {
+        BASE_ARG (BaseListMarkerPointer, RETURN_STATUS) = BASE_ARG (BaseListMarker, RETURN_STATUS);
+      }
     }
 
     //
@@ -209,17 +274,15 @@ DebugPrint (
     // This indicates that the DEBUG() macro is passing in more argument than can be handled by
     // the EFI_DEBUG_INFO record
     //
-    ASSERT ((CHAR8 *)BaseListMarker <= FormatString);
+    ASSERT ((CHAR8 *)BaseListMarkerPointer <= FormatString);
 
     //
     // If the converted BASE_LIST is larger than the 12 * sizeof (UINT64) allocated bytes, then return
     //
-    if ((CHAR8 *)BaseListMarker > FormatString) {
-      VA_END (VaListMarker);
+    if ((CHAR8 *)BaseListMarkerPointer > FormatString) {
       return;
     }
   }
-  VA_END (VaListMarker);
 
   //
   // Send the DebugInfo record
@@ -235,6 +298,60 @@ DebugPrint (
     );
 }
 
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL);
+}
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker);
+}
+
 /**
   Prints an assert message containing a filename, line number, and description.
   This may be followed by a breakpoint or a dead loop.
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (12 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28 10:13   ` Ni, Ray
  2019-03-28  8:10 ` [PATCH V5 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549

Add a debug PPI for PEI phase. This PPI will provide basic
services of debug. PEI debug lib instance can use these
services to implement debug function to reduce the PEIMs
which consume the debug lib.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
---
 MdeModulePkg/Include/Ppi/Debug.h | 82 ++++++++++++++++++++++++++++++++
 MdeModulePkg/MdeModulePkg.dec    |  3 ++
 2 files changed, 85 insertions(+)
 create mode 100644 MdeModulePkg/Include/Ppi/Debug.h

diff --git a/MdeModulePkg/Include/Ppi/Debug.h b/MdeModulePkg/Include/Ppi/Debug.h
new file mode 100644
index 0000000000..0fb6a8fdc2
--- /dev/null
+++ b/MdeModulePkg/Include/Ppi/Debug.h
@@ -0,0 +1,82 @@
+/** @file
+  Define the EDKII_DEBUG_PPI that PEIMs can use to dump info to debug port.
+
+  Copyright (c) 2019, 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef __EDKII_DEBUG_PPI_H__
+#define __EDKII_DEBUG_PPI_H__
+
+#include <Pi/PiPeiCis.h>
+
+//
+// Global ID for the EDKII_DEBUG_PPI
+//
+#define EDKII_DEBUG_PPI_GUID \
+  { \
+    0x999e699c, 0xb013, 0x475e, {0xb1, 0x7b, 0xf3, 0xa8, 0xae, 0x5c, 0x48, 0x75} \
+  }
+
+///
+/// Forward declaration for the PEI_DEBUG_LIB_DEBUG_PPI EDKII_DEBUG_PPI
+///
+typedef struct _EDKII_DEBUG_PPI EDKII_DEBUG_PPI;
+
+/**
+  Print a debug message to debug output device if the specified error level
+  is enabled.
+
+  @param[in] ErrorLevel               The error level of the debug message.
+  @param[in] Format                   Format string for the debug message to print.
+  @param[in] Marker                   BASE_LIST marker for the variable argument list.
+
+**/
+typedef
+VOID
+(EFIAPI *EDKII_DEBUG_BPRINT)(
+  IN UINTN                          ErrorLevel,
+  IN CONST CHAR8                    *Format,
+  IN BASE_LIST                      Marker
+  );
+
+/**
+  Print an assert message containing a filename, line number, and description.
+  This may be followed by a breakpoint or a dead loop.
+
+  @param[in] FileName                 The pointer to the name of the source file that
+                                      generated the assert condition.
+  @param[in] LineNumber               The line number in the source file that generated
+                                      the assert condition
+  @param[in] Description              The pointer to the description of the assert condition.
+
+**/
+typedef
+VOID
+(EFIAPI *EDKII_DEBUG_ASSERT)(
+  IN CONST CHAR8                    *FileName,
+  IN UINTN                          LineNumber,
+  IN CONST CHAR8                    *Description
+  );
+
+///
+/// This PPI contains a set of services to print message to debug output device
+///
+struct _EDKII_DEBUG_PPI {
+  EDKII_DEBUG_BPRINT                DebugBPrint;
+  EDKII_DEBUG_ASSERT                DebugAssert;
+};
+
+extern EFI_GUID gEdkiiDebugPpiGuid;
+
+#endif
+
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index a2130bc439..9bbd0572f5 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -492,6 +492,9 @@
   ## Include/Ppi/AtaPassThru.h
   gEdkiiPeiAtaPassThruPpiGuid               = { 0xa16473fd, 0xd474, 0x4c89, { 0xae, 0xc7, 0x90, 0xb8, 0x3c, 0x73, 0x86, 0x9  } }
 
+  ## Include/Ppi/Debug.h
+  gEdkiiDebugPpiGuid                        = { 0x999e699c, 0xb013, 0x475e, { 0xb1, 0x7b, 0xf3, 0xa8, 0xae, 0x5c, 0x48, 0x75 } }
+
 [Protocols]
   ## Load File protocol provides capability to load and unload EFI image into memory and execute it.
   #  Include/Protocol/LoadPe32Image.h
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (13 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
  2019-03-28  8:10 ` [PATCH V5 17/17] MdeModulePkg: Add PEIM and lib to dsc file Zhichao Gao
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549

Add a PEIM to install Debug PPI so that PEI debug library
instance can locate gEdkiiDebugPpiGuid to implement the
debug functions. Using this PPI can reduce the size of
PEIMs which consume the debug library.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
---
 .../Universal/DebugServicePei/DebugService.h  |  56 ++++++++++
 .../DebugServicePei/DebugServicePei.c         | 100 ++++++++++++++++++
 .../DebugServicePei/DebugServicePei.inf       |  51 +++++++++
 .../DebugServicePei/DebugServicePei.uni       |  20 ++++
 4 files changed, 227 insertions(+)
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugService.h
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugServicePei.uni

diff --git a/MdeModulePkg/Universal/DebugServicePei/DebugService.h b/MdeModulePkg/Universal/DebugServicePei/DebugService.h
new file mode 100644
index 0000000000..3e234f76b6
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugService.h
@@ -0,0 +1,56 @@
+/** @file
+  Header file of Debug services instances.
+
+  Copyright (c) 2019, 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+#ifndef __DEBUG_SERVICE_H__
+#define __DEBUG_SERVICE_H__
+
+#include <Ppi/Debug.h>
+
+/**
+  Print a debug message to debug output device if the specified error level
+  is enabled.
+
+  @param[in] ErrorLevel               The error level of the debug message.
+  @param[in] Format                   Format string for the debug message to print.
+  @param[in] Marker                   BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+PeiDebugBPrint(
+  IN UINTN                          ErrorLevel,
+  IN CONST CHAR8                    *Format,
+  IN BASE_LIST                      Marker
+  );
+
+/**
+  Prints an assert message containing a filename, line number, and description.
+  This may be followed by a breakpoint or a dead loop.
+
+  @param[in] FileName                 The pointer to the name of the source file that
+                                      generated the assert condition.
+  @param[in] LineNumber               The line number in the source file that generated
+                                      the assert condition
+  @param[in] Description              The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+PeiDebugAssert(
+  IN CONST CHAR8                    *FileName,
+  IN UINTN                          LineNumber,
+  IN CONST CHAR8                    *Description
+  );
+
+#endif
diff --git a/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
new file mode 100644
index 0000000000..6e85e709cb
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
@@ -0,0 +1,100 @@
+/** @file
+  This driver installs gEdkiiDebugPpiGuid PPI to provide
+  debug services for PEIMs.
+
+  Copyright (c) 2019, 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Uefi/UefiBaseType.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/DebugLib.h>
+
+#include <Ppi/Debug.h>
+
+#include "DebugService.h"
+
+EDKII_DEBUG_PPI mDebugPpi = {
+  PeiDebugBPrint,
+  PeiDebugAssert
+};
+
+EFI_PEI_PPI_DESCRIPTOR mDebugServicePpi = {
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+  &gEdkiiDebugPpiGuid,
+  (VOID *)&mDebugPpi
+};
+
+/**
+  Print a debug message to debug output device if the specified error level
+  is enabled.
+
+  @param[in] ErrorLevel               The error level of the debug message.
+  @param[in] Format                   Format string for the debug message to print.
+  @param[in] Marker                   BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+PeiDebugBPrint(
+  IN UINTN                          ErrorLevel,
+  IN CONST CHAR8                    *Format,
+  IN BASE_LIST                      Marker
+  )
+{
+  DebugBPrint(ErrorLevel, Format, Marker);
+}
+
+/**
+  Print an assert message containing a filename, line number, and description.
+  This may be followed by a breakpoint or a dead loop.
+
+  @param[in] FileName                 The pointer to the name of the source file that
+                                      generated the assert condition.
+  @param[in] LineNumber               The line number in the source file that generated
+                                      the assert condition
+  @param[in] Description              The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+PeiDebugAssert(
+  IN CONST CHAR8                    *FileName,
+  IN UINTN                          LineNumber,
+  IN CONST CHAR8                    *Description
+  )
+{
+  DebugAssert(FileName, LineNumber, Description);
+}
+
+/**
+  Entry point of Debug Service PEIM
+
+  This funciton installs EDKII DEBUG PPI
+
+  @param  FileHandle  Handle of the file being invoked.
+  @param  PeiServices Describes the list of possible PEI Services.
+
+  @retval EFI_SUCESS  The entry point of Debug Service PEIM executes successfully.
+  @retval Others      Some error occurs during the execution of this function.
+
+**/
+EFI_STATUS
+EFIAPI
+DebugSerivceInitialize (
+  IN EFI_PEI_FILE_HANDLE        FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  return PeiServicesInstallPpi (&mDebugServicePpi);
+}
+
diff --git a/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
new file mode 100644
index 0000000000..d1642cde38
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
@@ -0,0 +1,51 @@
+## @file
+#  Debug services for PEI phase
+#
+#  This module installs gEdkiiDebugPpiGuid PPI to provide
+#  debug services for PEIMs.
+#
+#  Copyright (c) 2019, 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
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DebugServicePei
+  MODULE_UNI_FILE                = DebugServicePei.uni
+  FILE_GUID                      = B73F81B9-1DFC-487C-824C-0509EE2B0128
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+
+  ENTRY_POINT                    = DebugSerivceInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 EBC
+#
+
+[Sources]
+  DebugServicePei.c
+  DebugService.h
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  PeimEntryPoint
+  PeiServicesLib
+  DebugLib
+
+[Ppis]
+  gEdkiiDebugPpiGuid                    ## PRODUCE
+
+[Depex]
+  TRUE
+
diff --git a/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.uni b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.uni
new file mode 100644
index 0000000000..c49a7acbca
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.uni
@@ -0,0 +1,20 @@
+///** @file
+//  This driver installs gEdkiiDebugPpiGuid PPI to provide
+//  debug services for PEIMs.
+//
+//  Copyright (c) 2019, 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
+//  http://opensource.org/licenses/bsd-license.php
+//
+//  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+//**/
+
+#string STR_MODULE_ABSTRACT             #language en-US "Provide debug services at PEI phase."
+
+#string STR_MODULE_DESCRIPTION          #language en-US "It produces gEdkiiDebugPpiGuid to print message to debug output device"
+
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (14 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  2019-03-28 10:10   ` Ni, Ray
  2019-03-28  8:10 ` [PATCH V5 17/17] MdeModulePkg: Add PEIM and lib to dsc file Zhichao Gao
  16 siblings, 1 reply; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Liming Gao, Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Sean Brogan,
	Michael Turner, Bret Barkelew

From: Liming Gao <liming.gao@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549

Add a PEI debug library instance PeiDebugLibDebugPpi base on
DebugPpi. Using the combination of the DebugServicePei and
this lib instance can reduce the image size of PEI drivers.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
---
 .../Library/PeiDebugLibDebugPpi/DebugLib.c    | 456 ++++++++++++++++++
 .../PeiDebugLibDebugPpi.inf                   |  56 +++
 2 files changed, 512 insertions(+)
 create mode 100644 MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
 create mode 100644 MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf

diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
new file mode 100644
index 0000000000..349577e5ea
--- /dev/null
+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
@@ -0,0 +1,456 @@
+/** @file
+  PEI debug lib instance base on DebugPpi to save size
+
+  Copyright (c) 2019, 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiPei.h>
+#include <Ppi/Debug.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/DebugPrintErrorLevelLib.h>
+
+EDKII_DEBUG_PPI             *mEdkiiDebugPpi = NULL;
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  ...           Variable argument list whose contents are accessed
+                        based on the format string specified by Format.
+
+**/
+VOID
+EFIAPI
+DebugPrint (
+  IN  UINTN        ErrorLevel,
+  IN  CONST CHAR8  *Format,
+  ...
+  )
+{
+  VA_LIST         Marker;
+
+  VA_START (Marker, Format);
+  DebugVPrint (ErrorLevel, Format, Marker);
+  VA_END (Marker);
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+  This function use BASE_LIST which would provide a more compatible
+  service than VA_LIST.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel      The error level of the debug message.
+  @param  Format          Format string for the debug message to print.
+  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugBPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  BASE_LIST     BaseListMarker
+  )
+{
+  EFI_STATUS      Status;
+
+  //
+  // If Format is NULL, then ASSERT().
+  //
+  ASSERT (Format != NULL);
+
+  //
+  // Check driver Debug Level value and global debug level
+  //
+  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
+    return;
+  }
+
+  if (mEdkiiDebugPpi == NULL) {
+    Status = PeiServicesLocatePpi (
+                &gEdkiiDebugPpiGuid,
+                0,
+                NULL,
+                (VOID **)&mEdkiiDebugPpi
+                );
+    if (EFI_ERROR (Status)) {
+      return;
+    }
+  }
+
+  mEdkiiDebugPpi->DebugBPrint (
+                    ErrorLevel,
+                    Format,
+                    BaseListMarker
+                    );
+}
+
+
+/**
+  Worker function that convert a VA_LIST to a BASE_LIST based on a
+  Null-terminated format string.
+
+  @param  Format          Null-terminated format string.
+  @param  VaListMarker    VA_LIST style variable argument list consumed
+                          by processing Format.
+  @param  BaseListMarker  BASE_LIST style variable argument list consumed
+                          by processing Format.
+  @param  Size            The size, in bytes, of the BaseListMarker buffer.
+
+  @return TRUE   The VA_LIST has been converted to BASE_LIST.
+  @return FALSE  The VA_LIST has not been converted to BASE_LIST.
+
+**/
+BOOLEAN
+VaListToBaseList (
+  IN  CONST CHAR8  *Format,
+  IN  VA_LIST      VaListMarker,
+  OUT BASE_LIST    BaseListMarker,
+  IN  UINTN        Size
+  )
+{
+  BASE_LIST       BaseListStart;
+  BOOLEAN         Long;
+
+  ASSERT (Format != NULL);
+
+  ASSERT (BaseListMarker != NULL);
+
+  BaseListStart = BaseListMarker;
+
+  for (; *Format != '\0'; Format++) {
+    //
+    // Only format with prefix % is processed.
+    //
+    if (*Format != '%') {
+      continue;
+    }
+
+    Long = FALSE;
+
+    //
+    // Parse Flags and Width
+    //
+    for (Format++; TRUE; Format++) {
+      if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {
+        //
+        // These characters in format field are omitted.
+        //
+        continue;
+      }
+      if (*Format >= '0' && *Format <= '9') {
+        //
+        // These characters in format field are omitted.
+        //
+        continue;
+      }
+      if (*Format == 'L' || *Format == 'l') {
+        //
+        // 'L" or "l" in format field means the number being printed is a UINT64
+        //
+        Long = TRUE;
+        continue;
+      }
+      if (*Format == '*') {
+        //
+        // '*' in format field means the precision of the field is specified by
+        // a UINTN argument in the argument list.
+        //
+        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+        continue;
+      }
+      if (*Format == '\0') {
+        //
+        // Make no output if Format string terminates unexpectedly when
+        // looking up for flag, width, precision and type.
+        //
+        Format--;
+      }
+      //
+      // When valid argument type detected or format string terminates unexpectedly,
+      // the inner loop is done.
+      //
+      break;
+    }
+
+    //
+    // Pack variable arguments into the storage area following EFI_DEBUG_INFO.
+    //
+    if ((*Format == 'p') && (sizeof (VOID *) > 4)) {
+      Long = TRUE;
+    }
+    if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' || *Format == 'u') {
+      if (Long) {
+        BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
+      } else {
+        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
+      }
+    } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format == 'g' || *Format == 't') {
+      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
+    } else if (*Format == 'c') {
+      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
+    } else if (*Format == 'r') {
+      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);
+    }
+
+    //
+    // If the converted BASE_LIST is larger than the size of BaseListMarker, then return FALSE
+    //
+    if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+
+/**
+  Prints a debug message to the debug output device if the specified
+  error level is enabled.
+
+  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function
+  GetDebugPrintErrorLevel (), then print the message specified by Format and
+  the associated variable argument list to the debug output device.
+
+  If Format is NULL, then ASSERT().
+
+  @param  ErrorLevel    The error level of the debug message.
+  @param  Format        Format string for the debug message to print.
+  @param  VaListMarker  VA_LIST marker for the variable argument list.
+
+**/
+VOID
+EFIAPI
+DebugVPrint (
+  IN  UINTN         ErrorLevel,
+  IN  CONST CHAR8   *Format,
+  IN  VA_LIST       VaListMarker
+  )
+{
+  UINT64            BaseListMarker[256 / sizeof (UINT64)];
+  BOOLEAN           Converted;
+
+  //
+  // Convert the VaList to BaseList
+  //
+  Converted = VaListToBaseList (
+                Format,
+                VaListMarker,
+                (BASE_LIST)BaseListMarker,
+                sizeof (BaseListMarker) - 8
+                );
+
+  if (!Converted) {
+    return;
+  }
+
+  DebugBPrint (ErrorLevel, Format, (BASE_LIST)BaseListMarker);
+}
+
+
+/**
+  Prints an assert message containing a filename, line number, and description.
+  This may be followed by a breakpoint or a dead loop.
+
+  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\n"
+  to the debug output device.  If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
+  PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if
+  DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set then
+  CpuDeadLoop() is called.  If neither of these bits are set, then this function
+  returns immediately after the message is printed to the debug output device.
+  DebugAssert() must actively prevent recursion.  If DebugAssert() is called while
+  processing another DebugAssert(), then DebugAssert() must return immediately.
+
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
+
+  @param  FileName     The pointer to the name of the source file that generated the assert condition.
+  @param  LineNumber   The line number in the source file that generated the assert condition
+  @param  Description  The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+DebugAssert (
+  IN CONST CHAR8  *FileName,
+  IN UINTN        LineNumber,
+  IN CONST CHAR8  *Description
+  )
+{
+  EFI_STATUS      Status;
+
+  if (mEdkiiDebugPpi == NULL) {
+    Status = PeiServicesLocatePpi (
+                &gEdkiiDebugPpiGuid,
+                0,
+                NULL,
+                (VOID **)&mEdkiiDebugPpi
+                );
+    if (EFI_ERROR (Status)) {
+      return;
+    }
+  }
+
+  mEdkiiDebugPpi->DebugAssert (
+                    FileName,
+                    LineNumber,
+                    Description
+                    );
+}
+
+
+/**
+  Fills a target buffer with PcdDebugClearMemoryValue, and returns the target buffer.
+
+  This function fills Length bytes of Buffer with the value specified by
+  PcdDebugClearMemoryValue, and returns Buffer.
+
+  If Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param   Buffer  The pointer to the target buffer to be filled with PcdDebugClearMemoryValue.
+  @param   Length  The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
+
+  @return  Buffer  The pointer to the target buffer filled with PcdDebugClearMemoryValue.
+
+**/
+VOID *
+EFIAPI
+DebugClearMemory (
+  OUT VOID  *Buffer,
+  IN UINTN  Length
+  )
+{
+  ASSERT (Buffer != NULL);
+
+  return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue));
+}
+
+
+/**
+  Returns TRUE if ASSERT() macros are enabled.
+
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
+  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugAssertEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
+}
+
+
+/**
+  Returns TRUE if DEBUG() macros are enabled.
+
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
+  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugPrintEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0);
+}
+
+
+/**
+  Returns TRUE if DEBUG_CODE() macros are enabled.
+
+  This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
+  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugCodeEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
+}
+
+
+/**
+  Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
+
+  This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
+  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugClearMemoryEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
+}
+
+
+/**
+  Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+  This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+  @retval  TRUE    Current ErrorLevel is supported.
+  @retval  FALSE   Current ErrorLevel is not supported.
+
+**/
+BOOLEAN
+EFIAPI
+DebugPrintLevelEnabled (
+  IN  CONST UINTN        ErrorLevel
+  )
+{
+  return (BOOLEAN) ((ErrorLevel & PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0);
+}
+
diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
new file mode 100644
index 0000000000..61c7a4fea7
--- /dev/null
+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
@@ -0,0 +1,56 @@
+## @file
+#  Debug Lib instance through DebugServicePei for PEI phase
+#
+#  This module use gEdkiiDebugPpiGuid to implement the PEI DebugLib for reduce
+#  the size of PEIMs which consume DebugLib
+#
+#  Copyright (c) 2019, 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
+#  http://opensource.org/licenses/bsd-license.php
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = PeiDebugLibDebugPpi
+  FILE_GUID                      = 2E08836C-4D1C-42F7-BBBE-EC5D25F1FDD4
+  MODULE_TYPE                    = PEIM
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DebugLib|PEIM
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 EBC
+#
+
+[Sources]
+  DebugLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  PcdLib
+  BaseMemoryLib
+  DebugPrintErrorLevelLib
+  PeiServicesLib
+  PeiServicesTablePointerLib
+
+[Ppis]
+  gEdkiiDebugPpiGuid                                        ## CONSUMES
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue         ## SOMETIMES_CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask             ## CONSUMES
+  gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel     ## CONSUMES
+
+[Depex]
+  gEdkiiDebugPpiGuid
+
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH V5 17/17] MdeModulePkg: Add PEIM and lib to dsc file
  2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (15 preceding siblings ...)
  2019-03-28  8:10 ` [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
@ 2019-03-28  8:10 ` Zhichao Gao
  16 siblings, 0 replies; 24+ messages in thread
From: Zhichao Gao @ 2019-03-28  8:10 UTC (permalink / raw)
  To: edk2-devel
  Cc: Jian J Wang, Hao Wu, Ray Ni, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549

Add the new PEIM DebugServicePei and library instance
PeiDebugLibDebugPpi to dsc file to verify it can build
correctly.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
---
 MdeModulePkg/MdeModulePkg.dsc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 6cd1727a0d..dec441e23e 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -297,6 +297,7 @@
   MdeModulePkg/Library/PlatformHookLibSerialPortPpi/PlatformHookLibSerialPortPpi.inf
   MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
   MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+  MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
   MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
   MdeModulePkg/Library/PlatformBootManagerLibNull/PlatformBootManagerLibNull.inf
   MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
@@ -423,6 +424,8 @@
   MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
   MdeModulePkg/Universal/LoadFileOnFv2/LoadFileOnFv2.inf
 
+  MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
+
   MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf
   MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
   MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
-- 
2.21.0.windows.1



^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-28  8:10 ` [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-28  8:44   ` Chiu, Chasel
  0 siblings, 0 replies; 24+ messages in thread
From: Chiu, Chasel @ 2019-03-28  8:44 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Bret Barkelew, Desimone, Nathaniel L, Zeng, Star, Gao, Liming,
	Sean Brogan, Michael Turner


No change from V4.
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 28, 2019 4:10 PM
> To: edk2-devel@lists.01.org
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao,
> Liming <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>
> Subject: [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new
> APIs
> 
> From: Bret Barkelew <Bret.Barkelew@microsoft.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> Add new APIs' implementation (DebugVPrint, DebugBPrint) in the DebugLib
> instance. These APIs would expose print routines with VaList parameter and
> BaseList parameter.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
> ---
>  .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++++++++++++++++-
>  1 file changed, 98 insertions(+), 5 deletions(-)
> 
> diff --git a/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> b/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> index 73bb08e357..8b322c038e 100644
> --- a/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> +++ b/IntelFspPkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2019, 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,12 @@
> 
>  CONST CHAR8  *mHexTable = "0123456789ABCDEF";
> 
> +//
> +// VA_LIST can not initialize to NULL for all compiler, so we use this
> +to // indicate a null VA_LIST //
> +VA_LIST     mVaListNull;
> +
>  /**
>    Get stack frame pointer of function call.
> 
> @@ -62,9 +68,40 @@ DebugPrint (
>    IN  CONST CHAR8  *Format,
>    ...
>    )
> +{
> +  VA_LIST         Marker;
> +
> +  VA_START (Marker, Format);
> +  DebugVPrint (ErrorLevel, Format, Marker);
> +  VA_END (Marker);
> +}
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled base on Null-terminated format string and a
> +  VA_LIST argument list or a BASE_LIST argument list.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel      The error level of the debug message.
> +  @param  Format          Format string for the debug message to print.
> +  @param  VaListMarker    VA_LIST marker for the variable argument list.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +DebugPrintMarker (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  VA_LIST       VaListMarker,
> +  IN  BASE_LIST     BaseListMarker
> +  )
>  {
>    CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
> -  VA_LIST  Marker;
> 
>    //
>    // If Format is NULL, then ASSERT().
> @@ -88,9 +125,11 @@ DebugPrint (
>    //
>    // Convert the DEBUG() message to an ASCII String
>    //
> -  VA_START (Marker, Format);
> -  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
> -  VA_END (Marker);
> +  if (BaseListMarker == NULL) {
> +    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);  }
> + else {
> +    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);  }
> 
>    //
>    // Send the print string to a Serial Port @@ -98,6 +137,60 @@ DebugPrint (
>    SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));  }
> 
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel    The error level of the debug message.
> +  @param  Format        Format string for the debug message to print.
> +  @param  VaListMarker  VA_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugVPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  VA_LIST       VaListMarker
> +  )
> +{
> +  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL); }
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +  This function use BASE_LIST which would provide a more compatible
> +  service than VA_LIST.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel      The error level of the debug message.
> +  @param  Format          Format string for the debug message to print.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugBPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  BASE_LIST     BaseListMarker
> +  )
> +{
> +  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker); }
> +
>  /**
>    Convert an UINT32 value into HEX string sepcified by Buffer.
> 
> --
> 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-28  8:10 ` [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-28  8:44   ` Chiu, Chasel
  0 siblings, 0 replies; 24+ messages in thread
From: Chiu, Chasel @ 2019-03-28  8:44 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Bret Barkelew, Desimone, Nathaniel L, Zeng, Star, Gao, Liming,
	Sean Brogan, Michael Turner


No change from V4.
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 28, 2019 4:10 PM
> To: edk2-devel@lists.01.org
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Desimone, Nathaniel L
> <nathaniel.l.desimone@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao,
> Liming <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>
> Subject: [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new
> APIs
> 
> From: Bret Barkelew <Bret.Barkelew@microsoft.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> Add new APIs' implementation (DebugVPrint, DebugBPrint) in the DebugLib
> instance. These APIs would expose print routines with VaList parameter and
> BaseList parameter.
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
> ---
>  .../BaseFspDebugLibSerialPort/DebugLib.c      | 103 +++++++++++++++++-
>  1 file changed, 98 insertions(+), 5 deletions(-)
> 
> diff --git a/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> b/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> index 73bb08e357..8b322c038e 100644
> --- a/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> +++ b/IntelFsp2Pkg/Library/BaseFspDebugLibSerialPort/DebugLib.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2014 - 2019, 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,12 @@
> 
>  CONST CHAR8  *mHexTable = "0123456789ABCDEF";
> 
> +//
> +// VA_LIST can not initialize to NULL for all compiler, so we use this
> +to // indicate a null VA_LIST //
> +VA_LIST     mVaListNull;
> +
>  /**
>    Get stack frame pointer of function call.
> 
> @@ -62,9 +68,40 @@ DebugPrint (
>    IN  CONST CHAR8  *Format,
>    ...
>    )
> +{
> +  VA_LIST         Marker;
> +
> +  VA_START (Marker, Format);
> +  DebugVPrint (ErrorLevel, Format, Marker);
> +  VA_END (Marker);
> +}
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled base on Null-terminated format string and a
> +  VA_LIST argument list or a BASE_LIST argument list.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel      The error level of the debug message.
> +  @param  Format          Format string for the debug message to print.
> +  @param  VaListMarker    VA_LIST marker for the variable argument list.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +DebugPrintMarker (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  VA_LIST       VaListMarker,
> +  IN  BASE_LIST     BaseListMarker
> +  )
>  {
>    CHAR8    Buffer[MAX_DEBUG_MESSAGE_LENGTH];
> -  VA_LIST  Marker;
> 
>    //
>    // If Format is NULL, then ASSERT().
> @@ -88,9 +125,11 @@ DebugPrint (
>    //
>    // Convert the DEBUG() message to an ASCII String
>    //
> -  VA_START (Marker, Format);
> -  AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker);
> -  VA_END (Marker);
> +  if (BaseListMarker == NULL) {
> +    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);  }
> + else {
> +    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);  }
> 
>    //
>    // Send the print string to a Serial Port @@ -98,6 +137,60 @@ DebugPrint (
>    SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));  }
> 
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel    The error level of the debug message.
> +  @param  Format        Format string for the debug message to print.
> +  @param  VaListMarker  VA_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugVPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  VA_LIST       VaListMarker
> +  )
> +{
> +  DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL); }
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +  This function use BASE_LIST which would provide a more compatible
> +  service than VA_LIST.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel      The error level of the debug message.
> +  @param  Format          Format string for the debug message to print.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugBPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  BASE_LIST     BaseListMarker
> +  )
> +{
> +  DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker); }
> +
>  /**
>    Convert an UINT32 value into HEX string sepcified by Buffer.
> 
> --
> 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-28  8:10 ` [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
@ 2019-03-28 10:10   ` Ni, Ray
  2019-03-29  5:10     ` Gao, Zhichao
  0 siblings, 1 reply; 24+ messages in thread
From: Ni, Ray @ 2019-03-28 10:10 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Gao, Liming, Wang, Jian J, Wu, Hao A, Zeng, Star, Sean Brogan,
	Michael Turner, Bret Barkelew

Zhichao,
For a PEIM, it may not be proper to have a global variable and update that global variable during execution.
Because sometimes the PEIM runs from read-only SPI flash, the global variable cannot be updated.
I see you have a check against NULL when using that global variable. How about just remove the global variable and always locate the PPI?

> -----Original Message-----
> From: Gao, Zhichao <zhichao.gao@intel.com>
> Sent: Thursday, March 28, 2019 4:10 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Sean Brogan
> <sean.brogan@microsoft.com>; Michael Turner
> <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> debug lib
> 
> From: Liming Gao <liming.gao@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549
> 
> Add a PEI debug library instance PeiDebugLibDebugPpi base on DebugPpi.
> Using the combination of the DebugServicePei and this lib instance can
> reduce the image size of PEI drivers.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  .../Library/PeiDebugLibDebugPpi/DebugLib.c    | 456 ++++++++++++++++++
>  .../PeiDebugLibDebugPpi.inf                   |  56 +++
>  2 files changed, 512 insertions(+)
>  create mode 100644
> MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
>  create mode 100644
> MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> 
> diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> new file mode 100644
> index 0000000000..349577e5ea
> --- /dev/null
> +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> @@ -0,0 +1,456 @@
> +/** @file
> +  PEI debug lib instance base on DebugPpi to save size
> +
> +  Copyright (c) 2019, 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  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> BASIS,
> + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#include <PiPei.h>
> +#include <Ppi/Debug.h>
> +#include <Library/DebugLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/PeiServicesLib.h>
> +#include <Library/DebugPrintErrorLevelLib.h>
> +
> +EDKII_DEBUG_PPI             *mEdkiiDebugPpi = NULL;
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel    The error level of the debug message.
> +  @param  Format        Format string for the debug message to print.
> +  @param  ...           Variable argument list whose contents are accessed
> +                        based on the format string specified by Format.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugPrint (
> +  IN  UINTN        ErrorLevel,
> +  IN  CONST CHAR8  *Format,
> +  ...
> +  )
> +{
> +  VA_LIST         Marker;
> +
> +  VA_START (Marker, Format);
> +  DebugVPrint (ErrorLevel, Format, Marker);
> +  VA_END (Marker);
> +}
> +
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +  This function use BASE_LIST which would provide a more compatible
> +  service than VA_LIST.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel      The error level of the debug message.
> +  @param  Format          Format string for the debug message to print.
> +  @param  BaseListMarker  BASE_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugBPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  BASE_LIST     BaseListMarker
> +  )
> +{
> +  EFI_STATUS      Status;
> +
> +  //
> +  // If Format is NULL, then ASSERT().
> +  //
> +  ASSERT (Format != NULL);
> +
> +  //
> +  // Check driver Debug Level value and global debug level  //  if
> + ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
> +    return;
> +  }
> +
> +  if (mEdkiiDebugPpi == NULL) {
> +    Status = PeiServicesLocatePpi (
> +                &gEdkiiDebugPpiGuid,
> +                0,
> +                NULL,
> +                (VOID **)&mEdkiiDebugPpi
> +                );
> +    if (EFI_ERROR (Status)) {
> +      return;
> +    }
> +  }
> +
> +  mEdkiiDebugPpi->DebugBPrint (
> +                    ErrorLevel,
> +                    Format,
> +                    BaseListMarker
> +                    );
> +}
> +
> +
> +/**
> +  Worker function that convert a VA_LIST to a BASE_LIST based on a
> +  Null-terminated format string.
> +
> +  @param  Format          Null-terminated format string.
> +  @param  VaListMarker    VA_LIST style variable argument list consumed
> +                          by processing Format.
> +  @param  BaseListMarker  BASE_LIST style variable argument list consumed
> +                          by processing Format.
> +  @param  Size            The size, in bytes, of the BaseListMarker buffer.
> +
> +  @return TRUE   The VA_LIST has been converted to BASE_LIST.
> +  @return FALSE  The VA_LIST has not been converted to BASE_LIST.
> +
> +**/
> +BOOLEAN
> +VaListToBaseList (
> +  IN  CONST CHAR8  *Format,
> +  IN  VA_LIST      VaListMarker,
> +  OUT BASE_LIST    BaseListMarker,
> +  IN  UINTN        Size
> +  )
> +{
> +  BASE_LIST       BaseListStart;
> +  BOOLEAN         Long;
> +
> +  ASSERT (Format != NULL);
> +
> +  ASSERT (BaseListMarker != NULL);
> +
> +  BaseListStart = BaseListMarker;
> +
> +  for (; *Format != '\0'; Format++) {
> +    //
> +    // Only format with prefix % is processed.
> +    //
> +    if (*Format != '%') {
> +      continue;
> +    }
> +
> +    Long = FALSE;
> +
> +    //
> +    // Parse Flags and Width
> +    //
> +    for (Format++; TRUE; Format++) {
> +      if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {
> +        //
> +        // These characters in format field are omitted.
> +        //
> +        continue;
> +      }
> +      if (*Format >= '0' && *Format <= '9') {
> +        //
> +        // These characters in format field are omitted.
> +        //
> +        continue;
> +      }
> +      if (*Format == 'L' || *Format == 'l') {
> +        //
> +        // 'L" or "l" in format field means the number being printed is a UINT64
> +        //
> +        Long = TRUE;
> +        continue;
> +      }
> +      if (*Format == '*') {
> +        //
> +        // '*' in format field means the precision of the field is specified by
> +        // a UINTN argument in the argument list.
> +        //
> +        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
> +        continue;
> +      }
> +      if (*Format == '\0') {
> +        //
> +        // Make no output if Format string terminates unexpectedly when
> +        // looking up for flag, width, precision and type.
> +        //
> +        Format--;
> +      }
> +      //
> +      // When valid argument type detected or format string terminates
> unexpectedly,
> +      // the inner loop is done.
> +      //
> +      break;
> +    }
> +
> +    //
> +    // Pack variable arguments into the storage area following
> EFI_DEBUG_INFO.
> +    //
> +    if ((*Format == 'p') && (sizeof (VOID *) > 4)) {
> +      Long = TRUE;
> +    }
> +    if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format == 'd' ||
> *Format == 'u') {
> +      if (Long) {
> +        BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
> +      } else {
> +        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
> +      }
> +    } else if (*Format == 's' || *Format == 'S' || *Format == 'a' || *Format ==
> 'g' || *Format == 't') {
> +      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);
> +    } else if (*Format == 'c') {
> +      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
> +    } else if (*Format == 'r') {
> +      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker,
> RETURN_STATUS);
> +    }
> +
> +    //
> +    // If the converted BASE_LIST is larger than the size of BaseListMarker,
> then return FALSE
> +    //
> +    if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {
> +      return FALSE;
> +    }
> +  }
> +
> +  return TRUE;
> +}
> +
> +
> +/**
> +  Prints a debug message to the debug output device if the specified
> +  error level is enabled.
> +
> +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> + function  GetDebugPrintErrorLevel (), then print the message specified
> + by Format and  the associated variable argument list to the debug output
> device.
> +
> +  If Format is NULL, then ASSERT().
> +
> +  @param  ErrorLevel    The error level of the debug message.
> +  @param  Format        Format string for the debug message to print.
> +  @param  VaListMarker  VA_LIST marker for the variable argument list.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugVPrint (
> +  IN  UINTN         ErrorLevel,
> +  IN  CONST CHAR8   *Format,
> +  IN  VA_LIST       VaListMarker
> +  )
> +{
> +  UINT64            BaseListMarker[256 / sizeof (UINT64)];
> +  BOOLEAN           Converted;
> +
> +  //
> +  // Convert the VaList to BaseList
> +  //
> +  Converted = VaListToBaseList (
> +                Format,
> +                VaListMarker,
> +                (BASE_LIST)BaseListMarker,
> +                sizeof (BaseListMarker) - 8
> +                );
> +
> +  if (!Converted) {
> +    return;
> +  }
> +
> +  DebugBPrint (ErrorLevel, Format, (BASE_LIST)BaseListMarker); }
> +
> +
> +/**
> +  Prints an assert message containing a filename, line number, and
> description.
> +  This may be followed by a breakpoint or a dead loop.
> +
> +  Print a message of the form "ASSERT <FileName>(<LineNumber>):
> <Description>\n"
> +  to the debug output device.  If
> + DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
> PcdDebugProperyMask
> + is set then CpuBreakpoint() is called. Otherwise, if
> + DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of
> PcdDebugProperyMask is
> + set then
> +  CpuDeadLoop() is called.  If neither of these bits are set, then this
> + function  returns immediately after the message is printed to the debug
> output device.
> +  DebugAssert() must actively prevent recursion.  If DebugAssert() is
> + called while  processing another DebugAssert(), then DebugAssert() must
> return immediately.
> +
> +  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is
> printed.
> +  If Description is NULL, then a <Description> string of "(NULL) Description" is
> printed.
> +
> +  @param  FileName     The pointer to the name of the source file that
> generated the assert condition.
> +  @param  LineNumber   The line number in the source file that generated
> the assert condition
> +  @param  Description  The pointer to the description of the assert condition.
> +
> +**/
> +VOID
> +EFIAPI
> +DebugAssert (
> +  IN CONST CHAR8  *FileName,
> +  IN UINTN        LineNumber,
> +  IN CONST CHAR8  *Description
> +  )
> +{
> +  EFI_STATUS      Status;
> +
> +  if (mEdkiiDebugPpi == NULL) {
> +    Status = PeiServicesLocatePpi (
> +                &gEdkiiDebugPpiGuid,
> +                0,
> +                NULL,
> +                (VOID **)&mEdkiiDebugPpi
> +                );
> +    if (EFI_ERROR (Status)) {
> +      return;
> +    }
> +  }
> +
> +  mEdkiiDebugPpi->DebugAssert (
> +                    FileName,
> +                    LineNumber,
> +                    Description
> +                    );
> +}
> +
> +
> +/**
> +  Fills a target buffer with PcdDebugClearMemoryValue, and returns the
> target buffer.
> +
> +  This function fills Length bytes of Buffer with the value specified
> + by  PcdDebugClearMemoryValue, and returns Buffer.
> +
> +  If Buffer is NULL, then ASSERT().
> +  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
> +
> +  @param   Buffer  The pointer to the target buffer to be filled with
> PcdDebugClearMemoryValue.
> +  @param   Length  The number of bytes in Buffer to fill with zeros
> PcdDebugClearMemoryValue.
> +
> +  @return  Buffer  The pointer to the target buffer filled with
> PcdDebugClearMemoryValue.
> +
> +**/
> +VOID *
> +EFIAPI
> +DebugClearMemory (
> +  OUT VOID  *Buffer,
> +  IN UINTN  Length
> +  )
> +{
> +  ASSERT (Buffer != NULL);
> +
> +  return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue)); }
> +
> +
> +/**
> +  Returns TRUE if ASSERT() macros are enabled.
> +
> +  This function returns TRUE if the
> DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
> + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> +
> +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
> PcdDebugProperyMask is set.
> +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
> PcdDebugProperyMask is clear.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +DebugAssertEnabled (
> +  VOID
> +  )
> +{
> +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> +DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); }
> +
> +
> +/**
> +  Returns TRUE if DEBUG() macros are enabled.
> +
> +  This function returns TRUE if the
> DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
> + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> +
> +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
> PcdDebugProperyMask is set.
> +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
> PcdDebugProperyMask is clear.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +DebugPrintEnabled (
> +  VOID
> +  )
> +{
> +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> +DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); }
> +
> +
> +/**
> +  Returns TRUE if DEBUG_CODE() macros are enabled.
> +
> +  This function returns TRUE if the
> DEBUG_PROPERTY_DEBUG_CODE_ENABLED
> + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> +
> +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
> PcdDebugProperyMask is set.
> +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
> PcdDebugProperyMask is clear.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +DebugCodeEnabled (
> +  VOID
> +  )
> +{
> +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> +DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); }
> +
> +
> +/**
> +  Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
> +
> +  This function returns TRUE if the
> DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
> + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> +
> +  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
> PcdDebugProperyMask is set.
> +  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
> PcdDebugProperyMask is clear.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +DebugClearMemoryEnabled (
> +  VOID
> +  )
> +{
> +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> +DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); }
> +
> +
> +/**
> +  Returns TRUE if any one of the bit is set both in ErrorLevel and
> PcdFixedDebugPrintErrorLevel.
> +
> +  This function compares the bit mask of ErrorLevel and
> PcdFixedDebugPrintErrorLevel.
> +
> +  @retval  TRUE    Current ErrorLevel is supported.
> +  @retval  FALSE   Current ErrorLevel is not supported.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +DebugPrintLevelEnabled (
> +  IN  CONST UINTN        ErrorLevel
> +  )
> +{
> +  return (BOOLEAN) ((ErrorLevel &
> +PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0); }
> +
> diff --git
> a/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> new file mode 100644
> index 0000000000..61c7a4fea7
> --- /dev/null
> +++
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> @@ -0,0 +1,56 @@
> +## @file
> +#  Debug Lib instance through DebugServicePei for PEI phase # #  This
> +module use gEdkiiDebugPpiGuid to implement the PEI DebugLib for reduce
> +#  the size of PEIMs which consume DebugLib # #  Copyright (c) 2019,
> +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 #
> +http://opensource.org/licenses/bsd-license.php
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> +BASIS, #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> EITHER EXPRESS OR IMPLIED.
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010005
> +  BASE_NAME                      = PeiDebugLibDebugPpi
> +  FILE_GUID                      = 2E08836C-4D1C-42F7-BBBE-EC5D25F1FDD4
> +  MODULE_TYPE                    = PEIM
> +  VERSION_STRING                 = 1.0
> +  LIBRARY_CLASS                  = DebugLib|PEIM
> +
> +#
> +# The following information is for reference only and not required by the
> build tools.
> +#
> +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> +#
> +
> +[Sources]
> +  DebugLib.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> +  PcdLib
> +  BaseMemoryLib
> +  DebugPrintErrorLevelLib
> +  PeiServicesLib
> +  PeiServicesTablePointerLib
> +
> +[Ppis]
> +  gEdkiiDebugPpiGuid                                        ## CONSUMES
> +
> +[Pcd]
> +  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue         ##
> SOMETIMES_CONSUMES
> +  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask             ##
> CONSUMES
> +  gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel     ##
> CONSUMES
> +
> +[Depex]
> +  gEdkiiDebugPpiGuid
> +
> --
> 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI
  2019-03-28  8:10 ` [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
@ 2019-03-28 10:13   ` Ni, Ray
  2019-03-29  0:11     ` Gao, Zhichao
  0 siblings, 1 reply; 24+ messages in thread
From: Ni, Ray @ 2019-03-28 10:13 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Wu, Hao A, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Zhichao,
I see you added library API called DebugVPrint. Why the interface in the PPI is called DebugBPrint?
What does "B" stand for? Why invent a "B" but not use "V"?

> -----Original Message-----
> From: Gao, Zhichao <zhichao.gao@intel.com>
> Sent: Thursday, March 28, 2019 4:10 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Gao, Liming
> <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG
> PPI
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549
> 
> Add a debug PPI for PEI phase. This PPI will provide basic services of debug.
> PEI debug lib instance can use these services to implement debug function to
> reduce the PEIMs which consume the debug lib.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> ---
>  MdeModulePkg/Include/Ppi/Debug.h | 82
> ++++++++++++++++++++++++++++++++
>  MdeModulePkg/MdeModulePkg.dec    |  3 ++
>  2 files changed, 85 insertions(+)
>  create mode 100644 MdeModulePkg/Include/Ppi/Debug.h
> 
> diff --git a/MdeModulePkg/Include/Ppi/Debug.h
> b/MdeModulePkg/Include/Ppi/Debug.h
> new file mode 100644
> index 0000000000..0fb6a8fdc2
> --- /dev/null
> +++ b/MdeModulePkg/Include/Ppi/Debug.h
> @@ -0,0 +1,82 @@
> +/** @file
> +  Define the EDKII_DEBUG_PPI that PEIMs can use to dump info to debug
> port.
> +
> +  Copyright (c) 2019, 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  http://opensource.org/licenses/bsd-license.php
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> BASIS,
> + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#ifndef __EDKII_DEBUG_PPI_H__
> +#define __EDKII_DEBUG_PPI_H__
> +
> +#include <Pi/PiPeiCis.h>
> +
> +//
> +// Global ID for the EDKII_DEBUG_PPI
> +//
> +#define EDKII_DEBUG_PPI_GUID \
> +  { \
> +    0x999e699c, 0xb013, 0x475e, {0xb1, 0x7b, 0xf3, 0xa8, 0xae, 0x5c,
> +0x48, 0x75} \
> +  }
> +
> +///
> +/// Forward declaration for the PEI_DEBUG_LIB_DEBUG_PPI
> EDKII_DEBUG_PPI
> +/// typedef struct _EDKII_DEBUG_PPI EDKII_DEBUG_PPI;
> +
> +/**
> +  Print a debug message to debug output device if the specified error
> +level
> +  is enabled.
> +
> +  @param[in] ErrorLevel               The error level of the debug message.
> +  @param[in] Format                   Format string for the debug message to print.
> +  @param[in] Marker                   BASE_LIST marker for the variable argument
> list.
> +
> +**/
> +typedef
> +VOID
> +(EFIAPI *EDKII_DEBUG_BPRINT)(
> +  IN UINTN                          ErrorLevel,
> +  IN CONST CHAR8                    *Format,
> +  IN BASE_LIST                      Marker
> +  );
> +
> +/**
> +  Print an assert message containing a filename, line number, and
> description.
> +  This may be followed by a breakpoint or a dead loop.
> +
> +  @param[in] FileName                 The pointer to the name of the source file
> that
> +                                      generated the assert condition.
> +  @param[in] LineNumber               The line number in the source file that
> generated
> +                                      the assert condition
> +  @param[in] Description              The pointer to the description of the assert
> condition.
> +
> +**/
> +typedef
> +VOID
> +(EFIAPI *EDKII_DEBUG_ASSERT)(
> +  IN CONST CHAR8                    *FileName,
> +  IN UINTN                          LineNumber,
> +  IN CONST CHAR8                    *Description
> +  );
> +
> +///
> +/// This PPI contains a set of services to print message to debug
> +output device /// struct _EDKII_DEBUG_PPI {
> +  EDKII_DEBUG_BPRINT                DebugBPrint;
> +  EDKII_DEBUG_ASSERT                DebugAssert;
> +};
> +
> +extern EFI_GUID gEdkiiDebugPpiGuid;
> +
> +#endif
> +
> diff --git a/MdeModulePkg/MdeModulePkg.dec
> b/MdeModulePkg/MdeModulePkg.dec index a2130bc439..9bbd0572f5
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -492,6 +492,9 @@
>    ## Include/Ppi/AtaPassThru.h
>    gEdkiiPeiAtaPassThruPpiGuid               = { 0xa16473fd, 0xd474, 0x4c89, { 0xae,
> 0xc7, 0x90, 0xb8, 0x3c, 0x73, 0x86, 0x9  } }
> 
> +  ## Include/Ppi/Debug.h
> +  gEdkiiDebugPpiGuid                        = { 0x999e699c, 0xb013, 0x475e, { 0xb1,
> 0x7b, 0xf3, 0xa8, 0xae, 0x5c, 0x48, 0x75 } }
> +
>  [Protocols]
>    ## Load File protocol provides capability to load and unload EFI image into
> memory and execute it.
>    #  Include/Protocol/LoadPe32Image.h
> --
> 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI
  2019-03-28 10:13   ` Ni, Ray
@ 2019-03-29  0:11     ` Gao, Zhichao
  0 siblings, 0 replies; 24+ messages in thread
From: Gao, Zhichao @ 2019-03-29  0:11 UTC (permalink / raw)
  To: Ni, Ray, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Wu, Hao A, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

B stand for BASE_LIST, we use B instead of V because of compatible issue.
For VA_LIST, it may be a pointer or a structure depend on the compiler.
If some PEIMs consume V version function and it is compiled by a different compiler, they may catch these issue.

Thanks,
Zhichao

> -----Original Message-----
> From: Ni, Ray
> Sent: Thursday, March 28, 2019 6:13 PM
> To: Gao, Zhichao <zhichao.gao@intel.com>; edk2-devel@lists.01.org
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Zeng, Star <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>;
> Sean Brogan <sean.brogan@microsoft.com>; Michael Turner
> <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: RE: [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII
> DEBUG PPI
> 
> Zhichao,
> I see you added library API called DebugVPrint. Why the interface in the PPI
> is called DebugBPrint?
> What does "B" stand for? Why invent a "B" but not use "V"?
> 
> > -----Original Message-----
> > From: Gao, Zhichao <zhichao.gao@intel.com>
> > Sent: Thursday, March 28, 2019 4:10 PM
> > To: edk2-devel@lists.01.org
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
> > <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Zeng, Star
> > <star.zeng@intel.com>; Gao, Liming <liming.gao@intel.com>; Sean Brogan
> > <sean.brogan@microsoft.com>; Michael Turner
> > <Michael.Turner@microsoft.com>; Bret Barkelew
> > <Bret.Barkelew@microsoft.com>
> > Subject: [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII
> > DEBUG PPI
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549
> >
> > Add a debug PPI for PEI phase. This PPI will provide basic services of debug.
> > PEI debug lib instance can use these services to implement debug
> > function to reduce the PEIMs which consume the debug lib.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Hao Wu <hao.a.wu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Star Zeng <star.zeng@intel.com>
> > Cc: Liming Gao <liming.gao@intel.com>
> > Cc: Sean Brogan <sean.brogan@microsoft.com>
> > Cc: Michael Turner <Michael.Turner@microsoft.com>
> > Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> > Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> > ---
> >  MdeModulePkg/Include/Ppi/Debug.h | 82
> > ++++++++++++++++++++++++++++++++
> >  MdeModulePkg/MdeModulePkg.dec    |  3 ++
> >  2 files changed, 85 insertions(+)
> >  create mode 100644 MdeModulePkg/Include/Ppi/Debug.h
> >
> > diff --git a/MdeModulePkg/Include/Ppi/Debug.h
> > b/MdeModulePkg/Include/Ppi/Debug.h
> > new file mode 100644
> > index 0000000000..0fb6a8fdc2
> > --- /dev/null
> > +++ b/MdeModulePkg/Include/Ppi/Debug.h
> > @@ -0,0 +1,82 @@
> > +/** @file
> > +  Define the EDKII_DEBUG_PPI that PEIMs can use to dump info to debug
> > port.
> > +
> > +  Copyright (c) 2019, 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  http://opensource.org/licenses/bsd-license.php
> > +
> > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > +
> > +**/
> > +
> > +#ifndef __EDKII_DEBUG_PPI_H__
> > +#define __EDKII_DEBUG_PPI_H__
> > +
> > +#include <Pi/PiPeiCis.h>
> > +
> > +//
> > +// Global ID for the EDKII_DEBUG_PPI
> > +//
> > +#define EDKII_DEBUG_PPI_GUID \
> > +  { \
> > +    0x999e699c, 0xb013, 0x475e, {0xb1, 0x7b, 0xf3, 0xa8, 0xae, 0x5c,
> > +0x48, 0x75} \
> > +  }
> > +
> > +///
> > +/// Forward declaration for the PEI_DEBUG_LIB_DEBUG_PPI
> > EDKII_DEBUG_PPI
> > +/// typedef struct _EDKII_DEBUG_PPI EDKII_DEBUG_PPI;
> > +
> > +/**
> > +  Print a debug message to debug output device if the specified error
> > +level
> > +  is enabled.
> > +
> > +  @param[in] ErrorLevel               The error level of the debug message.
> > +  @param[in] Format                   Format string for the debug message to
> print.
> > +  @param[in] Marker                   BASE_LIST marker for the variable
> argument
> > list.
> > +
> > +**/
> > +typedef
> > +VOID
> > +(EFIAPI *EDKII_DEBUG_BPRINT)(
> > +  IN UINTN                          ErrorLevel,
> > +  IN CONST CHAR8                    *Format,
> > +  IN BASE_LIST                      Marker
> > +  );
> > +
> > +/**
> > +  Print an assert message containing a filename, line number, and
> > description.
> > +  This may be followed by a breakpoint or a dead loop.
> > +
> > +  @param[in] FileName                 The pointer to the name of the source file
> > that
> > +                                      generated the assert condition.
> > +  @param[in] LineNumber               The line number in the source file that
> > generated
> > +                                      the assert condition
> > +  @param[in] Description              The pointer to the description of the
> assert
> > condition.
> > +
> > +**/
> > +typedef
> > +VOID
> > +(EFIAPI *EDKII_DEBUG_ASSERT)(
> > +  IN CONST CHAR8                    *FileName,
> > +  IN UINTN                          LineNumber,
> > +  IN CONST CHAR8                    *Description
> > +  );
> > +
> > +///
> > +/// This PPI contains a set of services to print message to debug
> > +output device /// struct _EDKII_DEBUG_PPI {
> > +  EDKII_DEBUG_BPRINT                DebugBPrint;
> > +  EDKII_DEBUG_ASSERT                DebugAssert;
> > +};
> > +
> > +extern EFI_GUID gEdkiiDebugPpiGuid;
> > +
> > +#endif
> > +
> > diff --git a/MdeModulePkg/MdeModulePkg.dec
> > b/MdeModulePkg/MdeModulePkg.dec index a2130bc439..9bbd0572f5
> > 100644
> > --- a/MdeModulePkg/MdeModulePkg.dec
> > +++ b/MdeModulePkg/MdeModulePkg.dec
> > @@ -492,6 +492,9 @@
> >    ## Include/Ppi/AtaPassThru.h
> >    gEdkiiPeiAtaPassThruPpiGuid               = { 0xa16473fd, 0xd474, 0x4c89,
> { 0xae,
> > 0xc7, 0x90, 0xb8, 0x3c, 0x73, 0x86, 0x9  } }
> >
> > +  ## Include/Ppi/Debug.h
> > +  gEdkiiDebugPpiGuid                        = { 0x999e699c, 0xb013, 0x475e, { 0xb1,
> > 0x7b, 0xf3, 0xa8, 0xae, 0x5c, 0x48, 0x75 } }
> > +
> >  [Protocols]
> >    ## Load File protocol provides capability to load and unload EFI
> > image into memory and execute it.
> >    #  Include/Protocol/LoadPe32Image.h
> > --
> > 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-28 10:10   ` Ni, Ray
@ 2019-03-29  5:10     ` Gao, Zhichao
  0 siblings, 0 replies; 24+ messages in thread
From: Gao, Zhichao @ 2019-03-29  5:10 UTC (permalink / raw)
  To: Ni, Ray, edk2-devel@lists.01.org
  Cc: Gao, Liming, Wang, Jian J, Wu, Hao A, Zeng, Star, Sean Brogan,
	Michael Turner, Bret Barkelew

You are right. I didn't think about that.
And I have change the variable to local and tested on open MinPlatform (Kabylake RVP3). It works fine. And also global variable make the system hang.

Thanks,
Zhichao

> -----Original Message-----
> From: Ni, Ray
> Sent: Thursday, March 28, 2019 6:11 PM
> To: Gao, Zhichao <zhichao.gao@intel.com>; edk2-devel@lists.01.org
> Cc: Gao, Liming <liming.gao@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; Zeng, Star
> <star.zeng@intel.com>; Sean Brogan <sean.brogan@microsoft.com>;
> Michael Turner <Michael.Turner@microsoft.com>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: RE: [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> PEI debug lib
> 
> Zhichao,
> For a PEIM, it may not be proper to have a global variable and update that
> global variable during execution.
> Because sometimes the PEIM runs from read-only SPI flash, the global
> variable cannot be updated.
> I see you have a check against NULL when using that global variable. How
> about just remove the global variable and always locate the PPI?
> 
> > -----Original Message-----
> > From: Gao, Zhichao <zhichao.gao@intel.com>
> > Sent: Thursday, March 28, 2019 4:10 PM
> > To: edk2-devel@lists.01.org
> > Cc: Gao, Liming <liming.gao@intel.com>; Wang, Jian J
> > <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> > <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Sean Brogan
> > <sean.brogan@microsoft.com>; Michael Turner
> > <Michael.Turner@microsoft.com>; Bret Barkelew
> > <Bret.Barkelew@microsoft.com>
> > Subject: [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> > debug lib
> >
> > From: Liming Gao <liming.gao@intel.com>
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1549
> >
> > Add a PEI debug library instance PeiDebugLibDebugPpi base on DebugPpi.
> > Using the combination of the DebugServicePei and this lib instance can
> > reduce the image size of PEI drivers.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Hao Wu <hao.a.wu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Star Zeng <star.zeng@intel.com>
> > Cc: Liming Gao <liming.gao@intel.com>
> > Cc: Sean Brogan <sean.brogan@microsoft.com>
> > Cc: Michael Turner <Michael.Turner@microsoft.com>
> > Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> > Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> > ---
> >  .../Library/PeiDebugLibDebugPpi/DebugLib.c    | 456
> ++++++++++++++++++
> >  .../PeiDebugLibDebugPpi.inf                   |  56 +++
> >  2 files changed, 512 insertions(+)
> >  create mode 100644
> > MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> >  create mode 100644
> > MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> >
> > diff --git a/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > new file mode 100644
> > index 0000000000..349577e5ea
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/DebugLib.c
> > @@ -0,0 +1,456 @@
> > +/** @file
> > +  PEI debug lib instance base on DebugPpi to save size
> > +
> > +  Copyright (c) 2019, 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  http://opensource.org/licenses/bsd-license.php
> > +
> > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > +
> > +**/
> > +
> > +#include <PiPei.h>
> > +#include <Ppi/Debug.h>
> > +#include <Library/DebugLib.h>
> > +#include <Library/BaseMemoryLib.h>
> > +#include <Library/PcdLib.h>
> > +#include <Library/PeiServicesLib.h>
> > +#include <Library/DebugPrintErrorLevelLib.h>
> > +
> > +EDKII_DEBUG_PPI             *mEdkiiDebugPpi = NULL;
> > +
> > +/**
> > +  Prints a debug message to the debug output device if the specified
> > +  error level is enabled.
> > +
> > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > + function  GetDebugPrintErrorLevel (), then print the message
> > + specified by Format and  the associated variable argument list to
> > + the debug output
> > device.
> > +
> > +  If Format is NULL, then ASSERT().
> > +
> > +  @param  ErrorLevel    The error level of the debug message.
> > +  @param  Format        Format string for the debug message to print.
> > +  @param  ...           Variable argument list whose contents are accessed
> > +                        based on the format string specified by Format.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugPrint (
> > +  IN  UINTN        ErrorLevel,
> > +  IN  CONST CHAR8  *Format,
> > +  ...
> > +  )
> > +{
> > +  VA_LIST         Marker;
> > +
> > +  VA_START (Marker, Format);
> > +  DebugVPrint (ErrorLevel, Format, Marker);
> > +  VA_END (Marker);
> > +}
> > +
> > +
> > +/**
> > +  Prints a debug message to the debug output device if the specified
> > +  error level is enabled.
> > +  This function use BASE_LIST which would provide a more compatible
> > +  service than VA_LIST.
> > +
> > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > + function  GetDebugPrintErrorLevel (), then print the message
> > + specified by Format and  the associated variable argument list to
> > + the debug output
> > device.
> > +
> > +  If Format is NULL, then ASSERT().
> > +
> > +  @param  ErrorLevel      The error level of the debug message.
> > +  @param  Format          Format string for the debug message to print.
> > +  @param  BaseListMarker  BASE_LIST marker for the variable argument
> list.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugBPrint (
> > +  IN  UINTN         ErrorLevel,
> > +  IN  CONST CHAR8   *Format,
> > +  IN  BASE_LIST     BaseListMarker
> > +  )
> > +{
> > +  EFI_STATUS      Status;
> > +
> > +  //
> > +  // If Format is NULL, then ASSERT().
> > +  //
> > +  ASSERT (Format != NULL);
> > +
> > +  //
> > +  // Check driver Debug Level value and global debug level  //  if
> > + ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
> > +    return;
> > +  }
> > +
> > +  if (mEdkiiDebugPpi == NULL) {
> > +    Status = PeiServicesLocatePpi (
> > +                &gEdkiiDebugPpiGuid,
> > +                0,
> > +                NULL,
> > +                (VOID **)&mEdkiiDebugPpi
> > +                );
> > +    if (EFI_ERROR (Status)) {
> > +      return;
> > +    }
> > +  }
> > +
> > +  mEdkiiDebugPpi->DebugBPrint (
> > +                    ErrorLevel,
> > +                    Format,
> > +                    BaseListMarker
> > +                    );
> > +}
> > +
> > +
> > +/**
> > +  Worker function that convert a VA_LIST to a BASE_LIST based on a
> > +  Null-terminated format string.
> > +
> > +  @param  Format          Null-terminated format string.
> > +  @param  VaListMarker    VA_LIST style variable argument list consumed
> > +                          by processing Format.
> > +  @param  BaseListMarker  BASE_LIST style variable argument list
> consumed
> > +                          by processing Format.
> > +  @param  Size            The size, in bytes, of the BaseListMarker buffer.
> > +
> > +  @return TRUE   The VA_LIST has been converted to BASE_LIST.
> > +  @return FALSE  The VA_LIST has not been converted to BASE_LIST.
> > +
> > +**/
> > +BOOLEAN
> > +VaListToBaseList (
> > +  IN  CONST CHAR8  *Format,
> > +  IN  VA_LIST      VaListMarker,
> > +  OUT BASE_LIST    BaseListMarker,
> > +  IN  UINTN        Size
> > +  )
> > +{
> > +  BASE_LIST       BaseListStart;
> > +  BOOLEAN         Long;
> > +
> > +  ASSERT (Format != NULL);
> > +
> > +  ASSERT (BaseListMarker != NULL);
> > +
> > +  BaseListStart = BaseListMarker;
> > +
> > +  for (; *Format != '\0'; Format++) {
> > +    //
> > +    // Only format with prefix % is processed.
> > +    //
> > +    if (*Format != '%') {
> > +      continue;
> > +    }
> > +
> > +    Long = FALSE;
> > +
> > +    //
> > +    // Parse Flags and Width
> > +    //
> > +    for (Format++; TRUE; Format++) {
> > +      if (*Format == '.' || *Format == '-' || *Format == '+' || *Format == ' ') {
> > +        //
> > +        // These characters in format field are omitted.
> > +        //
> > +        continue;
> > +      }
> > +      if (*Format >= '0' && *Format <= '9') {
> > +        //
> > +        // These characters in format field are omitted.
> > +        //
> > +        continue;
> > +      }
> > +      if (*Format == 'L' || *Format == 'l') {
> > +        //
> > +        // 'L" or "l" in format field means the number being printed is a
> UINT64
> > +        //
> > +        Long = TRUE;
> > +        continue;
> > +      }
> > +      if (*Format == '*') {
> > +        //
> > +        // '*' in format field means the precision of the field is specified by
> > +        // a UINTN argument in the argument list.
> > +        //
> > +        BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker,
> UINTN);
> > +        continue;
> > +      }
> > +      if (*Format == '\0') {
> > +        //
> > +        // Make no output if Format string terminates unexpectedly when
> > +        // looking up for flag, width, precision and type.
> > +        //
> > +        Format--;
> > +      }
> > +      //
> > +      // When valid argument type detected or format string
> > + terminates
> > unexpectedly,
> > +      // the inner loop is done.
> > +      //
> > +      break;
> > +    }
> > +
> > +    //
> > +    // Pack variable arguments into the storage area following
> > EFI_DEBUG_INFO.
> > +    //
> > +    if ((*Format == 'p') && (sizeof (VOID *) > 4)) {
> > +      Long = TRUE;
> > +    }
> > +    if (*Format == 'p' || *Format == 'X' || *Format == 'x' || *Format
> > + == 'd' ||
> > *Format == 'u') {
> > +      if (Long) {
> > +        BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);
> > +      } else {
> > +        BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);
> > +      }
> > +    } else if (*Format == 's' || *Format == 'S' || *Format == 'a' ||
> > + *Format ==
> > 'g' || *Format == 't') {
> > +      BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID
> *);
> > +    } else if (*Format == 'c') {
> > +      BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);
> > +    } else if (*Format == 'r') {
> > +      BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG
> > + (VaListMarker,
> > RETURN_STATUS);
> > +    }
> > +
> > +    //
> > +    // If the converted BASE_LIST is larger than the size of
> > + BaseListMarker,
> > then return FALSE
> > +    //
> > +    if (((UINTN)BaseListMarker - (UINTN)BaseListStart) > Size) {
> > +      return FALSE;
> > +    }
> > +  }
> > +
> > +  return TRUE;
> > +}
> > +
> > +
> > +/**
> > +  Prints a debug message to the debug output device if the specified
> > +  error level is enabled.
> > +
> > +  If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib
> > + function  GetDebugPrintErrorLevel (), then print the message
> > + specified by Format and  the associated variable argument list to
> > + the debug output
> > device.
> > +
> > +  If Format is NULL, then ASSERT().
> > +
> > +  @param  ErrorLevel    The error level of the debug message.
> > +  @param  Format        Format string for the debug message to print.
> > +  @param  VaListMarker  VA_LIST marker for the variable argument list.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugVPrint (
> > +  IN  UINTN         ErrorLevel,
> > +  IN  CONST CHAR8   *Format,
> > +  IN  VA_LIST       VaListMarker
> > +  )
> > +{
> > +  UINT64            BaseListMarker[256 / sizeof (UINT64)];
> > +  BOOLEAN           Converted;
> > +
> > +  //
> > +  // Convert the VaList to BaseList
> > +  //
> > +  Converted = VaListToBaseList (
> > +                Format,
> > +                VaListMarker,
> > +                (BASE_LIST)BaseListMarker,
> > +                sizeof (BaseListMarker) - 8
> > +                );
> > +
> > +  if (!Converted) {
> > +    return;
> > +  }
> > +
> > +  DebugBPrint (ErrorLevel, Format, (BASE_LIST)BaseListMarker); }
> > +
> > +
> > +/**
> > +  Prints an assert message containing a filename, line number, and
> > description.
> > +  This may be followed by a breakpoint or a dead loop.
> > +
> > +  Print a message of the form "ASSERT <FileName>(<LineNumber>):
> > <Description>\n"
> > +  to the debug output device.  If
> > + DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED bit of
> > PcdDebugProperyMask
> > + is set then CpuBreakpoint() is called. Otherwise, if
> > + DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of
> > PcdDebugProperyMask is
> > + set then
> > +  CpuDeadLoop() is called.  If neither of these bits are set, then
> > + this function  returns immediately after the message is printed to
> > + the debug
> > output device.
> > +  DebugAssert() must actively prevent recursion.  If DebugAssert() is
> > + called while  processing another DebugAssert(), then DebugAssert()
> > + must
> > return immediately.
> > +
> > +  If FileName is NULL, then a <FileName> string of "(NULL) Filename"
> > + is
> > printed.
> > +  If Description is NULL, then a <Description> string of "(NULL)
> > + Description" is
> > printed.
> > +
> > +  @param  FileName     The pointer to the name of the source file that
> > generated the assert condition.
> > +  @param  LineNumber   The line number in the source file that generated
> > the assert condition
> > +  @param  Description  The pointer to the description of the assert
> condition.
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +DebugAssert (
> > +  IN CONST CHAR8  *FileName,
> > +  IN UINTN        LineNumber,
> > +  IN CONST CHAR8  *Description
> > +  )
> > +{
> > +  EFI_STATUS      Status;
> > +
> > +  if (mEdkiiDebugPpi == NULL) {
> > +    Status = PeiServicesLocatePpi (
> > +                &gEdkiiDebugPpiGuid,
> > +                0,
> > +                NULL,
> > +                (VOID **)&mEdkiiDebugPpi
> > +                );
> > +    if (EFI_ERROR (Status)) {
> > +      return;
> > +    }
> > +  }
> > +
> > +  mEdkiiDebugPpi->DebugAssert (
> > +                    FileName,
> > +                    LineNumber,
> > +                    Description
> > +                    );
> > +}
> > +
> > +
> > +/**
> > +  Fills a target buffer with PcdDebugClearMemoryValue, and returns
> > +the
> > target buffer.
> > +
> > +  This function fills Length bytes of Buffer with the value specified
> > + by  PcdDebugClearMemoryValue, and returns Buffer.
> > +
> > +  If Buffer is NULL, then ASSERT().
> > +  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
> > +
> > +  @param   Buffer  The pointer to the target buffer to be filled with
> > PcdDebugClearMemoryValue.
> > +  @param   Length  The number of bytes in Buffer to fill with zeros
> > PcdDebugClearMemoryValue.
> > +
> > +  @return  Buffer  The pointer to the target buffer filled with
> > PcdDebugClearMemoryValue.
> > +
> > +**/
> > +VOID *
> > +EFIAPI
> > +DebugClearMemory (
> > +  OUT VOID  *Buffer,
> > +  IN UINTN  Length
> > +  )
> > +{
> > +  ASSERT (Buffer != NULL);
> > +
> > +  return SetMem (Buffer, Length, PcdGet8
> (PcdDebugClearMemoryValue));
> > + }
> > +
> > +
> > +/**
> > +  Returns TRUE if ASSERT() macros are enabled.
> > +
> > +  This function returns TRUE if the
> > DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED
> > + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> > +
> > +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
> > PcdDebugProperyMask is set.
> > +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of
> > PcdDebugProperyMask is clear.
> > +
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +DebugAssertEnabled (
> > +  VOID
> > +  )
> > +{
> > +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> > +DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0); }
> > +
> > +
> > +/**
> > +  Returns TRUE if DEBUG() macros are enabled.
> > +
> > +  This function returns TRUE if the
> > DEBUG_PROPERTY_DEBUG_PRINT_ENABLED
> > + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> > +
> > +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
> > PcdDebugProperyMask is set.
> > +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of
> > PcdDebugProperyMask is clear.
> > +
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +DebugPrintEnabled (
> > +  VOID
> > +  )
> > +{
> > +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> > +DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 0); }
> > +
> > +
> > +/**
> > +  Returns TRUE if DEBUG_CODE() macros are enabled.
> > +
> > +  This function returns TRUE if the
> > DEBUG_PROPERTY_DEBUG_CODE_ENABLED
> > + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> > +
> > +  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
> > PcdDebugProperyMask is set.
> > +  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of
> > PcdDebugProperyMask is clear.
> > +
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +DebugCodeEnabled (
> > +  VOID
> > +  )
> > +{
> > +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> > +DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0); }
> > +
> > +
> > +/**
> > +  Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
> > +
> > +  This function returns TRUE if the
> > DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED
> > + bit of  PcdDebugProperyMask is set.  Otherwise, FALSE is returned.
> > +
> > +  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit
> of
> > PcdDebugProperyMask is set.
> > +  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit
> of
> > PcdDebugProperyMask is clear.
> > +
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +DebugClearMemoryEnabled (
> > +  VOID
> > +  )
> > +{
> > +  return (BOOLEAN) ((PcdGet8 (PcdDebugPropertyMask) &
> > +DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0); }
> > +
> > +
> > +/**
> > +  Returns TRUE if any one of the bit is set both in ErrorLevel and
> > PcdFixedDebugPrintErrorLevel.
> > +
> > +  This function compares the bit mask of ErrorLevel and
> > PcdFixedDebugPrintErrorLevel.
> > +
> > +  @retval  TRUE    Current ErrorLevel is supported.
> > +  @retval  FALSE   Current ErrorLevel is not supported.
> > +
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +DebugPrintLevelEnabled (
> > +  IN  CONST UINTN        ErrorLevel
> > +  )
> > +{
> > +  return (BOOLEAN) ((ErrorLevel &
> > +PcdGet32(PcdFixedDebugPrintErrorLevel)) != 0); }
> > +
> > diff --git
> >
> a/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> >
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> > new file mode 100644
> > index 0000000000..61c7a4fea7
> > --- /dev/null
> > +++
> >
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> > @@ -0,0 +1,56 @@
> > +## @file
> > +#  Debug Lib instance through DebugServicePei for PEI phase # #  This
> > +module use gEdkiiDebugPpiGuid to implement the PEI DebugLib for
> > +reduce #  the size of PEIMs which consume DebugLib # #  Copyright (c)
> > +2019, 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 # http://opensource.org/licenses/bsd-license.php
> > +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > +BASIS, #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
> > EITHER EXPRESS OR IMPLIED.
> > +#
> > +##
> > +
> > +[Defines]
> > +  INF_VERSION                    = 0x00010005
> > +  BASE_NAME                      = PeiDebugLibDebugPpi
> > +  FILE_GUID                      = 2E08836C-4D1C-42F7-BBBE-EC5D25F1FDD4
> > +  MODULE_TYPE                    = PEIM
> > +  VERSION_STRING                 = 1.0
> > +  LIBRARY_CLASS                  = DebugLib|PEIM
> > +
> > +#
> > +# The following information is for reference only and not required by
> > +the
> > build tools.
> > +#
> > +#  VALID_ARCHITECTURES           = IA32 X64 EBC
> > +#
> > +
> > +[Sources]
> > +  DebugLib.c
> > +
> > +[Packages]
> > +  MdePkg/MdePkg.dec
> > +  MdeModulePkg/MdeModulePkg.dec
> > +
> > +[LibraryClasses]
> > +  PcdLib
> > +  BaseMemoryLib
> > +  DebugPrintErrorLevelLib
> > +  PeiServicesLib
> > +  PeiServicesTablePointerLib
> > +
> > +[Ppis]
> > +  gEdkiiDebugPpiGuid                                        ## CONSUMES
> > +
> > +[Pcd]
> > +  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue         ##
> > SOMETIMES_CONSUMES
> > +  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask             ##
> > CONSUMES
> > +  gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel     ##
> > CONSUMES
> > +
> > +[Depex]
> > +  gEdkiiDebugPpiGuid
> > +
> > --
> > 2.21.0.windows.1



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2019-03-29  5:10 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-28  8:09 [PATCH V5 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 02/17] MdePkg/BaseDebugLibNull: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 03/17] MdePkg/BaseDebugLibSerialPort: Add new APIs Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 04/17] MdePkg/UefidebugLibConOut: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 05/17] MdePkg/UefiDebugLibStdErr: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 06/17] MdePkg/DxeRuntimeDebugLibSerialPort: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 07/17] MdePkg/UefiDebuglibDebugPortProtocol: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 08/17] ArmPkg/SemiHostingDebugLib: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 09/17] OvmfPkg/PlatformDebugLibIoPort: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
2019-03-28  8:44   ` Chiu, Chasel
2019-03-28  8:10 ` [PATCH V5 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
2019-03-28  8:44   ` Chiu, Chasel
2019-03-28  8:10 ` [PATCH V5 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
2019-03-28 10:13   ` Ni, Ray
2019-03-29  0:11     ` Gao, Zhichao
2019-03-28  8:10 ` [PATCH V5 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
2019-03-28  8:10 ` [PATCH V5 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
2019-03-28 10:10   ` Ni, Ray
2019-03-29  5:10     ` Gao, Zhichao
2019-03-28  8:10 ` [PATCH V5 17/17] MdeModulePkg: Add PEIM and lib to dsc file Zhichao Gao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox