From 4face8708098c2fe637cf6866a0ced3df2ab89af Mon Sep 17 00:00:00 2001 From: kuqin12 <42554914+kuqin12@users.noreply.github.com> Date: Wed, 26 Apr 2023 11:24:31 -0700 Subject: [PATCH] Add Windows ARM 64-bit base tools (#376) # Preface Please ensure you have read the [contribution docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior to submitting the pull request. In particular, [pull request guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices). ## Description This change is a part of https://github.com/microsoft/mu_basecore/issues/305 feature work. The change expanded the accepted target architecture for VS builds with `AARCH64` option, which will output native Windows ARM64 binaries. Note that the warnings due to integer conversions are suppressed for this specific target to avoid too much local changes carried in MU. The formal change should drop all these binaries and move to pythonic scripts. For each item, place an "x" in between `[` and `]` if true. Example: `[x]`. _(you can also check items in the GitHub UI)_ - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested This was tested on Windows ARM64 hardware systems. ## Integration Instructions N/A --- .../BaseTools-Build-For-Publication.yml | 10 ++- BaseTools/.gitignore | 3 +- BaseTools/Edk2ToolsBuild.py | 12 ++- .../Source/C/Include/AArch64/ProcessorBind.h | 83 ++++++++++++++++--- BaseTools/Source/C/Makefiles/ms.common | 12 ++- 5 files changed, 102 insertions(+), 18 deletions(-) diff --git a/.azurepipelines/BaseTools-Build-For-Publication.yml b/.azurepipelines/BaseTools-Build-For-Publication.yml index d62e922cab..ee8711d4be 100644 --- a/.azurepipelines/BaseTools-Build-For-Publication.yml +++ b/.azurepipelines/BaseTools-Build-For-Publication.yml @@ -19,7 +19,7 @@ name: BaseTools_Bin_$(release_version)_$(Rev:r) variables: linux_build_output_path: '$(Build.Repository.LocalPath)/BaseTools/Source/C/bin' linux_artifact_name: 'LinuxOutput' - windows_build_output_path: '$(Build.Repository.LocalPath)\BaseTools\Bin\Win32' + windows_build_output_path: '$(Build.Repository.LocalPath)\BaseTools\Bin' windows_artifact_name: 'WindowsOutput' temp_publication_directory: 'PackageStaging' package_artifact_name: 'NugetReleasePackage' @@ -86,8 +86,13 @@ jobs: matrix: TARGET_x86: Build.Targets: 'IA32' + Build.TargetFolder: 'Win32' TARGET_ARM: Build.Targets: 'ARM' + Build.TargetFolder: 'Win32' + TARGET_AArch64: + Build.Targets: 'AARCH64' + Build.TargetFolder: 'Win64' pool: vmImage: windows-latest @@ -126,7 +131,7 @@ jobs: extra_parameters: '--skip_path_env -a $(Build.Targets)' tool_chain_tag: 'VS2022' - - publish: $(windows_build_output_path) + - publish: '$(windows_build_output_path)\$(Build.TargetFolder)' artifact: $(windows_artifact_name)_$(Build.Targets) displayName: Publish To Pipeline condition: SucceededOrFailed() @@ -188,6 +193,7 @@ jobs: mv $(Pipeline.Workspace)/$(linux_artifact_name)_AARCH64 $(Build.StagingDirectory)/$(temp_publication_directory)/Linux-ARM-64; mv $(Pipeline.Workspace)/$(windows_artifact_name)_IA32 $(Build.StagingDirectory)/$(temp_publication_directory)/Windows-x86; mv $(Pipeline.Workspace)/$(windows_artifact_name)_ARM $(Build.StagingDirectory)/$(temp_publication_directory)/Windows-ARM; + mv $(Pipeline.Workspace)/$(windows_artifact_name)_AARCH64 $(Build.StagingDirectory)/$(temp_publication_directory)/Windows-ARM-64; displayName: Stage Package Files - powershell: diff --git a/BaseTools/.gitignore b/BaseTools/.gitignore index ec9c69f8b2..5a057b604d 100644 --- a/BaseTools/.gitignore +++ b/BaseTools/.gitignore @@ -17,5 +17,6 @@ Source/C/VfrCompile/VfrTokens.h Source/C/bin/ Source/C/libs/ Bin/Win32 +Bin/Win64 Lib -BaseToolsBuild/ \ No newline at end of file +BaseToolsBuild/ diff --git a/BaseTools/Edk2ToolsBuild.py b/BaseTools/Edk2ToolsBuild.py index e7a202857a..0add59b5bb 100644 --- a/BaseTools/Edk2ToolsBuild.py +++ b/BaseTools/Edk2ToolsBuild.py @@ -138,9 +138,19 @@ def Go(self): if self.target_arch == "IA32": VcToolChainArch = "x86" TargetInfoArch = "x86" + OutputDir = "Win32" elif self.target_arch == "ARM": VcToolChainArch = "x86_arm" TargetInfoArch = "ARM" + OutputDir = "Win32" + elif self.target_arch == "X64": + VcToolChainArch = "amd64" + TargetInfoArch = "x86" + OutputDir = "Win64" + elif self.target_arch == "AARCH64": + VcToolChainArch = "amd64_arm64" + TargetInfoArch = "ARM" + OutputDir = "Win64" else: raise NotImplementedError() # MU_CHANGE @@ -166,7 +176,7 @@ def Go(self): shell_env.set_shell_var('HOST_ARCH', self.target_arch) self.OutputDir = os.path.join( - shell_env.get_shell_var("EDK_TOOLS_PATH"), "Bin", "Win32") + shell_env.get_shell_var("EDK_TOOLS_PATH"), "Bin", OutputDir) # compiled tools need to be added to path because antlr is referenced # MU_CHANGE: Added logic to support cross compilation scenarios diff --git a/BaseTools/Source/C/Include/AArch64/ProcessorBind.h b/BaseTools/Source/C/Include/AArch64/ProcessorBind.h index dfa725b2e3..4995eff3ce 100644 --- a/BaseTools/Source/C/Include/AArch64/ProcessorBind.h +++ b/BaseTools/Source/C/Include/AArch64/ProcessorBind.h @@ -24,26 +24,82 @@ #pragma pack() #endif +// MU_CHANGE Starts: Fixing basic ARM definitions in Windows #if _MSC_EXTENSIONS + +// +// Disable warning that make it impossible to compile at /W4 +// This only works for Microsoft* tools +// + +// +// Disabling bitfield type checking warnings. +// +#pragma warning ( disable : 4214 ) + +// +// Disabling the unreferenced formal parameter warnings. +// +#pragma warning ( disable : 4100 ) + +// +// Disable slightly different base types warning as CHAR8 * can not be set +// to a constant string. +// +#pragma warning ( disable : 4057 ) + +// +// ASSERT(FALSE) or while (TRUE) are legal constructs so suppress this warning +// +#pragma warning ( disable : 4127 ) + + +#endif + +#if !defined(__GNUC__) && (__STDC_VERSION__ < 199901L) // - // use Microsoft* C compiler dependent integer width types + // No ANSI C 2000 stdint.h integer width declarations, so define equivalents // - typedef unsigned __int64 UINT64; - typedef __int64 INT64; - typedef unsigned __int32 UINT32; - typedef __int32 INT32; - typedef unsigned short UINT16; - typedef unsigned short CHAR16; - typedef short INT16; - typedef unsigned char BOOLEAN; - typedef unsigned char UINT8; - typedef char CHAR8; - typedef signed char INT8; + + #if _MSC_EXTENSIONS + // + // use Microsoft* C compiler dependent integer width types + // + #include + typedef unsigned __int64 UINT64; + typedef __int64 INT64; + typedef unsigned __int32 UINT32; + typedef __int32 INT32; + typedef unsigned short UINT16; + typedef unsigned short CHAR16; + typedef short INT16; + typedef unsigned char BOOLEAN; + typedef unsigned char UINT8; + typedef char CHAR8; + typedef signed char INT8; + #else + // + // Assume standard ARM alignment. + // + typedef unsigned long long UINT64; + typedef long long INT64; + typedef unsigned int UINT32; + typedef int INT32; + typedef unsigned short UINT16; + typedef unsigned short CHAR16; + typedef short INT16; + typedef unsigned char BOOLEAN; + typedef unsigned char UINT8; + typedef char CHAR8; + typedef signed char INT8; + + #endif + #else // // Use ANSI C 2000 stdint.h integer width declarations // - #include + #include "stdint.h" typedef uint8_t BOOLEAN; typedef int8_t INT8; typedef uint8_t UINT8; @@ -57,6 +113,7 @@ typedef uint16_t CHAR16; #endif +// MU_CHANGE Ends /// /// Unsigned value of native width. (4 bytes on supported 32-bit processor instructions, diff --git a/BaseTools/Source/C/Makefiles/ms.common b/BaseTools/Source/C/Makefiles/ms.common index 9ba7f10edb..05f54719aa 100644 --- a/BaseTools/Source/C/Makefiles/ms.common +++ b/BaseTools/Source/C/Makefiles/ms.common @@ -44,13 +44,23 @@ LIB_PATH = $(BASE_TOOLS_PATH)\Lib\Win64 SYS_BIN_PATH = $(EDK_TOOLS_PATH)\Bin\Win64 SYS_LIB_PATH = $(EDK_TOOLS_PATH)\Lib\Win64 -# MU_CHANGE Starts: Adding support to build base tools for ARM +# MU_CHANGE Starts: Adding support to build base tools for ARM and AARCH64 !ELSEIF "$(HOST_ARCH)"=="ARM" ARCH_INCLUDE = $(SOURCE_PATH)\Include\Arm BIN_PATH = $(BASE_TOOLS_PATH)\Bin\Win32 LIB_PATH = $(BASE_TOOLS_PATH)\Lib\Win32 SYS_BIN_PATH = $(EDK_TOOLS_PATH)\Bin\Win32 SYS_LIB_PATH = $(EDK_TOOLS_PATH)\Lib\Win32 +!ELSEIF "$(HOST_ARCH)"=="AARCH64" +ARCH_INCLUDE = $(SOURCE_PATH)\Include\AArch64 +BIN_PATH = $(BASE_TOOLS_PATH)\Bin\Win64 +LIB_PATH = $(BASE_TOOLS_PATH)\Lib\Win64 +SYS_BIN_PATH = $(EDK_TOOLS_PATH)\Bin\Win64 +SYS_LIB_PATH = $(EDK_TOOLS_PATH)\Lib\Win64 +# Note: These are bit-width conversion related warning suppressions we carry to avoid much more +# overrides in the C code. The future plan is to replace all of these binary based tools +# with python scripts, when it happens in tianocore.. +CFLAGS = $(CFLAGS) /wd4267 /wd4244 /wd4334 # MU_CHANGE Ends !ELSE