Re: [edk2] How to using PcdGetEx to change a PCD.

2017-12-28 Thread krishnaLee


Hi,Liming and Andrew Fish,
I modified as your description,and move the pcd to [PcdEx] in inf file,but 
compile fail,the error is type-Mismatched,I understand now,so this pcd is not 
Ex-Pcd.
As  Andrew Fish said:"If different binaries that got compiled in different 
places need to work together then the Ex form is required."
Does it mean ,for example ,the bios_rom will finally contaion both Ex and 
non_Ex PCDs,and PCD_driver will publish the interface to access,so other module 
for exameple a efi_application access
Pcds can using PcdGetEx function to access pcds(type must be DynamicEx )?


I can't find a example for PcdGetEx in the EDK2 project,so I think the steps to 
using it as follow,right?
1,define a DynamicEx PCD in MdePkg.dec,format as follow,the follow 
token-number:0x00f1 ,just a unique number will work well ,yes?
[PcdsDynamicEx]  

gEfiMdePkgTokenSpaceGuid.myExPcdSample| 0xE000 |UINT64 | 0x00f1  

2,reference and modify it in Nt32Pkg.dsc as follow:
[PcdsDynamicEx]  
gEfiMdePkgTokenSpaceGuid.myExPcdSample| 0xD000  # value changed for the 
platform.


3,using the pcd in some drivers by PcdGetEx function,the driver can modifiy it 
in runtime ,the driver must build in Nt32Pkg.dsc, the driver must build in 
bios.fd.
3-1,add follow to driver-inf file:
[Guid]
gEfiMdePkgTokenSpaceGuid
[PcdEx]
 gEfiMdePkgTokenSpaceGuid.myExPcdSample
   3-2,add pcd-library to the driver-module and write code in source.c as 
follow:
#include //pcd need
#include //PcdToken
...
PcdGetEx64(,PcdToken(myExPcdSample));
  
PcdSetEx64(,PcdToken(myExPcdSample),some_value_changed);


4,using the pcd in uefi_Shell_application by PcdGetEx function,to check the 
runtime-value.the flow is same as driver.
//steps-end


//last build-error-message:
build...
d:\edk2-vudk2017\Nt32Pkg\Nt32Pkg.dsc(...): error 1002: Mismatched PCD type
gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut is defined as 
[DynamicEx] in module 
d:\edk2-vudk2017\Nt32Pkg\Application\mytestpcd2\mytestpcd2.inf, but as 
[DynamicHii] in platform.
Stop.




some edk2 mail has sorted  to a wrong group by me,so I haven't  see it for a 
long time,sorry to reply late.


thank you
by krishna

At 2017-12-14 22:55:00, "Gao, Liming"  wrote:
>PcdGet() is the recommended API to be used. It will be mapped to the matched 
>PcdGet usage based on PCD type.
>
>PcdGetEx() is only used when PCD is configured to DynamicEx type. Its first 
>parameter is the pointer to the token space guid, the second parameter is the 
>token number. The token number can be get by PcdToken() macro. So, the correct 
>way is PcdGetEx16(, PcdToken 
>(PcdPlatformBootTimeOut));. But PcdPlatformBootTimeOut is not configured to 
>DynamicEx PCD in NT32 platform. This style can pass build, but can't work. 
>
>Thanks
>Liming
>> -Original Message-
>> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of 
>> Andrew Fish
>> Sent: Thursday, December 14, 2017 6:27 PM
>> To: krishnaLee 
>> Cc: edk2-devel@lists.01.org
>> Subject: Re: [edk2] How to using PcdGetEx to change a PCD.
>> 
>> 
>> 
>> > On Dec 14, 2017, at 12:59 AM, krishnaLee  wrote:
>> >
>> > Hello,
>> > I am learning and writing a application to change the Nt32pkg-virtual 
>> > machine's boot time.follow code is success.
>> > but I think if I using PcdGetEx16 function, it will also work well,but 
>> > failed when I compile it.
>> > I had read some Specs about the difference between PcdGetEx and PcdGet,but 
>> > I can't understand,maybe I need some practice,
>> > So can anyone modify it to using PcdGetEx to implement the same function 
>> > in the application?
>> > //source-code--start
>> 
>> Did you add:
>> 
>> #include 
>> 
>> and list gEfiMdePkgTokenSpaceGuid in the [Guids] section of the INF.
>> 
>> In general it is hard to comment on compiler failures in fragments of code. 
>> If you post the actual compiler error it is easier to explain.
>> 
>> 
>> 
>> The PCDs are a GUID + token number namespace for config. Since anyone can 
>> define a GUID that does not conflict it allows arbitrary
>> extension without conflict.
>> 
>> The Ex form of the API includes the GUID + token number. The non Ex form is 
>> a size optimization that uses a build generated token
>> space. So generally if everything is built together then you use the non Ex 
>> form to save space. If different binaries that got compiled in
>> different places need to work together then the Ex form is required.
>> 
>> Thanks,
>> 
>> Andrew Fish
>> 
>> > EFI_STATUS
>> > EFIAPI
>> > UefiMain (
>> > IN EFI_HANDLE ImageHandle,
>> > IN EFI_SYSTEM_TABLE *SystemTable
>> > )
>> > {
>> > UINTN buffer=0;
>> > UINTN index;
>> > buffer=PcdGet16(PcdPlatformBootTimeOut);
>> > //buffer=PcdGetEx16(,PcdPlatformBootTimeOut);//compile
>> >  failed.
>> > Print(L"buffer:%d\n",buffer);
>> > PcdSet16(PcdPlatformBootTimeOut,5);
>> > ...
>> >
>> >
>> > //source-code-end.
>> >
>> >
>> > attachment is the 

[edk2] [PATCH edk2-platforms] Platform/Socionext/SynQuacerEvalBoard: add ACPI support

2017-12-28 Thread Ard Biesheuvel
Enable ACPI support for the SynQuacerEvalBoard platform: add descriptions
of the CPUs, the GIC, the serial port, the timers and the second PCIe RC,
including the MSI routing via the GICv3 ITS. Also add descriptions of the
ethernet and MMC platform devices.

Note that PCIe support is limited to the RC that is connected to the M.2
slot, and only supports MMIO BARs and only a single bus. This is all we
can support on the non-ECAM compliant root complex implementation, and
also works around the lack of ACPI support for the pre-ITS. However, it
should be sufficient for running the EVB with a NVME SSD installed.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel 
---
 Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc |  18 ++
 Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf |  13 ++
 Silicon/Socionext/SynQuacer/AcpiTables/AcpiSsdtRootPci.asl   | 127 
+
 Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.h  |  73 
 Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.inf|  64 +++
 Silicon/Socionext/SynQuacer/AcpiTables/Dsdt.asl  | 191 

 Silicon/Socionext/SynQuacer/AcpiTables/Fadt.aslc |  91 ++
 Silicon/Socionext/SynQuacer/AcpiTables/Gtdt.aslc |  93 ++
 Silicon/Socionext/SynQuacer/AcpiTables/Iort.aslc |  96 ++
 Silicon/Socionext/SynQuacer/AcpiTables/Madt.aslc | 182 
+++
 Silicon/Socionext/SynQuacer/AcpiTables/Mcfg.aslc |  55 ++
 Silicon/Socionext/SynQuacer/AcpiTables/Spcr.aslc | 128 
+
 12 files changed, 1131 insertions(+)

diff --git a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc 
b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc
index 1e6beb489048..4c2193724b83 100644
--- a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc
+++ b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.dsc
@@ -219,7 +219,15 @@ [PcdsFeatureFlag]
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleReset|TRUE
 
+  gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE
+
 [PcdsFixedAtBuild.common]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId|"SNI   "
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId|0x52434155514e5953 # 
SYNQUACR
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision|0x20171228
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId|0x4f524e4c # LNRO
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision|1
+
 !ifdef $(FIRMWARE_VENDOR)
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor|L"$(FIRMWARE_VENDOR)"
 !endif
@@ -637,3 +645,13 @@ [Components.common]
   SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
   SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf
 
+  #
+  # ACPI support
+  #
+  MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf {
+
+  # support ACPI v5.0 or later
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20
+  }
+  MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf
+  Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.inf
diff --git a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf 
b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf
index bd980548e7bb..dfadc96018c7 100644
--- a/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf
+++ b/Platform/Socionext/SynQuacerEvalBoard/SynQuacerEvalBoard.fdf
@@ -233,6 +233,13 @@ [FV.FvMain]
  SECTION UI = "Pkcs7TestRoot"
   }
 
+  #
+  # ACPI support
+  #
+  INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
+  INF MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf
+  INF RuleOverride = ACPITABLE 
Silicon/Socionext/SynQuacer/AcpiTables/AcpiTables.inf
+
 !if $(DO_X86EMU) == TRUE
   #
   # x86 emulator
