public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib
@ 2019-03-21 14:04 Zhichao Gao
  2019-03-21 14:04 ` [PATCH V4 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
                   ` (16 more replies)
  0 siblings, 17 replies; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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.

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>

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

Zhichao Gao (16):
  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
  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      | 173 ++++++--
 .../Library/BaseFspDebugLibSerialPort/DebugLib.c   | 103 ++++-
 .../Library/BaseFspDebugLibSerialPort/DebugLib.c   | 103 ++++-
 MdeModulePkg/Include/Ppi/Debug.h                   |  82 ++++
 .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456 +++++++++++++++++++++
 .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c      | 171 ++++++--
 MdeModulePkg/MdeModulePkg.dec                      |   3 +
 MdeModulePkg/MdeModulePkg.dsc                      |   3 +
 .../Universal/DebugServicePei/DebugService.c       |  60 +++
 .../Universal/DebugServicePei/DebugService.h       |  56 +++
 .../Universal/DebugServicePei/DebugServicePei.c    |  54 +++
 .../Universal/DebugServicePei/DebugServicePei.inf  |  52 +++
 .../Universal/DebugServicePei/DebugServicePei.uni  |  20 +
 MdePkg/Include/Library/DebugLib.h                  |  52 ++-
 MdePkg/Library/BaseDebugLibNull/DebugLib.c         |  56 ++-
 MdePkg/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 ++++-
 OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c  | 106 ++++-
 23 files changed, 2140 insertions(+), 102 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.c
 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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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/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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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.16.2.windows.1



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

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

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>
---
 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.16.2.windows.1



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

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

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>
---
 OvmfPkg/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.16.2.windows.1



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

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

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>
---
 .../Library/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.16.2.windows.1



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

* [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (9 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  2019-03-22  1:28   ` Chiu, Chasel
  2019-03-22  7:08   ` Desimone, Nathaniel L
  2019-03-21 14:04 ` [PATCH V4 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
                   ` (5 subsequent siblings)
  16 siblings, 2 replies; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 UTC (permalink / raw)
  To: edk2-devel
  Cc: Chasel Chiu, Nate DeSimone, Star Zeng, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

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>
---
 .../Library/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.16.2.windows.1



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

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

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>
---
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c      | 173 +++++++++++++++++----
 1 file changed, 145 insertions(+), 28 deletions(-)

diff --git a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index b0445115a9..7ae4edb40d 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,25 +121,25 @@ 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);
   }
 
   //