@@ -462,3 +469,9 @@ [Rule.Common.PEIM.FMP_IMAGE_DESC]
  UI   STRING="$(MODULE_NAME)" Optional
  VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
   }
+
+[Rule.Common.USER_DEFINED.ACPITABLE]
+  FILE FREEFORM = $(NAMED_GUID) {
+RAW ACPI   |.acpi
+RAW ASL|.aml
+  }
diff --git a/Silicon/Socionext/SynQuacer/AcpiTables/AcpiSsdtRootPci.asl 
b/Silicon/Socionext/SynQuacer/AcpiTables/AcpiSsdtRootPci.asl
new file mode 100644
index ..966acbc6adbd
--- /dev/null
+++ b/Silicon/Socionext/SynQuacer/AcpiTables/AcpiSsdtRootPci.asl
@@ -0,0 +1,127 @@
+/** @file
+  Secondary System Description Table (SSDT) for SynQuacer PCIe RCs
+
+  Copyright (c) 2014-2016, ARM Ltd. All rights reserved.
+  Copyright (c) 2017, Linaro Ltd. All rights reserved.
+
+  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
+  

Re: [edk2] [PATCH] BaseTools/tools_def XCODE5: Add -Wno-varargs

2017-12-28 Thread Alex James
Disregard this patch if Zenith432's patch to fix this bug is accepted.

On Thu, Dec 28, 2017 at 12:04 PM Alex James 
wrote:

> Commit 47bfbd7f8069e523798ef973c8eb0abd5c6b0746 ("BaseTools/Conf:
> Support LLVM39 and LLVM40 in CLANG38 toolchain") added -Wno-varargs to
> suppress va_start errors when building MdePkg/UefiLib. Do the same for
> the XCODE5 toolchain to fix building with Xcode 9 as per
> https://bugzilla.tianocore.org/show_bug.cgi?id=741.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Alex James 
> ---
>  BaseTools/Conf/tools_def.template | 12 ++--
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/BaseTools/Conf/tools_def.template
> b/BaseTools/Conf/tools_def.template
> index 98ab6dd45e..12278302b3 100755
> --- a/BaseTools/Conf/tools_def.template
> +++ b/BaseTools/Conf/tools_def.template
> @@ -7550,9 +7550,9 @@ RELEASE_XCODE5_IA32_ASM_FLAGS  = -arch i386
>*_XCODE5_IA32_NASM_FLAGS = -f macho32
>
>
> -  DEBUG_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -Os   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
> -RELEASE_XCODE5_IA32_CC_FLAGS   = -arch i386 -c-Os   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
> -  NOOPT_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -O0   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
> +  DEBUG_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -Os   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -Wno-varargs
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
> +RELEASE_XCODE5_IA32_CC_FLAGS   = -arch i386 -c-Os   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -Wno-varargs
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
> +  NOOPT_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -O0   -Wall -Werror
> -include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin
> -fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float
> -mms-bitfields -msoft-float -Wno-unused-parameter -Wno-missing-braces
> -Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare
> -Wno-varargs
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang
> $(PLATFORM_FLAGS)
>
>  ##
>  # X64 definitions
> @@ -7569,9 +7569,9 @@ RELEASE_XCODE5_X64_ASM_FLAGS  = -arch x86_64
>  *_XCODE5_*_PP_FLAGS = -E -x assembler-with-cpp -include
> $(DEST_DIR_DEBUG)/AutoGen.h
>  *_XCODE5_*_VFRPP_FLAGS  = -x c -E -P -DVFRCOMPILE -include
> $(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h
>
> -  DEBUG_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c -g -Os
>  -Wall -Werror -Wextra -include AutoGen.h -funsigned-char
> -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar
> -mno-implicit-float -mms-bitfields -Wno-unused-parameter
> -Wno-missing-braces -Wno-missing-field-initializers
> -Wno-tautological-compare -Wno-sign-compare
> -ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -D
> NO_MSABI_VA_FUNCS $(PLATFORM_FLAGS)
> -  NOOPT_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c -g -O0
>  -Wall -Werror -Wextra -include AutoGen.h -funsigned-char
> -fno-ms-extensions -fno-stack-protector -fno-builtin -fshort-wchar
> -mno-implicit-float -mms-bitfields -Wno-unused-parameter
> -Wno-missing-braces -Wno-missing-field-initializers
> -Wno-tautological-compare -Wno-sign-compare
> 

[edk2] [PATCH] BaseTools/PcdValueCommon: Fix PcdDataTypeUint64 format string

2017-12-28 Thread Alex James
Always specify unsigned long long for PcdDataTypeUint64. This is needed
to fix building with XCODE5.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Alex James 
---
 BaseTools/Source/C/Common/PcdValueCommon.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c 
b/BaseTools/Source/C/Common/PcdValueCommon.c
index 6ca0994744..f5d68e79e0 100644
--- a/BaseTools/Source/C/Common/PcdValueCommon.c
+++ b/BaseTools/Source/C/Common/PcdValueCommon.c
@@ -266,11 +266,7 @@ Returns:
 sprintf(PcdList[Index].Value, "0x%08x", (UINT32)(Value & 0x));
 break;
   case PcdDataTypeUint64:
-#ifdef __GNUC__
-sprintf(PcdList[Index].Value, "0x%016lx", Value);
-#else
 sprintf(PcdList[Index].Value, "0x%016llx", Value);
-#endif
 break;
   case PcdDataTypePointer:
 fprintf (stderr, "PCD %s.%s.%s.%s is structure.  Use PcdSetPtr()\n", 
SkuName, DefaultValueName, TokenSpaceGuidName, TokenName);
-- 
2.15.1

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


[edk2] [PATCH] BaseTools/tools_def XCODE5: Add -Wno-varargs

2017-12-28 Thread Alex James
Commit 47bfbd7f8069e523798ef973c8eb0abd5c6b0746 ("BaseTools/Conf:
Support LLVM39 and LLVM40 in CLANG38 toolchain") added -Wno-varargs to
suppress va_start errors when building MdePkg/UefiLib. Do the same for
the XCODE5 toolchain to fix building with Xcode 9 as per
https://bugzilla.tianocore.org/show_bug.cgi?id=741.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Alex James 
---
 BaseTools/Conf/tools_def.template | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Conf/tools_def.template 
b/BaseTools/Conf/tools_def.template
index 98ab6dd45e..12278302b3 100755
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -7550,9 +7550,9 @@ RELEASE_XCODE5_IA32_ASM_FLAGS  = -arch i386
   *_XCODE5_IA32_NASM_FLAGS = -f macho32
 
 
-  DEBUG_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -Os   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
-RELEASE_XCODE5_IA32_CC_FLAGS   = -arch i386 -c-Os   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
-  NOOPT_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -O0   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
+  DEBUG_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -Os   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-Wno-varargs 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
+RELEASE_XCODE5_IA32_CC_FLAGS   = -arch i386 -c-Os   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-Wno-varargs 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
+  NOOPT_XCODE5_IA32_CC_FLAGS   = -arch i386 -c -g -O0   -Wall -Werror 
-include AutoGen.h -funsigned-char -fno-stack-protector -fno-builtin 
-fshort-wchar -fasm-blocks -mdynamic-no-pic -mno-implicit-float -mms-bitfields 
-msoft-float -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-Wno-varargs 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang 
$(PLATFORM_FLAGS)
 
 ##
 # X64 definitions
@@ -7569,9 +7569,9 @@ RELEASE_XCODE5_X64_ASM_FLAGS  = -arch x86_64
 *_XCODE5_*_PP_FLAGS = -E -x assembler-with-cpp -include 
$(DEST_DIR_DEBUG)/AutoGen.h 
 *_XCODE5_*_VFRPP_FLAGS  = -x c -E -P -DVFRCOMPILE -include 
$(DEST_DIR_DEBUG)/$(MODULE_NAME)StrDefs.h 
 
-  DEBUG_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c -g -Os   
-Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions 
-fno-stack-protector -fno-builtin -fshort-wchar -mno-implicit-float 
-mms-bitfields -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -D 
NO_MSABI_VA_FUNCS $(PLATFORM_FLAGS)
-  NOOPT_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c -g -O0   
-Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions 
-fno-stack-protector -fno-builtin -fshort-wchar -mno-implicit-float 
-mms-bitfields -Wno-unused-parameter -Wno-missing-braces 
-Wno-missing-field-initializers -Wno-tautological-compare -Wno-sign-compare 
-ftrap-function=undefined_behavior_has_been_optimized_away_by_clang -D 
NO_MSABI_VA_FUNCS $(PLATFORM_FLAGS)
-RELEASE_XCODE5_X64_CC_FLAGS   = -target x86_64-pc-win32-macho -c-Os   
-Wall -Werror -Wextra -include AutoGen.h -funsigned-char -fno-ms-extensions 
-fno-stack-protector 

[edk2] [Patch] BaseTools: Fix the bug for QuarkPlatformPkg build failure

2017-12-28 Thread Yonghong Zhu
The issue is that the string 'LPC' starts with the 'L' character and
this is being confused with L" or L' for a Unicode string or Unicode
character.

Fixes:https://bugzilla.tianocore.org/show_bug.cgi?id=831
Cc: Liming Gao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yonghong Zhu 
---
 BaseTools/Source/Python/Common/Expression.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py 
b/BaseTools/Source/Python/Common/Expression.py
index 953a412..55fa06d 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -162,11 +162,11 @@ class ValueExpression(object):
 if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or 
Oprand1.startswith("L'")or Oprand1.startswith('UINT'):
 Oprand1, Size = ParseFieldValue(Oprand1)
 else:
 Oprand1,Size = ParseFieldValue('"' + Oprand1 + '"')
 if type(Oprand2) == type(''):
-if Oprand2[0] in ['"', "'", 'L'] or Oprand2.startswith('UINT'):
+if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or 
Oprand2.startswith("L'") or Oprand2.startswith('UINT'):
 Oprand2, Size = ParseFieldValue(Oprand2)
 else:
 Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"')
 if type(Oprand1) == type('') or type(Oprand2) == type(''):
 raise BadExpression(ERR_STRING_EXPR % Operator)
-- 
2.6.1.windows.1

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


[edk2] [Patch] MdeModulePkg DxePrintLibPrint2Protocol: Fix GCC5 build failure

2017-12-28 Thread Liming Gao
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Liming Gao 
Cc: Eric Dong 
---
 MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c 
b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
index 570d06d82e..0e6178fc9c 100644
--- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
+++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
@@ -2052,7 +2052,7 @@ InternalPrintLibSPrintMarker (
   //
   for (Count = 0;
 ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
-Count < Precision || ((Flags & PRECISION) == 0);
+(Count < Precision || ((Flags & PRECISION) == 0));
 Count++) {
 ArgumentCharacter = ((ArgumentString[Count * 
BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * 
BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
 if (ArgumentCharacter == 0) {
-- 
2.11.0.windows.1

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


Re: [edk2] [PATCH] MdeModulePkg/DxePrintLibPrint2Protocol: fix GCC5 build break

2017-12-28 Thread Gao, Liming
Reviewed-by: Liming Gao 

>-Original Message-
>From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jian
>J Wang
>Sent: Friday, December 29, 2017 9:40 AM
>To: edk2-devel@lists.01.org
>Cc: Kinney, Michael D ; Dong, Eric
>; Zeng, Star 
>Subject: [edk2] [PATCH] MdeModulePkg/DxePrintLibPrint2Protocol: fix GCC5
>build break
>
>Cc: Star Zeng 
>Cc: Eric Dong 
>Cc: Michael Kinney 
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Jian J Wang 
>---
> MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
>b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
>index 570d06d82e..0e6178fc9c 100644
>--- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
>+++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
>@@ -2052,7 +2052,7 @@ InternalPrintLibSPrintMarker (
>   //
>   for (Count = 0;
> ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
>-Count < Precision || ((Flags & PRECISION) == 0);
>+(Count < Precision || ((Flags & PRECISION) == 0));
> Count++) {
> ArgumentCharacter = ((ArgumentString[Count *
>BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count *
>BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
> if (ArgumentCharacter == 0) {
>--
>2.15.1.windows.2
>
>___
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 0/2] Fix error in PrintLib

2017-12-28 Thread Wang, Jian J
Mike,

Thanks for catching it. The patch has sent out.

Regards,
Jian


> -Original Message-
> From: Kinney, Michael D
> Sent: Friday, December 29, 2017 9:08 AM
> To: Wang, Jian J ; edk2-devel@lists.01.org; Kinney,
> Michael D 
> Subject: RE: [edk2] [PATCH v2 0/2] Fix error in PrintLib
> 
> Jian,
> 
> This change breaks GCC5 builds.
> 
> /home/mdkinney/tianocore/edk2/MdeModulePkg/Library/DxePrintLibPrint2Pro
> tocol/PrintLib.c: In function 'InternalPrintLibSPrintMarker':
> /home/mdkinney/tianocore/edk2/MdeModulePkg/Library/DxePrintLibPrint2Pro
> tocol/PrintLib.c:2054:71: error: suggest parentheses around '&&' within '||' 
> [-
> Werror=parentheses]
>  ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
> 
> ~~^~~
>  Count < Precision || ((Flags & PRECISION) == 0);
>  ~
> 
> Mike
> 
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-
> > boun...@lists.01.org] On Behalf Of Jian J Wang
> > Sent: Wednesday, December 27, 2017 6:38 PM
> > To: edk2-devel@lists.01.org
> > Subject: [edk2] [PATCH v2 0/2] Fix error in PrintLib
> >
> > > v2:
> > >a. Correct incorrect description in commit log
> > >b. Fix another similar issue in the same function
> > >c. Fix similar issues in
> > MdeModulePkg/DxePrintLibPrint2Protocol
> >
> > Due to a potential hole in the stop condition of the
> > loop, the two continuous
> > access to ArgumentString (index, index+1) inside the
> > loop might cause the
> > string ending character ('\0') and the byte after it to
> > be read.
> >
> > Jian J Wang (2):
> >   MdePkg/BasePrintLib: Fix error in Precision position
> > calculation
> >   MdeModulePkg/DxePrintLibPrint2Protocol: Fix potential
> > string over read
> >
> >
> > MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib
> > .c | 7 +--
> >  MdePkg/Library/BasePrintLib/PrintLibInternal.c
> > | 7 +--
> >  2 files changed, 10 insertions(+), 4 deletions(-)
> >
> > --
> > 2.15.1.windows.2
> >
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH] MdeModulePkg/DxePrintLibPrint2Protocol: fix GCC5 build break

2017-12-28 Thread Dong, Eric
Reviewed-by: Eric Dong 

-Original Message-
From: Wang, Jian J 
Sent: Friday, December 29, 2017 9:40 AM
To: edk2-devel@lists.01.org
Cc: Zeng, Star ; Dong, Eric ; Kinney, 
Michael D 
Subject: [PATCH] MdeModulePkg/DxePrintLibPrint2Protocol: fix GCC5 build break

Cc: Star Zeng 
Cc: Eric Dong 
Cc: Michael Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c 
b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
index 570d06d82e..0e6178fc9c 100644
--- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
+++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
@@ -2052,7 +2052,7 @@ InternalPrintLibSPrintMarker (
   //
   for (Count = 0;
 ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
-Count < Precision || ((Flags & PRECISION) == 0);
+(Count < Precision || ((Flags & PRECISION) == 0));
 Count++) {
 ArgumentCharacter = ((ArgumentString[Count * 
BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * 
BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
 if (ArgumentCharacter == 0) {
-- 
2.15.1.windows.2

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


Re: [edk2] [Patch] BaseTools: Fix a bug for different FV use same FILE statement Guid

2017-12-28 Thread Gao, Liming
Reviewed-by: Liming Gao 

>-Original Message-
>From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
>Yonghong Zhu
>Sent: Friday, December 29, 2017 1:41 AM
>To: edk2-devel@lists.01.org
>Subject: [edk2] [Patch] BaseTools: Fix a bug for different FV use same FILE
>statement Guid
>
>We meet a case that different FV use same FILE statement Guid, but the
>FILE content is different. current we use the Guid value as Ffs file
>dir which cause the ffs file will be override. This patch use Guid
>value and Fv name as ffs dir for FILE statement.
>
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Yonghong Zhu 
>---
> BaseTools/Source/Python/GenFds/FfsFileStatement.py | 7 +--
> BaseTools/Source/Python/GenFds/FfsInfStatement.py  | 2 +-
> BaseTools/Source/Python/GenFds/Fv.py   | 2 +-
> 3 files changed, 7 insertions(+), 4 deletions(-)
>
>diff --git a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
>b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
>index edb1312..12ec95b 100644
>--- a/BaseTools/Source/Python/GenFds/FfsFileStatement.py
>+++ b/BaseTools/Source/Python/GenFds/FfsFileStatement.py
>@@ -55,11 +55,11 @@ class FileStatement (FileStatementClassObject) :
> #   @param  Dict dictionary contains macro and value pair
> #   @param  FvChildAddr  Array of the inside FvImage base address
> #   @param  FvParentAddr Parent Fv base address
> #   @retval string   Generated FFS file name
> #
>-def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None,
>IsMakefile=False):
>+def GenFfs(self, Dict = {}, FvChildAddr=[], FvParentAddr=None,
>IsMakefile=False, FvName=None):
>
> if self.NameGuid != None and self.NameGuid.startswith('PCD('):
> PcdValue = GenFdsGlobalVariable.GetPcdValue(self.NameGuid)
> if len(PcdValue) == 0:
> EdkLogger.error("GenFds", GENFDS_ERROR, '%s NOT defined.' \
>@@ -70,11 +70,14 @@ class FileStatement (FileStatementClassObject) :
> if len(RegistryGuidStr) == 0:
> EdkLogger.error("GenFds", GENFDS_ERROR, 'GUID value for %s in
>wrong format.' \
> % (self.NameGuid))
> self.NameGuid = RegistryGuidStr
>
>-OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, self.NameGuid)
>+Str = self.NameGuid
>+if FvName:
>+Str += FvName
>+OutputDir = os.path.join(GenFdsGlobalVariable.FfsDir, Str)
> if not os.path.exists(OutputDir):
> os.makedirs(OutputDir)
>
> Dict.update(self.DefineVarDict)
> SectionAlignments = None
>diff --git a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
>b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
>index 4b47817..baee543 100644
>--- a/BaseTools/Source/Python/GenFds/FfsInfStatement.py
>+++ b/BaseTools/Source/Python/GenFds/FfsInfStatement.py
>@@ -420,11 +420,11 @@ class FfsInfStatement(FfsInfStatementClassObject):
> #   @param  Dict dictionary contains macro and value pair
> #   @param  FvChildAddr  Array of the inside FvImage base address
> #   @param  FvParentAddr Parent Fv base address
> #   @retval string   Generated FFS file name
> #
>-def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None,
>IsMakefile=False):
>+def GenFfs(self, Dict = {}, FvChildAddr = [], FvParentAddr=None,
>IsMakefile=False, FvName=None):
> #
> # Parse Inf file get Module related information
> #
>
> self.__InfParse__(Dict)
>diff --git a/BaseTools/Source/Python/GenFds/Fv.py
>b/BaseTools/Source/Python/GenFds/Fv.py
>index d5922c0..a69abb3 100644
>--- a/BaseTools/Source/Python/GenFds/Fv.py
>+++ b/BaseTools/Source/Python/GenFds/Fv.py
>@@ -119,11 +119,11 @@ class FV (FvClassObject):
> if Flag:
> if isinstance(FfsFile, FfsFileStatement.FileStatement):
> continue
> if GenFdsGlobalVariable.EnableGenfdsMultiThread and
>GenFdsGlobalVariable.ModuleFile and
>GenFdsGlobalVariable.ModuleFile.Path.find(os.path.normpath(FfsFile.InfFile
>Name)) == -1:
> continue
>-FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress,
>IsMakefile=Flag)
>+FileName = FfsFile.GenFfs(MacroDict, FvParentAddr=BaseAddress,
>IsMakefile=Flag, FvName=self.UiFvName)
> FfsFileList.append(FileName)
> if not Flag:
> self.FvInfFile.writelines("EFI_FILE_NAME = " + \
> FileName  + \
> T_CHAR_LF)
>--
>2.6.1.windows.1
>
>___
>edk2-devel mailing list
>edk2-devel@lists.01.org
>https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Re: [edk2] [PATCH] BaseTools/PcdValueCommon: Fix PcdDataTypeUint64 format string

2017-12-28 Thread Alex James
Hi Liming,

I was able to reproduce this, will send out the v2 patch shortly.

Thanks,
Alex

On Thu, Dec 28, 2017 at 7:46 PM Gao, Liming  wrote:

> This fix will trig GCC build warning.
>
> PcdValueCommon.c: In function '__PcdSet':
> PcdValueCommon.c:269:35: error: format '%llx' expects argument of type
> 'long long unsigned int', but argument 3 has type 'UINT64 {aka long
> unsigned int}' [-Werror=format=]
>  sprintf(PcdList[Index].Value, "0x%016llx", Value);
>^
>
> Thanks
> Liming
> > -Original Message-
> > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of
> Alex James
> > Sent: Friday, December 29, 2017 4:00 AM
> > To: edk2-devel@lists.01.org
> > Cc: Alex James 
> > Subject: [edk2] [PATCH] BaseTools/PcdValueCommon: Fix PcdDataTypeUint64
> format string
> >
> > Always specify unsigned long long for PcdDataTypeUint64. This is needed
> > to fix building with XCODE5.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Alex James 
> > ---
> >  BaseTools/Source/C/Common/PcdValueCommon.c | 4 
> >  1 file changed, 4 deletions(-)
> >
> > diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c
> b/BaseTools/Source/C/Common/PcdValueCommon.c
> > index 6ca0994744..f5d68e79e0 100644
> > --- a/BaseTools/Source/C/Common/PcdValueCommon.c
> > +++ b/BaseTools/Source/C/Common/PcdValueCommon.c
> > @@ -266,11 +266,7 @@ Returns:
> >  sprintf(PcdList[Index].Value, "0x%08x", (UINT32)(Value &
> 0x));
> >  break;
> >case PcdDataTypeUint64:
> > -#ifdef __GNUC__
> > -sprintf(PcdList[Index].Value, "0x%016lx", Value);
> > -#else
> >  sprintf(PcdList[Index].Value, "0x%016llx", Value);
> > -#endif
> >  break;
> >case PcdDataTypePointer:
> >  fprintf (stderr, "PCD %s.%s.%s.%s is structure.  Use
> PcdSetPtr()\n", SkuName, DefaultValueName, TokenSpaceGuidName,
> > TokenName);
> > --
> > 2.15.1
> >
> > ___
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
>
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [PATCH v2] BaseTools/PcdValueCommon: Fix build with XCODE5

2017-12-28 Thread Alex James
Use the correct UINT64 format specifier when building on macOS. This is
needed to fix building with XCODE5.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Alex James 
---

Notes:
v2:
- Change ifdef to fix GCC build failure [Liming]

 BaseTools/Source/C/Common/PcdValueCommon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c 
b/BaseTools/Source/C/Common/PcdValueCommon.c
index 6ca0994744..1b7b48c125 100644
--- a/BaseTools/Source/C/Common/PcdValueCommon.c
+++ b/BaseTools/Source/C/Common/PcdValueCommon.c
@@ -266,7 +266,7 @@ Returns:
 sprintf(PcdList[Index].Value, "0x%08x", (UINT32)(Value & 0x));
 break;
   case PcdDataTypeUint64:
-#ifdef __GNUC__
+#if defined(__GNUC__) && !defined(__APPLE__)
 sprintf(PcdList[Index].Value, "0x%016lx", Value);
 #else
 sprintf(PcdList[Index].Value, "0x%016llx", Value);
-- 
2.15.1

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


[edk2] [PATCH] MdeModulePkg/DxePrintLibPrint2Protocol: fix GCC5 build break

2017-12-28 Thread Jian J Wang
Cc: Star Zeng 
Cc: Eric Dong 
Cc: Michael Kinney 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang 
---
 MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c 
b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
index 570d06d82e..0e6178fc9c 100644
--- a/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
+++ b/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c
@@ -2052,7 +2052,7 @@ InternalPrintLibSPrintMarker (
   //
   for (Count = 0;
 ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
-Count < Precision || ((Flags & PRECISION) == 0);
+(Count < Precision || ((Flags & PRECISION) == 0));
 Count++) {
 ArgumentCharacter = ((ArgumentString[Count * 
BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * 
BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
 if (ArgumentCharacter == 0) {
-- 
2.15.1.windows.2

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


Re: [edk2] [Patch] BaseTools: Fix the bug for QuarkPlatformPkg build failure

2017-12-28 Thread Gao, Liming
Reviewed-by: Liming Gao 

>-Original Message-
>From: Zhu, Yonghong
>Sent: Friday, December 29, 2017 8:28 AM
>To: edk2-devel@lists.01.org
>Cc: Gao, Liming 
>Subject: [Patch] BaseTools: Fix the bug for QuarkPlatformPkg build failure
>
>The issue is that the string 'LPC' starts with the 'L' character and
>this is being confused with L" or L' for a Unicode string or Unicode
>character.
>
>Fixes:https://bugzilla.tianocore.org/show_bug.cgi?id=831
>Cc: Liming Gao 
>Contributed-under: TianoCore Contribution Agreement 1.1
>Signed-off-by: Yonghong Zhu 
>---
> BaseTools/Source/Python/Common/Expression.py | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/BaseTools/Source/Python/Common/Expression.py
>b/BaseTools/Source/Python/Common/Expression.py
>index 953a412..55fa06d 100644
>--- a/BaseTools/Source/Python/Common/Expression.py
>+++ b/BaseTools/Source/Python/Common/Expression.py
>@@ -162,11 +162,11 @@ class ValueExpression(object):
> if Oprand1[0] in ['"', "'"] or Oprand1.startswith('L"') or
>Oprand1.startswith("L'")or Oprand1.startswith('UINT'):
> Oprand1, Size = ParseFieldValue(Oprand1)
> else:
> Oprand1,Size = ParseFieldValue('"' + Oprand1 + '"')
> if type(Oprand2) == type(''):
>-if Oprand2[0] in ['"', "'", 'L'] or 
>Oprand2.startswith('UINT'):
>+if Oprand2[0] in ['"', "'"] or Oprand2.startswith('L"') or
>Oprand2.startswith("L'") or Oprand2.startswith('UINT'):
> Oprand2, Size = ParseFieldValue(Oprand2)
> else:
> Oprand2, Size = ParseFieldValue('"' + Oprand2 + '"')
> if type(Oprand1) == type('') or type(Oprand2) == type(''):
> raise BadExpression(ERR_STRING_EXPR % Operator)
>--
>2.6.1.windows.1

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


[edk2] [RFC v4 0/6] Stack trace support in X64 exception handling

2017-12-28 Thread Paulo Alcantara
Hi,

This series adds stack trace support during IA32 and X64 CPU exceptions.

Informations like back trace, stack contents and image module names
(that were part of the call stack) will be dumped out.

The current limitation is that it relies on available frame pointers
(GCC only) in order to successfully unwind the stack.

(Sorry for the very long delay - I was very busy working on something
 else and then went to vacations)

Jiewen,

I have tested it with VS2015x86 and the stack trace just hanged when
printing out the first EIP (that is, no frame pointer at all).

Thanks!
Paulo

Repo:   https://github.com/pcacjr/edk2.git
Branch: stacktrace_v4

Cc: Rick Bramley 
Cc: Andrew Fish 
Cc: Eric Dong 
Cc: Laszlo Ersek 
Cc: Brian Johnson 
Cc: Jeff Fan 
Cc: Jiewen Yao 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Paulo Alcantara 
---

v1 -> v2:
  * Add IA32 arch support (GCC toolchain only)
  * Replace hard-coded stack alignment value (16) with
CPU_STACK_ALIGNMENT.
  * Check for proper stack and frame pointer alignments.
  * Fix initialization of UnwoundStacksCount to 1.
  * Move GetPdbFileName() to common code since it will be used by both
IA32 and X64 implementations.

v2 -> v3:
  * Fixed wrong assumption about "RIP < ImageBase" to start searching
for another PE/COFF image. That is, RIP may point to lower and
higher addresses for any other PE/COFF images. Both IA32 & X64.
(Thanks Andrew & Jiewen)
  * Fixed typo: unwond -> unwound. Both IA32 & X64. (Thanks Brian)

v3 -> v4:
  * Validate all frame/stack pointer addresses before dereferencing them
as requested by Brian & Jiewen.
  * Correctly print out IP addresses during the stack traces (by Jeff)

Paulo Alcantara (6):
  UefiCpuPkg/CpuExceptionHandlerLib/X64: Add stack trace support
  UefiCpuPkg/CpuExceptionHandlerLib: Export GetPdbFileName()
  UefiCpuPkg/CpuExceptionHandlerLib/Ia32: Add stack trace support
  UefiCpuPkg/CpuExceptionHandlerLib: Add helper to valid memory
addresses
  UefiCpuPkg/CpuExceptionHandlerLib: Ensure valid frame/stack pointers
  UefiCpuPkg/CpuExceptionHandlerLib: Correctly print IP addresses

 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c| 484 
++--
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h|  41 +-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c | 445 
+-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  | 384 
+++-
 4 files changed, 1296 insertions(+), 58 deletions(-)

-- 
2.14.3

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


Re: [edk2] [PATCH] BaseTools/PcdValueCommon: Fix PcdDataTypeUint64 format string

2017-12-28 Thread Gao, Liming
This fix will trig GCC build warning. 

PcdValueCommon.c: In function '__PcdSet':
PcdValueCommon.c:269:35: error: format '%llx' expects argument of type 'long 
long unsigned int', but argument 3 has type 'UINT64 {aka long unsigned int}' 
[-Werror=format=]
 sprintf(PcdList[Index].Value, "0x%016llx", Value);
   ^

Thanks
Liming
> -Original Message-
> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Alex 
> James
> Sent: Friday, December 29, 2017 4:00 AM
> To: edk2-devel@lists.01.org
> Cc: Alex James 
> Subject: [edk2] [PATCH] BaseTools/PcdValueCommon: Fix PcdDataTypeUint64 
> format string
> 
> Always specify unsigned long long for PcdDataTypeUint64. This is needed
> to fix building with XCODE5.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Alex James 
> ---
>  BaseTools/Source/C/Common/PcdValueCommon.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/BaseTools/Source/C/Common/PcdValueCommon.c 
> b/BaseTools/Source/C/Common/PcdValueCommon.c
> index 6ca0994744..f5d68e79e0 100644
> --- a/BaseTools/Source/C/Common/PcdValueCommon.c
> +++ b/BaseTools/Source/C/Common/PcdValueCommon.c
> @@ -266,11 +266,7 @@ Returns:
>  sprintf(PcdList[Index].Value, "0x%08x", (UINT32)(Value & 0x));
>  break;
>case PcdDataTypeUint64:
> -#ifdef __GNUC__
> -sprintf(PcdList[Index].Value, "0x%016lx", Value);
> -#else
>  sprintf(PcdList[Index].Value, "0x%016llx", Value);
> -#endif
>  break;
>case PcdDataTypePointer:
>  fprintf (stderr, "PCD %s.%s.%s.%s is structure.  Use PcdSetPtr()\n", 
> SkuName, DefaultValueName, TokenSpaceGuidName,
> TokenName);
> --
> 2.15.1
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


Re: [edk2] [PATCH v2 0/2] Fix error in PrintLib

2017-12-28 Thread Kinney, Michael D
Jian,

This change breaks GCC5 builds.

/home/mdkinney/tianocore/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c:
 In function 'InternalPrintLibSPrintMarker':
/home/mdkinney/tianocore/edk2/MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib.c:2054:71:
 error: suggest parentheses around '&&' within '||' [-Werror=parentheses]
 ArgumentString[Count * BytesPerArgumentCharacter] != '\0' &&
 ~~^~~
 Count < Precision || ((Flags & PRECISION) == 0);
 ~

Mike

> -Original Message-
> From: edk2-devel [mailto:edk2-devel-
> boun...@lists.01.org] On Behalf Of Jian J Wang
> Sent: Wednesday, December 27, 2017 6:38 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH v2 0/2] Fix error in PrintLib
> 
> > v2:
> >a. Correct incorrect description in commit log
> >b. Fix another similar issue in the same function
> >c. Fix similar issues in
> MdeModulePkg/DxePrintLibPrint2Protocol
> 
> Due to a potential hole in the stop condition of the
> loop, the two continuous
> access to ArgumentString (index, index+1) inside the
> loop might cause the
> string ending character ('\0') and the byte after it to
> be read.
> 
> Jian J Wang (2):
>   MdePkg/BasePrintLib: Fix error in Precision position
> calculation
>   MdeModulePkg/DxePrintLibPrint2Protocol: Fix potential
> string over read
> 
> 
> MdeModulePkg/Library/DxePrintLibPrint2Protocol/PrintLib
> .c | 7 +--
>  MdePkg/Library/BasePrintLib/PrintLibInternal.c
> | 7 +--
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> --
> 2.15.1.windows.2
> 
> ___
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [RFC v4 5/6] UefiCpuPkg/CpuExceptionHandlerLib: Ensure valid frame/stack pointers

2017-12-28 Thread Paulo Alcantara
Validate all possible memory dereferences during stack traces in IA32
and X64 CPU exceptions.

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Eric Dong 
Cc: Laszlo Ersek 
Requested-by: Brian Johnson 
Requested-by: Jiewen Yao 
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c | 143 
+++-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  |  75 
+-
 2 files changed, 210 insertions(+), 8 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
index 25e02fbbc1..9b52d4f6d2 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
@@ -398,6 +398,96 @@ DumpCpuContext (
 );
 }
 
+/**
+  Check if a logical address is valid.
+
+  @param[in]  SystemContext  Pointer to EFI_SYSTEM_CONTEXT.
+  @param[in]  SegmentSelectorSegment selector.
+  @param[in]  Offset Offset or logical address.
+**/
+STATIC
+BOOLEAN
+IsLogicalAddressValid (
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,
+  IN  UINT16   SegmentSelector,
+  IN  UINTNOffset
+  )
+{
+  IA32_SEGMENT_DESCRIPTOR  *SegmentDescriptor;
+  UINT32   SegDescBase;
+  UINT32   SegDescLimit;
+  UINTNSegDescLimitInBytes;
+
+  //
+  // Check for valid input parameters
+  //
+  if (SegmentSelector == 0 || Offset == 0) {
+return FALSE;
+  }
+
+  //
+  // Check whether to look for a segment descriptor in GDT or LDT table
+  //
+  if ((SegmentSelector & BIT2) == 0) {
+//
+// Get segment descriptor from GDT table
+//
+SegmentDescriptor =
+  (IA32_SEGMENT_DESCRIPTOR *)(
+(UINTN)SystemContext.SystemContextIa32->Gdtr[0] +
+((SegmentSelector >> 3) * 8)
+);
+  } else {
+//
+// Get segment descriptor from LDT table
+//
+SegmentDescriptor =
+  (IA32_SEGMENT_DESCRIPTOR *)(
+(UINTN)SystemContext.SystemContextIa32->Ldtr +
+((SegmentSelector >> 3) * 8)
+);
+  }
+
+  //
+  // Get segment descriptor's base address
+  //
+  SegDescBase = SegmentDescriptor->Bits.BaseLow |
+(SegmentDescriptor->Bits.BaseMid << 16) |
+(SegmentDescriptor->Bits.BaseHigh << 24);
+
+  //
+  // Get segment descriptor's limit
+  //
+  SegDescLimit = SegmentDescriptor->Bits.LimitLow |
+(SegmentDescriptor->Bits.LimitHigh << 16);
+
+  //
+  // Calculate segment descriptor's limit in bytes
+  //
+  if (SegmentDescriptor->Bits.G == 1) {
+SegDescLimitInBytes = (UINTN)SegDescLimit * SIZE_4KB;
+  } else {
+SegDescLimitInBytes = SegDescLimit;
+  }
+
+  //
+  // Make sure to not access beyond a segment limit boundary
+  //
+  if (Offset + SegDescBase > SegDescLimitInBytes) {
+return FALSE;
+  }
+
+  //
+  // Check if the translated logical address (or linear address) is valid
+  //
+  return IsLinearAddressValid (
+SystemContext.SystemContextIa32->Cr0,
+SystemContext.SystemContextIa32->Cr3,
+SystemContext.SystemContextIa32->Cr4,
+Offset + SegDescBase
+);
+}
+
 /**
   Dump stack trace.
 
@@ -459,6 +549,20 @@ DumpStackTrace (
   InternalPrintMessage ("\nCall trace:\n");
 
   for (;;) {
+//
+// Check for valid frame pointer
+//
+if (!IsLogicalAddressValid (SystemContext,
+SystemContext.SystemContextIa32->Ss,
+(UINTN)Ebp + 4) ||
+!IsLogicalAddressValid (SystemContext,
+SystemContext.SystemContextIa32->Ss,
+(UINTN)Ebp)) {
+  InternalPrintMessage ("%a: attempted to dereference an invalid frame "
+"pointer at 0x%08x\n", __FUNCTION__, Ebp);
+  break;
+}
+
 //
 // Print stack frame in the following format:
 //
@@ -588,6 +692,16 @@ DumpImageModuleNames (
   // Walk through call stack and find next module names
   //
   for (;;) {
+if (!IsLogicalAddressValid (SystemContext,
+SystemContext.SystemContextIa32->Ss,
+(UINTN)Ebp) ||
+!IsLogicalAddressValid (SystemContext,
+SystemContext.SystemContextIa32->Ss,
+(UINTN)Ebp + 4)) {
+  InternalPrintMessage ("%a: attempted to dereference an invalid frame "
+"pointer at 0x%08x\n", __FUNCTION__, Ebp);
+}
+
 //
 // Set EIP with return address from current stack frame
 //
@@ -651,16 +765,23 @@ DumpImageModuleNames (
 /**
   Dump stack contents.
 
-  @param[in]  CurrentEsp Current stack pointer address.
+  @param[in]  SystemContext   Pointer to 

[edk2] [RFC v4 2/6] UefiCpuPkg/CpuExceptionHandlerLib: Export GetPdbFileName()

2017-12-28 Thread Paulo Alcantara
This function will be used by both IA32 and X64 exception handling in
order to print out image module names during stack unwinding.

Cc: Eric Dong 
Cc: Laszlo Ersek 
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c   | 60 
+++-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h   | 14 +
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c | 59 
---
 3 files changed, 73 insertions(+), 60 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
index dbfaae1d30..f62ab8c48c 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
@@ -54,6 +54,11 @@ CONST CHAR8 *mExceptionNameStr[] = {
 
 #define EXCEPTION_KNOWN_NAME_NUM  (sizeof (mExceptionNameStr) / sizeof (CHAR8 
*))
 
+//
+// Unknown PDB file name
+//
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mUnknownPdbFileName = "";
+
 /**
   Get ASCII format string exception name by exception type.
 
@@ -177,4 +182,57 @@ ReadAndVerifyVectorInfo (
 VectorInfo ++;
   }
   return EFI_SUCCESS;
-}
\ No newline at end of file
+}
+
+/**
+  Get absolute path and file name of PDB file in PE/COFF image.
+
+  @param[in]  ImageBaseBase address of PE/COFF image.
+  @param[out] PdbAbsoluteFilePath  Absolute path of PDB file.
+  @param[out] PdbFileName  File name of PDB file.
+**/
+VOID
+GetPdbFileName (
+  IN  UINTNImageBase,
+  OUT CHAR8**PdbAbsoluteFilePath,
+  OUT CHAR8**PdbFileName
+  )
+{
+  VOID   *PdbPointer;
+  CHAR8  *Str;
+
+  //
+  // Get PDB file name from PE/COFF image
+  //
+  PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)ImageBase);
+  if (PdbPointer == NULL) {
+//
+// No PDB file name found. Set it to an unknown file name.
+//
+*PdbFileName = (CHAR8 *)mUnknownPdbFileName;
+if (PdbAbsoluteFilePath != NULL) {
+  *PdbAbsoluteFilePath = NULL;
+}
+  } else {
+//
+// Get file name portion out of PDB file in PE/COFF image
+//
+Str = (CHAR8 *)((UINTN)PdbPointer +
+AsciiStrLen ((CHAR8 *)PdbPointer) - sizeof *Str);
+for (; *Str != '/' && *Str != '\\'; Str--) {
+  ;
+}
+
+//
+// Set PDB file name (also skip trailing path separator: '/' or '\\')
+//
+*PdbFileName = Str + 1;
+
+if (PdbAbsoluteFilePath != NULL) {
+  //
+  // Set absolute file path of PDB file
+  //
+  *PdbAbsoluteFilePath = PdbPointer;
+}
+  }
+}
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
index e10d9379d5..64c7094513 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
@@ -327,5 +327,19 @@ AsmGetTssTemplateMap (
   OUT EXCEPTION_HANDLER_TEMPLATE_MAP  *AddressMap
   );
 
+/**
+  Get absolute path and file name of PDB file in PE/COFF image.
+
+  @param[in]  ImageBaseBase address of PE/COFF image.
+  @param[out] PdbAbsoluteFilePath  Absolute path of PDB file.
+  @param[out] PdbFileName  File name of PDB file.
+**/
+VOID
+GetPdbFileName (
+  IN  UINTNImageBase,
+  OUT CHAR8**PdbAbsoluteFilePath,
+  OUT CHAR8**PdbFileName
+  );
+
 #endif
 
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
index 19bfaa329a..d3a3878b3d 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
@@ -14,11 +14,6 @@
 
 #include "CpuExceptionCommon.h"
 
-//
-// Unknown PDB file name
-//
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mUnknownPdbFileName = "";
-
 /**
   Return address map of exception handler template so that C code can generate
   exception tables.
@@ -403,60 +398,6 @@ DumpCpuContext (
 );
 }
 
-/**
-  Get absolute path and file name of PDB file in PE/COFF image.
-
-  @param[in]  ImageBaseBase address of PE/COFF image.
-  @param[out] PdbAbsoluteFilePath  Absolute path of PDB file.
-  @param[out] PdbFileName  File name of PDB file.
-**/
-STATIC
-VOID
-GetPdbFileName (
-  IN  UINTNImageBase,
-  OUT CHAR8**PdbAbsoluteFilePath,
-  OUT CHAR8**PdbFileName
-  )
-{
-  VOID   *PdbPointer;
-  CHAR8  *Str;
-
-  //
-  // Get PDB file name from PE/COFF image
-  //
-  PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)ImageBase);
-  if (PdbPointer == NULL) {
-//
-// No PDB file name found. Set it to an unknown file name.
-//
-*PdbFileName = (CHAR8 *)mUnknownPdbFileName;
-if (PdbAbsoluteFilePath != 

[edk2] [RFC v4 4/6] UefiCpuPkg/CpuExceptionHandlerLib: Add helper to valid memory addresses

2017-12-28 Thread Paulo Alcantara
Introduce IsLinearAddressValid() function that will be used for
validating memory addresses that would get dereferenced during stack
traces in IA32 and X64 CPU exceptions.

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Eric Dong 
Cc: Laszlo Ersek 
Requested-by: Brian Johnson 
Requested-by: Jiewen Yao 
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c | 382 

 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h |  16 +
 2 files changed, 398 insertions(+)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
index 867c5c01d6..52b3eb1463 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
@@ -14,6 +14,9 @@
 
 #include "CpuExceptionCommon.h"
 
+#include 
+#include 
+
 //
 // Error code flag indicating whether or not an error code will be
 // pushed on the stack if an exception occurs.
@@ -194,3 +197,382 @@ GetPdbFileName (
 }
   }
 }