@@ -110,7 +152,7 @@ DebugPrint (
   //
   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.16.2.windows.1



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

* [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (11 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  2019-03-22  1:50   ` Wu, Hao A
  2019-03-21 14:04 ` [PATCH V4 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
                   ` (3 subsequent siblings)
  16 siblings, 1 reply; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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=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>
---
 .../PeiDxeDebugLibReportStatusCode/DebugLib.c      | 171 +++++++++++++++++----
 1 file changed, 144 insertions(+), 27 deletions(-)

diff --git a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
index 6f0f416273..d593752050 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);
@@ -109,7 +151,7 @@ DebugPrint (
   //
   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.16.2.windows.1



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

* [PATCH V4 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (12 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  2019-03-22  1:58   ` Wu, Hao A
  2019-03-21 14:04 ` [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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=1395

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>
---
 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..dc50ed1b46
--- /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] VaListMarker             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.16.2.windows.1



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

* [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (13 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  2019-03-22  2:00   ` Wu, Hao A
  2019-03-28  2:05   ` Gao, Liming
  2019-03-21 14:04 ` [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
  2019-03-21 14:04 ` [PATCH V4 17/17] MdeModulePkg: Add PEIM and lib to dsc file Zhichao Gao
  16 siblings, 2 replies; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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=1395

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>
---
 .../Universal/DebugServicePei/DebugService.c       | 60 ++++++++++++++++++++++
 .../Universal/DebugServicePei/DebugService.h       | 56 ++++++++++++++++++++
 .../Universal/DebugServicePei/DebugServicePei.c    | 54 +++++++++++++++++++
 .../Universal/DebugServicePei/DebugServicePei.inf  | 52 +++++++++++++++++++
 .../Universal/DebugServicePei/DebugServicePei.uni  | 20 ++++++++
 5 files changed, 242 insertions(+)
 create mode 100644 MdeModulePkg/Universal/DebugServicePei/DebugService.c
 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.c b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
new file mode 100644
index 0000000000..a9ea14db81
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
@@ -0,0 +1,60 @@
+/** @file
+  Debug services instances for PEI phase.
+
+  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 <Ppi/Debug.h>
+#include <Library/DebugLib.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
+  )
+{
+  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);
+}
+
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..06117cfcf0
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
@@ -0,0 +1,54 @@
+/** @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 "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
+};
+
+/**
+  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..e1252b658d
--- /dev/null
+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
@@ -0,0 +1,52 @@
+## @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.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.16.2.windows.1



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

* [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (14 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  2019-03-22  2:09   ` Wu, Hao A
  2019-03-28  2:04   ` Gao, Liming
  2019-03-21 14:04 ` [PATCH V4 17/17] MdeModulePkg: Add PEIM and lib to dsc file Zhichao Gao
  16 siblings, 2 replies; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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=1395

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>
---
 .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456 +++++++++++++++++++++
 .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
 2 files changed, 511 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..75859163ae
--- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
+    Status = PeiServicesLocatePpi (
+                &gEdkiiDebugPpiGuid,
+                0,
+                NULL,
+                (VOID **)&mDebugPpi
+                );
+    if (EFI_ERROR (Status)) {
+      CpuDeadLoop();
+    }
+  }
+
+  mDebugPpi->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 (mDebugPpi == NULL) {
+    Status = PeiServicesLocatePpi (
+                &gEdkiiDebugPpiGuid,
+                0,
+                NULL,
+                (VOID **)&mDebugPpi
+                );
+    if (EFI_ERROR (Status)) {
+      CpuDeadLoop();
+    }
+  }
+
+  mDebugPpi->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..4ab21e577e
--- /dev/null
+++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
@@ -0,0 +1,55 @@
+## @file
+#  Debug Lib instance through DebugServicePei for PEI phase
+#
+#  This module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check for FTW last write data has been done.
+#
+#  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.16.2.windows.1



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

* [PATCH V4 17/17] MdeModulePkg: Add PEIM and lib to dsc file
  2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
                   ` (15 preceding siblings ...)
  2019-03-21 14:04 ` [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
@ 2019-03-21 14:04 ` Zhichao Gao
  16 siblings, 0 replies; 37+ messages in thread
From: Zhichao Gao @ 2019-03-21 14:04 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=1395

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>
---
 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.16.2.windows.1



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

* Re: [PATCH V4 09/17] OvmfPkg/PlatformDebugLibIoPort: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 09/17] OvmfPkg/PlatformDebugLibIoPort: " Zhichao Gao
@ 2019-03-21 18:58   ` Laszlo Ersek
  2019-03-22  0:42     ` Gao, Zhichao
  0 siblings, 1 reply; 37+ messages in thread
From: Laszlo Ersek @ 2019-03-21 18:58 UTC (permalink / raw)
  To: Zhichao Gao, edk2-devel
  Cc: Jordan Justen, Ard Biesheuvel, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

On 03/21/19 15:04, Zhichao Gao wrote:
> 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>
> ---
>  OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 106 +++++++++++++++++++++-
>  1 file changed, 101 insertions(+), 5 deletions(-)

This v4 patch is identical to v3.

When you repost a series in order to update a subset of the patches, you
should please pick up the feedback tags from the previous review session
for those patches that you do *not* change.

This is explained here, for example:

https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers#contrib-26

https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-guide-for-edk2-contributors-and-maintainers#contrib-28

This makes a huge difference for reviewers -- it costs you a bit of
time, but it saves reviewers a lot more time.

For example, the present patch has not been changed from v3 to v4, and I
gave my A-b in the v3 review session. Therefore you should have edited
the commit message on this patch, to include my A-b, for the v4 posting.

Either way, I can give it again here.

Acked-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


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

* Re: [PATCH V4 09/17] OvmfPkg/PlatformDebugLibIoPort: Add new APIs
  2019-03-21 18:58   ` Laszlo Ersek
@ 2019-03-22  0:42     ` Gao, Zhichao
  0 siblings, 0 replies; 37+ messages in thread
From: Gao, Zhichao @ 2019-03-22  0:42 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel@lists.01.org
  Cc: Justen, Jordan L, Ard Biesheuvel, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Sorry for forgetting to add tag.
I am new to this community and this wiki page would help me a lot. 

Thanks,
Zhichao

> -----Original Message-----
> From: Laszlo Ersek [mailto:lersek@redhat.com]
> Sent: Friday, March 22, 2019 2:58 AM
> To: Gao, Zhichao <zhichao.gao@intel.com>; edk2-devel@lists.01.org
> Cc: Justen, Jordan L <jordan.l.justen@intel.com>; Ard Biesheuvel
> <ard.biesheuvel@linaro.org>; 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 V4 09/17] OvmfPkg/PlatformDebugLibIoPort: Add new
> APIs
> 
> On 03/21/19 15:04, Zhichao Gao wrote:
> > 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>
> > ---
> >  OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 106
> > +++++++++++++++++++++-
> >  1 file changed, 101 insertions(+), 5 deletions(-)
> 
> This v4 patch is identical to v3.
> 
> When you repost a series in order to update a subset of the patches, you
> should please pick up the feedback tags from the previous review session for
> those patches that you do *not* change.
> 
> This is explained here, for example:
> 
> https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-
> guide-for-edk2-contributors-and-maintainers#contrib-26
> 
> https://github.com/tianocore/tianocore.github.io/wiki/Laszlo's-unkempt-git-
> guide-for-edk2-contributors-and-maintainers#contrib-28
> 
> This makes a huge difference for reviewers -- it costs you a bit of time, but it
> saves reviewers a lot more time.
> 
> For example, the present patch has not been changed from v3 to v4, and I
> gave my A-b in the v3 review session. Therefore you should have edited the
> commit message on this patch, to include my A-b, for the v4 posting.
> 
> Either way, I can give it again here.
> 
> Acked-by: Laszlo Ersek <lersek@redhat.com>
> 
> Thanks
> Laszlo

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

* Re: [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-22  1:28   ` Chiu, Chasel
  2019-03-22  7:08   ` Desimone, Nathaniel L
  1 sibling, 0 replies; 37+ messages in thread
From: Chiu, Chasel @ 2019-03-22  1:28 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Desimone, Nathaniel L, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: 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>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new
> APIs
> 
> 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>
> ---
>  .../Library/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.16.2.windows.1



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

* Re: [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
@ 2019-03-22  1:28   ` Chiu, Chasel
  2019-03-22  7:08   ` Desimone, Nathaniel L
  1 sibling, 0 replies; 37+ messages in thread
From: Chiu, Chasel @ 2019-03-22  1:28 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Desimone, Nathaniel L, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew


Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: 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>; Bret Barkelew
> <Bret.Barkelew@microsoft.com>
> Subject: [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new
> APIs
> 
> 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>
> ---
>  .../Library/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.16.2.windows.1



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

* Re: [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-22  1:50   ` Wu, Hao A
  0 siblings, 0 replies; 37+ messages in thread
From: Wu, Hao A @ 2019-03-22  1:50 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode:
> Add new APIs
> 
> 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>
> ---
>  .../PeiDxeDebugLibReportStatusCode/DebugLib.c      | 171
> +++++++++++++++++----
>  1 file changed, 144 insertions(+), 27 deletions(-)
> 
> diff --git
> a/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> b/MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/DebugLib.c
> index 6f0f416273..d593752050 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);

It seems to me that the below chunk of comment needs to be updated for the
rename to the 'BaseListMarkerPointer' as well:

  //
  // 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
  // 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.
  //

There is no need to re-send the patch again if there is no other major
change in the patch series. And you can keep my previous 'Reviewed-by'
tag given in V3 of the series.

Best Regards,
Hao Wu


> @@ -109,7 +151,7 @@ DebugPrint (
>    //
>    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.16.2.windows.1



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

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

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [PATCH V4 14/17] MdeModulePkg: Add definitions for EDKII DEBUG
> PPI
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> 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>
> ---
>  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..dc50ed1b46
> --- /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] VaListMarker             BASE_LIST marker for the variable
> argument list.

Minor comment:

Parameter name is not consistent between function description comment
'VaListMarker' and the service prototype 'Marker'.

With this handled:
Reviewed-by: Hao Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


> +
> +**/
> +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.16.2.windows.1



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

* Re: [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
  2019-03-21 14:04 ` [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
@ 2019-03-22  2:00   ` Wu, Hao A
  2019-03-28  2:05   ` Gao, Liming
  1 sibling, 0 replies; 37+ messages in thread
From: Wu, Hao A @ 2019-03-22  2:00 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Ni, Ray, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Reviewed-by: Hao Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Gao, Liming; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> 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>
> ---
>  .../Universal/DebugServicePei/DebugService.c       | 60
> ++++++++++++++++++++++
>  .../Universal/DebugServicePei/DebugService.h       | 56
> ++++++++++++++++++++
>  .../Universal/DebugServicePei/DebugServicePei.c    | 54
> +++++++++++++++++++
>  .../Universal/DebugServicePei/DebugServicePei.inf  | 52
> +++++++++++++++++++
>  .../Universal/DebugServicePei/DebugServicePei.uni  | 20 ++++++++
>  5 files changed, 242 insertions(+)
>  create mode 100644
> MdeModulePkg/Universal/DebugServicePei/DebugService.c
>  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.c
> b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
> new file mode 100644
> index 0000000000..a9ea14db81
> --- /dev/null
> +++ b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
> @@ -0,0 +1,60 @@
> +/** @file
> +  Debug services instances for PEI phase.
> +
> +  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 <Ppi/Debug.h>
> +#include <Library/DebugLib.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
> +  )
> +{
> +  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);
> +}
> +
> 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..06117cfcf0
> --- /dev/null
> +++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
> @@ -0,0 +1,54 @@
> +/** @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 "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
> +};
> +
> +/**
> +  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..e1252b658d
> --- /dev/null
> +++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
> @@ -0,0 +1,52 @@
> +## @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.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.16.2.windows.1



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

* Re: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-21 14:04 ` [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
@ 2019-03-22  2:09   ` Wu, Hao A
  2019-03-22  2:19     ` Gao, Zhichao
  2019-03-28  2:04   ` Gao, Liming
  1 sibling, 1 reply; 37+ messages in thread
From: Wu, Hao A @ 2019-03-22  2:09 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Gao, Liming, Wang, Jian J, Ni, Ray, Zeng, Star, Sean Brogan,
	Michael Turner, Bret Barkelew

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, March 21, 2019 10:05 PM
> To: edk2-devel@lists.01.org
> Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean Brogan;
> Michael Turner; Bret Barkelew
> Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> debug lib
> 
> From: Liming Gao <liming.gao@intel.com>
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> 
> 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>
> ---
>  .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456
> +++++++++++++++++++++
>  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
>  2 files changed, 511 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..75859163ae
> --- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
> +    Status = PeiServicesLocatePpi (

*****

> +                &gEdkiiDebugPpiGuid,
> +                0,
> +                NULL,
> +                (VOID **)&mDebugPpi
> +                );

*****

The indention seems not consistent for the above several lines.


> +    if (EFI_ERROR (Status)) {
> +      CpuDeadLoop();
> +    }
> +  }
> +
> +  mDebugPpi->DebugBPrint (

*****

> +              ErrorLevel,
> +              Format,
> +              BaseListMarker
> +              );

*****

The indention seems not consistent for the above several lines.


> +}
> +
> +
> +/**
> +  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 (mDebugPpi == NULL) {
> +    Status = PeiServicesLocatePpi (

*****

> +                &gEdkiiDebugPpiGuid,
> +                0,
> +                NULL,
> +                (VOID **)&mDebugPpi
> +                );

*****

The indention seems not consistent for the above several lines.


> +    if (EFI_ERROR (Status)) {
> +      CpuDeadLoop();
> +    }
> +  }
> +
> +  mDebugPpi->DebugAssert (

*****

> +              FileName,
> +              LineNumber,
> +              Description
> +              );

*****

The indention seems not consistent for the above several lines.


> +}
> +
> +
> +/**
> +  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..4ab21e577e
> --- /dev/null
> +++ b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> @@ -0,0 +1,55 @@
> +## @file
> +#  Debug Lib instance through DebugServicePei for PEI phase
> +#
> +#  This module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check
> for FTW last write data has been done.

Please help to correct the above description for the INF file.

With the these minor comments handled:
Reviewed-by: Hao Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


> +#
> +#  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.16.2.windows.1



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

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

For the sections you point. It seems good to watch the patch downloaded.
The indention is one or two space behind the function name depend on tab expand(2 space).
Is it need to adjust them?

Thanks,
Zhichao

> -----Original Message-----
> From: Wu, Hao A
> Sent: Friday, March 22, 2019 10:09 AM
> 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>; 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: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> PEI debug lib
> 
> > -----Original Message-----
> > From: Gao, Zhichao
> > Sent: Thursday, March 21, 2019 10:05 PM
> > To: edk2-devel@lists.01.org
> > Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean
> > Brogan; Michael Turner; Bret Barkelew
> > Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> > debug lib
> >
> > From: Liming Gao <liming.gao@intel.com>
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> >
> > 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>
> > ---
> >  .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456
> > +++++++++++++++++++++
> >  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
> >  2 files changed, 511 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..75859163ae
> > --- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
> > +    Status = PeiServicesLocatePpi (
> 
> *****
> 
> > +                &gEdkiiDebugPpiGuid,
> > +                0,
> > +                NULL,
> > +                (VOID **)&mDebugPpi
> > +                );
> 
> *****
> 
> The indention seems not consistent for the above several lines.
> 
> 
> > +    if (EFI_ERROR (Status)) {
> > +      CpuDeadLoop();
> > +    }
> > +  }
> > +
> > +  mDebugPpi->DebugBPrint (
> 
> *****
> 
> > +              ErrorLevel,
> > +              Format,
> > +              BaseListMarker
> > +              );
> 
> *****
> 
> The indention seems not consistent for the above several lines.
> 
> 
> > +}
> > +
> > +
> > +/**
> > +  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 (mDebugPpi == NULL) {
> > +    Status = PeiServicesLocatePpi (
> 
> *****
> 
> > +                &gEdkiiDebugPpiGuid,
> > +                0,
> > +                NULL,
> > +                (VOID **)&mDebugPpi
> > +                );
> 
> *****
> 
> The indention seems not consistent for the above several lines.
> 
> 
> > +    if (EFI_ERROR (Status)) {
> > +      CpuDeadLoop();
> > +    }
> > +  }
> > +
> > +  mDebugPpi->DebugAssert (
> 
> *****
> 
> > +              FileName,
> > +              LineNumber,
> > +              Description
> > +              );
> 
> *****
> 
> The indention seems not consistent for the above several lines.
> 
> 
> > +}
> > +
> > +
> > +/**
> > +  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..4ab21e577e
> > --- /dev/null
> > +++
> b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> > @@ -0,0 +1,55 @@
> > +## @file
> > +#  Debug Lib instance through DebugServicePei for PEI phase # #  This
> > +module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check
> > for FTW last write data has been done.
> 
> Please help to correct the above description for the INF file.
> 
> With the these minor comments handled:
> Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> 
> Best Regards,
> Hao Wu
> 
> 
> > +#
> > +#  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.16.2.windows.1



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

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

If it follows the EDK II C Coding Standards Specification, then ignore
my relating comments then,

Best Regards,
Hao Wu

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Friday, March 22, 2019 10:19 AM
> To: Wu, Hao A; edk2-devel@lists.01.org
> Cc: Gao, Liming; Wang, Jian J; Ni, Ray; Zeng, Star; Sean Brogan; Michael Turner;
> Bret Barkelew
> Subject: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> debug lib
> 
> For the sections you point. It seems good to watch the patch downloaded.
> The indention is one or two space behind the function name depend on tab
> expand(2 space).
> Is it need to adjust them?
> 
> Thanks,
> Zhichao
> 
> > -----Original Message-----
> > From: Wu, Hao A
> > Sent: Friday, March 22, 2019 10:09 AM
> > 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>; 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: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> > PEI debug lib
> >
> > > -----Original Message-----
> > > From: Gao, Zhichao
> > > Sent: Thursday, March 21, 2019 10:05 PM
> > > To: edk2-devel@lists.01.org
> > > Cc: Gao, Liming; Wang, Jian J; Wu, Hao A; Ni, Ray; Zeng, Star; Sean
> > > Brogan; Michael Turner; Bret Barkelew
> > > Subject: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> > > debug lib
> > >
> > > From: Liming Gao <liming.gao@intel.com>
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> > >
> > > 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>
> > > ---
> > >  .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456
> > > +++++++++++++++++++++
> > >  .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
> > >  2 files changed, 511 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..75859163ae
> > > --- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
> > > +    Status = PeiServicesLocatePpi (
> >
> > *****
> >
> > > +                &gEdkiiDebugPpiGuid,
> > > +                0,
> > > +                NULL,
> > > +                (VOID **)&mDebugPpi
> > > +                );
> >
> > *****
> >
> > The indention seems not consistent for the above several lines.
> >
> >
> > > +    if (EFI_ERROR (Status)) {
> > > +      CpuDeadLoop();
> > > +    }
> > > +  }
> > > +
> > > +  mDebugPpi->DebugBPrint (
> >
> > *****
> >
> > > +              ErrorLevel,
> > > +              Format,
> > > +              BaseListMarker
> > > +              );
> >
> > *****
> >
> > The indention seems not consistent for the above several lines.
> >
> >
> > > +}
> > > +
> > > +
> > > +/**
> > > +  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 (mDebugPpi == NULL) {
> > > +    Status = PeiServicesLocatePpi (
> >
> > *****
> >
> > > +                &gEdkiiDebugPpiGuid,
> > > +                0,
> > > +                NULL,
> > > +                (VOID **)&mDebugPpi
> > > +                );
> >
> > *****
> >
> > The indention seems not consistent for the above several lines.
> >
> >
> > > +    if (EFI_ERROR (Status)) {
> > > +      CpuDeadLoop();
> > > +    }
> > > +  }
> > > +
> > > +  mDebugPpi->DebugAssert (
> >
> > *****
> >
> > > +              FileName,
> > > +              LineNumber,
> > > +              Description
> > > +              );
> >
> > *****
> >
> > The indention seems not consistent for the above several lines.
> >
> >
> > > +}
> > > +
> > > +
> > > +/**
> > > +  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..4ab21e577e
> > > --- /dev/null
> > > +++
> > b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> > > @@ -0,0 +1,55 @@
> > > +## @file
> > > +#  Debug Lib instance through DebugServicePei for PEI phase # #  This
> > > +module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check
> > > for FTW last write data has been done.
> >
> > Please help to correct the above description for the INF file.
> >
> > With the these minor comments handled:
> > Reviewed-by: Hao Wu <hao.a.wu@intel.com>
> >
> > Best Regards,
> > Hao Wu
> >
> >
> > > +#
> > > +#  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.16.2.windows.1



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

* Re: [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
  2019-03-22  1:28   ` Chiu, Chasel
@ 2019-03-22  7:08   ` Desimone, Nathaniel L
  1 sibling, 0 replies; 37+ messages in thread
From: Desimone, Nathaniel L @ 2019-03-22  7:08 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Chiu, Chasel, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: Gao, Zhichao 
Sent: Thursday, March 21, 2019 7:05 AM
To: edk2-devel@lists.01.org
Cc: 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>; Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: Add new APIs

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>
---
 .../Library/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.16.2.windows.1



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

* Re: [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
  2019-03-22  1:28   ` Chiu, Chasel
@ 2019-03-22  7:08   ` Desimone, Nathaniel L
  1 sibling, 0 replies; 37+ messages in thread
From: Desimone, Nathaniel L @ 2019-03-22  7:08 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Chiu, Chasel, Zeng, Star, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: Gao, Zhichao 
Sent: Thursday, March 21, 2019 7:05 AM
To: edk2-devel@lists.01.org
Cc: 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>; Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: Add new APIs

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>
---
 .../Library/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.16.2.windows.1



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

* Re: [PATCH V4 08/17] ArmPkg/SemiHostingDebugLib: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 08/17] ArmPkg/SemiHostingDebugLib: " Zhichao Gao
@ 2019-03-26 12:19   ` Leif Lindholm
  2019-03-26 12:43     ` Ard Biesheuvel
  2019-03-27  1:21     ` Gao, Zhichao
  0 siblings, 2 replies; 37+ messages in thread
From: Leif Lindholm @ 2019-03-26 12:19 UTC (permalink / raw)
  To: Zhichao Gao
  Cc: edk2-devel, Ard Biesheuvel, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

Hi Zhichao,

Apologies for delay in responding, due to holiday and stuff.

On the whole this looks fine (one comment below), but I don't actually
have any platform on which to test this.

Ard: maybe it's time to retire this component?

On Thu, Mar 21, 2019 at 10:04:50PM +0800, Zhichao Gao wrote:
> 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>
> ---
>  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;

I would prefer if this was marked STATIC.

If you feel strongly otherwise, leave it as is.
Either way:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

/
    Leif

> +
>  /**
>  
>    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.16.2.windows.1
> 


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

* Re: [PATCH V4 08/17] ArmPkg/SemiHostingDebugLib: Add new APIs
  2019-03-26 12:19   ` Leif Lindholm
@ 2019-03-26 12:43     ` Ard Biesheuvel
  2019-03-27  1:21     ` Gao, Zhichao
  1 sibling, 0 replies; 37+ messages in thread
From: Ard Biesheuvel @ 2019-03-26 12:43 UTC (permalink / raw)
  To: Leif Lindholm, Cohen, Eugene
  Cc: Zhichao Gao, edk2-devel@lists.01.org, Liming Gao, Sean Brogan,
	Michael Turner, Bret Barkelew

On Tue, 26 Mar 2019 at 13:19, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>
> Hi Zhichao,
>
> Apologies for delay in responding, due to holiday and stuff.
>
> On the whole this looks fine (one comment below), but I don't actually
> have any platform on which to test this.
>
> Ard: maybe it's time to retire this component?
>

I don't have a problem with that. Adding Eugene, perhaps he has an
opinion as well.


> On Thu, Mar 21, 2019 at 10:04:50PM +0800, Zhichao Gao wrote:
> > 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>
> > ---
> >  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;
>
> I would prefer if this was marked STATIC.
>
> If you feel strongly otherwise, leave it as is.
> Either way:
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>
> /
>     Leif
>
> > +
> >  /**
> >
> >    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.16.2.windows.1
> >


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

* Re: [PATCH V4 08/17] ArmPkg/SemiHostingDebugLib: Add new APIs
  2019-03-26 12:19   ` Leif Lindholm
  2019-03-26 12:43     ` Ard Biesheuvel
@ 2019-03-27  1:21     ` Gao, Zhichao
  1 sibling, 0 replies; 37+ messages in thread
From: Gao, Zhichao @ 2019-03-27  1:21 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: edk2-devel@lists.01.org, Ard Biesheuvel, Gao, Liming, Sean Brogan,
	Michael Turner, Bret Barkelew

Thanks for your reply.
The variable "mVaListNull" I prefer to keep it as a module data even though there is only one source file in this DebugLib inf.

Thanks,
Zhichao

> -----Original Message-----
> From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> Sent: Tuesday, March 26, 2019 8:19 PM
> To: Gao, Zhichao <zhichao.gao@intel.com>
> Cc: edk2-devel@lists.01.org; Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> 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 V4 08/17] ArmPkg/SemiHostingDebugLib: Add new APIs
> 
> Hi Zhichao,
> 
> Apologies for delay in responding, due to holiday and stuff.
> 
> On the whole this looks fine (one comment below), but I don't actually have
> any platform on which to test this.
> 
> Ard: maybe it's time to retire this component?
> 
> On Thu, Mar 21, 2019 at 10:04:50PM +0800, Zhichao Gao wrote:
> > 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>
> > ---
> >  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;
> 
> I would prefer if this was marked STATIC.
> 
> If you feel strongly otherwise, leave it as is.
> Either way:
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
> 
> /
>     Leif
> 
> > +
> >  /**
> >
> >    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.16.2.windows.1
> >


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

* Re: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib
  2019-03-21 14:04 ` [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
  2019-03-22  2:09   ` Wu, Hao A
@ 2019-03-28  2:04   ` Gao, Liming
  2019-03-28  4:10     ` Gao, Zhichao
  1 sibling, 1 reply; 37+ messages in thread
From: Gao, Liming @ 2019-03-28  2:04 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Wu, Hao A, Ni, Ray, Zeng, Star, Sean Brogan,
	Michael Turner, Bret Barkelew

Zhichao:
   For new library instance, I have some comments. 

1) DebugPrint(). If DebugPpi is not found, directly return instead of CpuDeadLoop().
2) DebugAssert(). If DebugPpi is not found, bases on PcdDebugPropertyMask value to trig CpuDeadLoop() or CpuBreakPoint(). 
3) Please rename mDebugPpi as the specific prefix name to avoid the name confliction. 
4) What test is done for this library instance? 

Thanks
Liming
>-----Original Message-----
>From: Gao, Zhichao
>Sent: Thursday, March 21, 2019 10:05 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 V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
>debug lib
>
>From: Liming Gao <liming.gao@intel.com>
>
>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
>
>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>
>---
> .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456
>+++++++++++++++++++++
> .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
> 2 files changed, 511 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..75859163ae
>--- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
>+    Status = PeiServicesLocatePpi (
>+                &gEdkiiDebugPpiGuid,
>+                0,
>+                NULL,
>+                (VOID **)&mDebugPpi
>+                );
>+    if (EFI_ERROR (Status)) {
>+      CpuDeadLoop();
>+    }
>+  }
>+
>+  mDebugPpi->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 (mDebugPpi == NULL) {
>+    Status = PeiServicesLocatePpi (
>+                &gEdkiiDebugPpiGuid,
>+                0,
>+                NULL,
>+                (VOID **)&mDebugPpi
>+                );
>+    if (EFI_ERROR (Status)) {
>+      CpuDeadLoop();
>+    }
>+  }
>+
>+  mDebugPpi->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..4ab21e577e
>--- /dev/null
>+++
>b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
>@@ -0,0 +1,55 @@
>+## @file
>+#  Debug Lib instance through DebugServicePei for PEI phase
>+#
>+#  This module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check
>for FTW last write data has been done.
>+#
>+#  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.16.2.windows.1



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

* Re: [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
  2019-03-21 14:04 ` [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
  2019-03-22  2:00   ` Wu, Hao A
@ 2019-03-28  2:05   ` Gao, Liming
  1 sibling, 0 replies; 37+ messages in thread
From: Gao, Liming @ 2019-03-28  2:05 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Wang, Jian J, Wu, Hao A, Ni, Ray, Zeng, Star, Sean Brogan,
	Michael Turner, Bret Barkelew

Zhichao:
  One .c file is enough for this PEIM. You can implement all in one C file. 

Thanks
Liming
>-----Original Message-----
>From: Gao, Zhichao
>Sent: Thursday, March 21, 2019 10:05 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 V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI
>
>REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
>
>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>
>---
> .../Universal/DebugServicePei/DebugService.c       | 60
>++++++++++++++++++++++
> .../Universal/DebugServicePei/DebugService.h       | 56
>++++++++++++++++++++
> .../Universal/DebugServicePei/DebugServicePei.c    | 54
>+++++++++++++++++++
> .../Universal/DebugServicePei/DebugServicePei.inf  | 52
>+++++++++++++++++++
> .../Universal/DebugServicePei/DebugServicePei.uni  | 20 ++++++++
> 5 files changed, 242 insertions(+)
> create mode 100644
>MdeModulePkg/Universal/DebugServicePei/DebugService.c
> 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.c
>b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
>new file mode 100644
>index 0000000000..a9ea14db81
>--- /dev/null
>+++ b/MdeModulePkg/Universal/DebugServicePei/DebugService.c
>@@ -0,0 +1,60 @@
>+/** @file
>+  Debug services instances for PEI phase.
>+
>+  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 <Ppi/Debug.h>
>+#include <Library/DebugLib.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
>+  )
>+{
>+  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);
>+}
>+
>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..06117cfcf0
>--- /dev/null
>+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.c
>@@ -0,0 +1,54 @@
>+/** @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 "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
>+};
>+
>+/**
>+  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..e1252b658d
>--- /dev/null
>+++ b/MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf
>@@ -0,0 +1,52 @@
>+## @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.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.16.2.windows.1



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

* Re: [PATCH V4 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
  2019-03-21 14:04 ` [PATCH V4 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
@ 2019-03-28  2:07   ` Gao, Liming
  0 siblings, 0 replies; 37+ messages in thread
From: Gao, Liming @ 2019-03-28  2:07 UTC (permalink / raw)
  To: Gao, Zhichao, edk2-devel@lists.01.org
  Cc: Sean Brogan, Michael Turner, Bret Barkelew

Reviewed-by: Liming Gao <liming.gao@intel.com>

>-----Original Message-----
>From: Gao, Zhichao
>Sent: Thursday, March 21, 2019 10:05 PM
>To: edk2-devel@lists.01.org
>Cc: 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 V4 12/17]
>IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: Add new APIs
>
>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>
>---
> .../PeiDxeDebugLibReportStatusCode/DebugLib.c      | 173
>+++++++++++++++++----
> 1 file changed, 145 insertions(+), 28 deletions(-)
>
>diff --git
>a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/De
>bugLib.c
>b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/De
>bugLib.c
>index b0445115a9..7ae4edb40d 100644
>---
>a/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/De
>bugLib.c
>+++
>b/IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/De
>bugLib.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,25 +121,25 @@ 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);
>   }
>
>   //
>@@ -110,7 +152,7 @@ DebugPrint (
>   //
>   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.16.2.windows.1



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

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

Thanks for your comments. I will update base on 1, 2, 3.
I have tested on Nt32Pkg and OvmfPkg to replace the PEIM debug lib with the new one and add MdeModulePkg/Universal/DebugServicePei/DebugServicePei.inf with the original PEIM DebugLib to dsc and fdf file.
The PEIMs which use the DebugLib can output debug message fine.

Thanks,
Zhichao

> -----Original Message-----
> From: Gao, Liming
> Sent: Thursday, March 28, 2019 10:04 AM
> 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>;
> 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: RE: [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add
> PEI debug lib
> 
> Zhichao:
>    For new library instance, I have some comments.
> 
> 1) DebugPrint(). If DebugPpi is not found, directly return instead of
> CpuDeadLoop().
> 2) DebugAssert(). If DebugPpi is not found, bases on
> PcdDebugPropertyMask value to trig CpuDeadLoop() or CpuBreakPoint().
> 3) Please rename mDebugPpi as the specific prefix name to avoid the name
> confliction.
> 4) What test is done for this library instance?
> 
> Thanks
> Liming
> >-----Original Message-----
> >From: Gao, Zhichao
> >Sent: Thursday, March 21, 2019 10:05 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 V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI
> >debug lib
> >
> >From: Liming Gao <liming.gao@intel.com>
> >
> >REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1395
> >
> >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>
> >---
> > .../Library/PeiDebugLibDebugPpi/DebugLib.c         | 456
> >+++++++++++++++++++++
> > .../PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf    |  55 +++
> > 2 files changed, 511 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..75859163ae
> >--- /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             *mDebugPpi = 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 (mDebugPpi == NULL) {
> >+    Status = PeiServicesLocatePpi (
> >+                &gEdkiiDebugPpiGuid,
> >+                0,
> >+                NULL,
> >+                (VOID **)&mDebugPpi
> >+                );
> >+    if (EFI_ERROR (Status)) {
> >+      CpuDeadLoop();
> >+    }
> >+  }
> >+
> >+  mDebugPpi->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 (mDebugPpi == NULL) {
> >+    Status = PeiServicesLocatePpi (
> >+                &gEdkiiDebugPpiGuid,
> >+                0,
> >+                NULL,
> >+                (VOID **)&mDebugPpi
> >+                );
> >+    if (EFI_ERROR (Status)) {
> >+      CpuDeadLoop();
> >+    }
> >+  }
> >+
> >+  mDebugPpi->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..4ab21e577e
> >--- /dev/null
> >+++
> >b/MdeModulePkg/Library/PeiDebugLibDebugPpi/PeiDebugLibDebugPpi.inf
> >@@ -0,0 +1,55 @@
> >+## @file
> >+#  Debug Lib instance through DebugServicePei for PEI phase # #  This
> >+module installs gEdkiiFaultTolerantWriteGuid PPI to inform the check
> >for FTW last write data has been done.
> >+#
> >+#  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.16.2.windows.1



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

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

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-21 14:04 [PATCH V4 00/17] Add new APIs DebugVPrint for DebugLib Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 01/17] MdePkg/DebugLib.h: Add new APIs " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 02/17] MdePkg/BaseDebugLibNull: " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 03/17] MdePkg/BaseDebugLibSerialPort: Add new APIs Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 04/17] MdePkg/UefidebugLibConOut: " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 05/17] MdePkg/UefiDebugLibStdErr: " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 06/17] MdePkg/DxeRuntimeDebugLibSerialPort: " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 07/17] MdePkg/UefiDebuglibDebugPortProtocol: " Zhichao Gao
2019-03-21 14:04 ` [PATCH V4 08/17] ArmPkg/SemiHostingDebugLib: " Zhichao Gao
2019-03-26 12:19   ` Leif Lindholm
2019-03-26 12:43     ` Ard Biesheuvel
2019-03-27  1:21     ` Gao, Zhichao
2019-03-21 14:04 ` [PATCH V4 09/17] OvmfPkg/PlatformDebugLibIoPort: " Zhichao Gao
2019-03-21 18:58   ` Laszlo Ersek
2019-03-22  0:42     ` Gao, Zhichao
2019-03-21 14:04 ` [PATCH V4 10/17] IntelFsp2Pkg/BaseFspDebugLibSerialPort: " Zhichao Gao
2019-03-22  1:28   ` Chiu, Chasel
2019-03-22  7:08   ` Desimone, Nathaniel L
2019-03-21 14:04 ` [PATCH V4 11/17] IntelFspPkg/BaseFspDebugLibSerialPort: " Zhichao Gao
2019-03-22  1:28   ` Chiu, Chasel
2019-03-22  7:08   ` Desimone, Nathaniel L
2019-03-21 14:04 ` [PATCH V4 12/17] IntelFramworkModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
2019-03-28  2:07   ` Gao, Liming
2019-03-21 14:04 ` [PATCH V4 13/17] MdeModulePkg/PeiDxeDebugLibReportStatusCode: " Zhichao Gao
2019-03-22  1:50   ` Wu, Hao A
2019-03-21 14:04 ` [PATCH V4 14/17] MdeModulePkg: Add definitions for EDKII DEBUG PPI Zhichao Gao
2019-03-22  1:58   ` Wu, Hao A
2019-03-21 14:04 ` [PATCH V4 15/17] MdeModulePkg: Add a PEIM to install Debug PPI Zhichao Gao
2019-03-22  2:00   ` Wu, Hao A
2019-03-28  2:05   ` Gao, Liming
2019-03-21 14:04 ` [PATCH V4 16/17] MdeModulePkg/PeiDebugLibDebugPpi: Add PEI debug lib Zhichao Gao
2019-03-22  2:09   ` Wu, Hao A
2019-03-22  2:19     ` Gao, Zhichao
2019-03-22  2:31       ` Wu, Hao A
2019-03-28  2:04   ` Gao, Liming
2019-03-28  4:10     ` Gao, Zhichao
2019-03-21 14:04 ` [PATCH V4 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