+
+/**
+  Check if a linear address is valid by walking the page tables in 4-level
+  paging mode.
+
+  @param[in]  Cr3 CR3 control register.
+  @param[in]  MaxPhyAddrBits  MAXPHYADDRBITS bits.
+  @param[in]  LinearAddress   Linear address to be checked.
+**/
+STATIC
+BOOLEAN
+Do4LevelPagingModeCheck (
+  IN UINTNCr3,
+  IN UINT8MaxPhyAddrBits,
+  IN UINTNLinearAddress
+  )
+{
+  UINT64 PhysicalAddress;
+  UINT64 *Pml4TableEntry;
+  UINT64 *PageDirPtrTableEntry;
+  UINT64 *PageDirEntry;
+  UINT64 *PageTableEntry;
+
+  //
+  // In 4-level paging mode, linear addresses are 48 bits wide
+  //
+  if ((UINT64)LinearAddress > (1ULL << 48) - 1) {
+return FALSE;
+  }
+
+  //
+  // Calculate physical address of PML4E
+  //
+  PhysicalAddress = (UINT64)Cr3 & (((1ULL << MaxPhyAddrBits) - 1) << 12);
+  PhysicalAddress |= (((UINT64)LinearAddress >> 39) & 0x1FF) << 3;
+
+  ASSERT ((PhysicalAddress & (sizeof (*Pml4TableEntry) - 1)) == 0);
+
+  Pml4TableEntry = (UINT64 *)(UINTN)PhysicalAddress;
+
+  //
+  // Check if a PDPTE is present
+  //
+  if ((*Pml4TableEntry & BIT0) == 0) {
+return FALSE;
+  }
+
+  //
+  // Calculate physical address of PDPTE
+  //
+  PhysicalAddress = *Pml4TableEntry & (((1ULL << MaxPhyAddrBits) - 1) << 12);
+  PhysicalAddress |= (((UINT64)LinearAddress >> 30) & 0x1FF) << 3;
+
+  ASSERT ((PhysicalAddress & (sizeof (*PageDirPtrTableEntry) - 1)) == 0);
+
+  PageDirPtrTableEntry = (UINT64 *)(UINTN)PhysicalAddress;
+
+  //
+  // Check whether a PDPTE or 1GiB page entry is present
+  //
+  if ((*PageDirPtrTableEntry & BIT0) == 0) {
+return FALSE;
+  }
+
+  //
+  // Check if PDPTE maps an 1GiB page
+  //
+  if ((*PageDirPtrTableEntry & BIT7) != 0) {
+return TRUE;
+  }
+
+  //
+  // Calculate physical address of PDE
+  //
+  PhysicalAddress = *PageDirPtrTableEntry & (((1ULL << MaxPhyAddrBits) - 1) <<
+ 12);
+  PhysicalAddress |= (((UINT64)LinearAddress >> 21) & 0x1FF) << 3;
+
+  ASSERT ((PhysicalAddress & (sizeof (*PageDirEntry) - 1)) == 0);
+
+  PageDirEntry = (UINT64 *)(UINTN)PhysicalAddress;
+
+  //
+  // Check whether a PDE or a 2MiB page entry is present
+  //
+  if ((*PageDirEntry & BIT0) == 0) {
+return FALSE;
+  }
+
+  //
+  // Check if PDE maps a 2MiB page
+  //
+  if ((*PageDirEntry & BIT7) != 0) {
+return TRUE;
+  }
+
+  //
+  // Calculate physical address of PTE
+  //
+  PhysicalAddress = *PageDirEntry & (((1ULL << MaxPhyAddrBits) - 1) << 12);
+  PhysicalAddress |= (((UINT64)LinearAddress >> 12) & 0x1FF) << 3;
+
+  ASSERT ((PhysicalAddress & (sizeof (*PageTableEntry) - 1)) == 0);
+
+  PageTableEntry = (UINT64 *)(UINTN)PhysicalAddress;
+
+  //
+  // Check if PTE maps a 4KiB page
+  //
+  if ((*PageTableEntry & BIT0) == 0) {
+return FALSE;
+  }
+
+  return TRUE;
+}
+
+/**
+  Check if a linear address is valid by walking the page tables in 32-bit 
paging
+  mode.
+
+  @param[in]  Cr3 CR3 control register.
+  @param[in]  Cr4 CR4 control register.
+  @param[in]  LinearAddress   Linear address to be checked.
+**/
+STATIC
+BOOLEAN
+Do32BitPagingModeCheck (
+  IN UINTNCr3,
+  IN UINTNCr4,
+  IN UINTNLinearAddress
+  )
+{
+  UINT64 PhysicalAddress;
+  UINT32 *PageDirEntry;
+  UINT32 *PageTableEntry;
+
+  if (LinearAddress > MAX_UINT32) {
+return FALSE;
+  }
+
+  //
+  // Calculate physical address of PDE
+  //
+  PhysicalAddress = (UINT32)Cr3 & (((1ULL << 20) - 1) << 12);
+  PhysicalAddress |= (((UINT32)LinearAddress >> 22) & 0x3FF) << 2;
+
+  ASSERT ((PhysicalAddress & (sizeof (*PageDirEntry) - 1)) == 0);
+
+  PageDirEntry = (UINT32 *)(UINTN)PhysicalAddress;
+
+  //
+  // Check whether a PTE or a 4MiB page is present
+ 

[edk2] [RFC v4 6/6] UefiCpuPkg/CpuExceptionHandlerLib: Correctly print IP addresses

2017-12-28 Thread Paulo Alcantara
Remove the supurious '- 1' when calculating the IP addresses during the
stack traces.

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Eric Dong 
Cc: Laszlo Ersek 
Requested-by: Jeff Fan 
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c | 2 +-
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
index 9b52d4f6d2..e2a3341286 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
@@ -573,7 +573,7 @@ DumpStackTrace (
   *UnwoundStacksCount - 1,
   Eip,
   ImageBase,
-  Eip - ImageBase - 1,
+  Eip - ImageBase,
   Ebp,
   PdbFileName
   );
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
index 8067c34122..5ae3aa4e73 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
@@ -717,7 +717,7 @@ DumpStackTrace (
   *UnwoundStacksCount - 1,
   Rip,
   ImageBase,
-  Rip - ImageBase - 1,
+  Rip - ImageBase,
   Rbp,
   PdbFileName
   );
-- 
2.14.3

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


[edk2] [RFC v4 1/6] UefiCpuPkg/CpuExceptionHandlerLib/X64: Add stack trace support

2017-12-28 Thread Paulo Alcantara
This patch adds stack trace support during a X64 CPU exception.

It will dump out back trace, stack contents as well as image module
names that were part of the call stack.

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Eric Dong 
Cc: Laszlo Ersek 
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c | 376 
+++-
 1 file changed, 374 insertions(+), 2 deletions(-)

diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
index 1dcf4277de..19bfaa329a 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchExceptionHandler.c
@@ -14,6 +14,11 @@
 
 #include "CpuExceptionCommon.h"
 
+//
+// Unknown PDB file name
+//
+GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mUnknownPdbFileName = "";
+
 /**
   Return address map of exception handler template so that C code can generate
   exception tables.
@@ -398,6 +403,357 @@ DumpCpuContext (
 );
 }
 
+/**
+  Get absolute path and file name of PDB file in PE/COFF image.
+
+  @param[in]  ImageBaseBase address of PE/COFF image.
+  @param[out] PdbAbsoluteFilePath  Absolute path of PDB file.
+  @param[out] PdbFileName  File name of PDB file.
+**/
+STATIC
+VOID
+GetPdbFileName (
+  IN  UINTNImageBase,
+  OUT CHAR8**PdbAbsoluteFilePath,
+  OUT CHAR8**PdbFileName
+  )
+{
+  VOID   *PdbPointer;
+  CHAR8  *Str;
+
+  //
+  // Get PDB file name from PE/COFF image
+  //
+  PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *)ImageBase);
+  if (PdbPointer == NULL) {
+//
+// No PDB file name found. Set it to an unknown file name.
+//
+*PdbFileName = (CHAR8 *)mUnknownPdbFileName;
+if (PdbAbsoluteFilePath != NULL) {
+  *PdbAbsoluteFilePath = NULL;
+}
+  } else {
+//
+// Get file name portion out of PDB file in PE/COFF image
+//
+Str = (CHAR8 *)((UINTN)PdbPointer +
+AsciiStrLen ((CHAR8 *)PdbPointer) - sizeof *Str);
+for (; *Str != '/' && *Str != '\\'; Str--) {
+  ;
+}
+
+//
+// Set PDB file name (also skip trailing path separator: '/' or '\\')
+//
+*PdbFileName = Str + 1;
+
+if (PdbAbsoluteFilePath != NULL) {
+  //
+  // Set absolute file path of PDB file
+  //
+  *PdbAbsoluteFilePath = PdbPointer;
+}
+  }
+}
+
+/**
+  Dump stack contents.
+
+  @param[in]  CurrentRsp Current stack pointer address.
+  @param[in]  UnwoundStacksCount  Count of unwound stack frames.
+**/
+STATIC
+VOID
+DumpStackContents (
+  IN UINT64  CurrentRsp,
+  IN INTNUnwoundStacksCount
+  )
+{
+  //
+  // Check for proper stack pointer alignment
+  //
+  if (((UINTN)CurrentRsp & (CPU_STACK_ALIGNMENT - 1)) != 0) {
+InternalPrintMessage (" Unaligned stack pointer. \n");
+return;
+  }
+
+  //
+  // Dump out stack contents
+  //
+  InternalPrintMessage ("\nStack dump:\n");
+  while (UnwoundStacksCount-- > 0) {
+InternalPrintMessage (
+  "0x%016lx: %016lx %016lx\n",
+  CurrentRsp,
+  *(UINT64 *)CurrentRsp,
+  *(UINT64 *)((UINTN)CurrentRsp + 8)
+  );
+
+//
+// Point to next stack
+//
+CurrentRsp += CPU_STACK_ALIGNMENT;
+  }
+}
+
+/**
+  Dump all image module names from call stack.
+
+  @param[in]  SystemContext  Pointer to EFI_SYSTEM_CONTEXT.
+**/
+STATIC
+VOID
+DumpImageModuleNames (
+  IN EFI_SYSTEM_CONTEXT   SystemContext
+  )
+{
+  EFI_STATUS  Status;
+  UINT64  Rip;
+  UINTN   ImageBase;
+  VOID*EntryPoint;
+  CHAR8   *PdbAbsoluteFilePath;
+  CHAR8   *PdbFileName;
+  UINT64  Rbp;
+  UINTN   LastImageBase;
+
+  //
+  // Set current RIP address
+  //
+  Rip = SystemContext.SystemContextX64->Rip;
+
+  //
+  // Set current frame pointer address
+  //
+  Rbp = SystemContext.SystemContextX64->Rbp;
+
+  //
+  // Check for proper frame pointer alignment
+  //
+  if (((UINTN)Rbp & (CPU_STACK_ALIGNMENT - 1)) != 0) {
+InternalPrintMessage (" Unaligned frame pointer. \n");
+return;
+  }
+
+  //
+  // Get initial PE/COFF image base address from current RIP
+  //
+  ImageBase = PeCoffSearchImageBase (Rip);
+  if (ImageBase == 0) {
+InternalPrintMessage (" Could not find image module names. ");
+return;
+  }
+
+  //
+  // Set last PE/COFF image base address
+  //
+  LastImageBase = ImageBase;
+
+  //
+  // Get initial PE/COFF image's entry point
+  //
+  Status = PeCoffLoaderGetEntryPoint ((VOID *)ImageBase, );
+  if (EFI_ERROR (Status)) {
+EntryPoint = NULL;
+  }
+
+  //
+  // Get file name and absolute path of initial PDB file
+  //
+  GetPdbFileName (ImageBase, , );
+
+  //
+  // Print out initial image module name (if any)
+  //
+  if (PdbAbsoluteFilePath != NULL) {
+InternalPrintMessage (
+  "\n%a (ImageBase=0x%016lx, 

[edk2] [RFC v4 3/6] UefiCpuPkg/CpuExceptionHandlerLib/Ia32: Add stack trace support

2017-12-28 Thread Paulo Alcantara
This patch adds stack trace support during a IA32 CPU exception.

It will dump out back trace, stack contents as well as image module
names that were part of the call stack.

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Eric Dong 
Cc: Laszlo Ersek 
Signed-off-by: Paulo Alcantara 
---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c|  42 ---
 UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h|  11 -
 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c | 310 
+++-
 3 files changed, 308 insertions(+), 55 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
index f62ab8c48c..867c5c01d6 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
@@ -109,48 +109,6 @@ InternalPrintMessage (
   SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
 }
 
-/**
-  Find and display image base address and return image base and its entry 
point.
-
-  @param CurrentEip  Current instruction pointer.
-
-**/
-VOID
-DumpModuleImageInfo (
-  IN  UINTN  CurrentEip
-  )
-{
-  EFI_STATUS   Status;
-  UINTNPe32Data;
-  VOID *PdbPointer;
-  VOID *EntryPoint;
-
-  Pe32Data = PeCoffSearchImageBase (CurrentEip);
-  if (Pe32Data == 0) {
-InternalPrintMessage (" Can't find image information. \n");
-  } else {
-//
-// Find Image Base entry point
-//
-Status = PeCoffLoaderGetEntryPoint ((VOID *) Pe32Data, );
-if (EFI_ERROR (Status)) {
-  EntryPoint = NULL;
-}
-InternalPrintMessage (" Find image ");
-PdbPointer = PeCoffLoaderGetPdbPointer ((VOID *) Pe32Data);
-if (PdbPointer != NULL) {
-  InternalPrintMessage ("%a", PdbPointer);
-} else {
-  InternalPrintMessage ("(No PDB) " );
-}
-InternalPrintMessage (
-  " (ImageBase=%016lp, EntryPoint=%016p) \n",
-  (VOID *) Pe32Data,
-  EntryPoint
-  );
-  }
-}
-
 /**
   Read and save reserved vector information
 
diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
index 64c7094513..ec46c2d9d3 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.h
@@ -130,17 +130,6 @@ InternalPrintMessage (
   ...
   );
 
-/**
-  Find and display image base address and return image base and its entry 
point.
-
-  @param CurrentEip  Current instruction pointer.
-
-**/
-VOID
-DumpModuleImageInfo (
-  IN  UINTN  CurrentEip
-  );
-
 /**
   Display CPU information.
 
diff --git 
a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
index 6ac8549839..25e02fbbc1 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ArchExceptionHandler.c
@@ -398,6 +398,296 @@ DumpCpuContext (
 );
 }
 
+/**
+  Dump stack trace.
+
+  @param[in]  SystemContext  Pointer to EFI_SYSTEM_CONTEXT.
+  @param[out] UnwoundStacksCount  Count of unwound stack frames.
+**/
+STATIC
+VOID
+DumpStackTrace (
+  IN  EFI_SYSTEM_CONTEXT   SystemContext,
+  OUT INTN *UnwoundStacksCount
+  )
+{
+  UINT32  Eip;
+  UINT32  Ebp;
+  UINTN   ImageBase;
+  CHAR8   *PdbFileName;
+
+  //
+  // Set current EIP address
+  //
+  Eip = SystemContext.SystemContextIa32->Eip;
+
+  //
+  // Set current frame pointer address
+  //
+  Ebp = SystemContext.SystemContextIa32->Ebp;
+
+  //
+  // Check for proper frame pointer alignment
+  //
+  if (((UINTN)Ebp & (CPU_STACK_ALIGNMENT - 1)) != 0) {
+InternalPrintMessage (" Unaligned frame pointer. \n");
+return;
+  }
+
+  //
+  // Get initial PE/COFF image base address from current EIP
+  //
+  ImageBase = PeCoffSearchImageBase (Eip);
+  if (ImageBase == 0) {
+InternalPrintMessage (" Could not find backtrace information. ");
+return;
+  }
+
+  //
+  // Get PDB file name from initial PE/COFF image
+  //
+  GetPdbFileName (ImageBase, NULL, );
+
+  //
+  // Initialize count of unwound stacks
+  //
+  *UnwoundStacksCount = 1;
+
+  //
+  // Print out back trace
+  //
+  InternalPrintMessage ("\nCall trace:\n");
+
+  for (;;) {
+//
+// Print stack frame in the following format:
+//
+// #  @ + (EBP) in [ | ]
+//
+InternalPrintMessage (
+  "%d 0x%08x @ 0x%08x+0x%x (0x%08x) in %a\n",
+  *UnwoundStacksCount - 1,
+  Eip,
+  ImageBase,
+  Eip - ImageBase - 1,
+  Ebp,
+  PdbFileName
+  );
+
+//
+// Set EIP