public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support
@ 2021-10-09 15:49 retrage01
  2021-10-09 15:49 ` [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo Akira Moroo
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: retrage01 @ 2021-10-09 15:49 UTC (permalink / raw)
  To: devel; +Cc: afish, ray.ni, Akira Moroo

This series of patches proposes adding AArch64 Linux host support for
EmulatorPkg. The main difference from IA32/X64 is that it does not
need to convert calling conventions between EFI environment and the
host. It is enough just directly registering the host side functions to
the EmulatorPkg provided UEFI protocols. I tested this feature on the
latest Ubuntu 20.04 with both CLANG38 and GCC5 toolchains.

The patch 1/4 is a trivial typo fix that are required for the 3/4 patch.
The 2/4 adds AArch64 specific stack switch code for EmulatorPkg/Sec. The
3/4 changes EmulatorPkg/Unix/Host to support AArch64. The 4/4 introduces
EmulatorPkg AArch64 Linux host build support.

Akira Moroo (4):
  EmulatorPkg/Unix/Host: Fix typo
  EmulatorPkg/Sec: Add AArch64 support
  EmulatorPkg/Unix/Host: Add AArch64 support
  EmulatorPkg: Add AArch64 Unix host build support

 EmulatorPkg/EmulatorPkg.dsc                  | 15 +++-
 EmulatorPkg/Readme.md                        |  8 ++
 EmulatorPkg/Sec/AArch64/SwitchRam.S          | 22 +++++
 EmulatorPkg/Sec/AArch64/TempRam.c            | 58 ++++++++++++
 EmulatorPkg/Sec/Sec.inf                      |  4 +
 EmulatorPkg/Unix/Host/AArch64/Gasket.c       | 50 +++++++++++
 EmulatorPkg/Unix/Host/AArch64/SwitchStack.S  | 42 +++++++++
 EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c | 37 ++++++++
 EmulatorPkg/Unix/Host/BlockIo.c              | 26 ++++++
 EmulatorPkg/Unix/Host/EmuThunk.c             | 29 ++++++
 EmulatorPkg/Unix/Host/Host.c                 | 32 +++++++
 EmulatorPkg/Unix/Host/Host.h                 |  4 +-
 EmulatorPkg/Unix/Host/Host.inf               | 10 ++-
 EmulatorPkg/Unix/Host/LinuxPacketFilter.c    | 38 ++++++++
 EmulatorPkg/Unix/Host/PosixFileSystem.c      | 94 +++++++++++++++++++-
 EmulatorPkg/Unix/Host/Pthreads.c             | 30 ++++++-
 EmulatorPkg/Unix/Host/X11GraphicsWindow.c    | 26 +++++-
 EmulatorPkg/build.sh                         |  8 ++
 18 files changed, 524 insertions(+), 9 deletions(-)
 create mode 100644 EmulatorPkg/Sec/AArch64/SwitchRam.S
 create mode 100644 EmulatorPkg/Sec/AArch64/TempRam.c
 create mode 100644 EmulatorPkg/Unix/Host/AArch64/Gasket.c
 create mode 100644 EmulatorPkg/Unix/Host/AArch64/SwitchStack.S

-- 
2.33.0


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

* [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo
  2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
@ 2021-10-09 15:49 ` Akira Moroo
  2021-10-09 15:49 ` [RFC PATCH 2/4] EmulatorPkg/Sec: Add AArch64 support Akira Moroo
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Moroo @ 2021-10-09 15:49 UTC (permalink / raw)
  To: devel; +Cc: afish, ray.ni, Akira Moroo

The function name should be `SecPeCoffUnloadImageExtraAction`.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
---
 EmulatorPkg/Unix/Host/Host.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/EmulatorPkg/Unix/Host/Host.h b/EmulatorPkg/Unix/Host/Host.h
index 9791cf8c37..3841a91db8 100644
--- a/EmulatorPkg/Unix/Host/Host.h
+++ b/EmulatorPkg/Unix/Host/Host.h
@@ -292,8 +292,8 @@ SecPeCoffRelocateImageExtraAction (
 
 VOID
 EFIAPI
-SecPeCoffLoaderUnloadImageExtraAction (
-  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext
+SecPeCoffUnloadImageExtraAction (
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
   );
 
 
-- 
2.33.0


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

* [RFC PATCH 2/4] EmulatorPkg/Sec: Add AArch64 support
  2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
  2021-10-09 15:49 ` [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo Akira Moroo
@ 2021-10-09 15:49 ` Akira Moroo
  2021-10-09 15:49 ` [RFC PATCH 3/4] EmulatorPkg/Unix/Host: " Akira Moroo
  2021-10-09 15:49 ` [RFC PATCH 4/4] EmulatorPkg: Add AArch64 Unix host build support Akira Moroo
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Moroo @ 2021-10-09 15:49 UTC (permalink / raw)
  To: devel; +Cc: afish, ray.ni, Akira Moroo

This commit adds AArch64 support to EmulatorPkg/Sec. The architecture
specific part is switching stack from temporary to permanent.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
---
 EmulatorPkg/Sec/AArch64/SwitchRam.S | 22 +++++++++++
 EmulatorPkg/Sec/AArch64/TempRam.c   | 58 +++++++++++++++++++++++++++++
 EmulatorPkg/Sec/Sec.inf             |  4 ++
 3 files changed, 84 insertions(+)
 create mode 100644 EmulatorPkg/Sec/AArch64/SwitchRam.S
 create mode 100644 EmulatorPkg/Sec/AArch64/TempRam.c

diff --git a/EmulatorPkg/Sec/AArch64/SwitchRam.S b/EmulatorPkg/Sec/AArch64/SwitchRam.S
new file mode 100644
index 0000000000..9ec8ddd627
--- /dev/null
+++ b/EmulatorPkg/Sec/AArch64/SwitchRam.S
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2011, Apple Inc. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#------------------------------------------------------------------------------
+
+
+// VOID
+// EFIAPI
+// SecSwitchStack (
+//   VOID  *StackDelta
+//   )
+//
+ASM_GLOBAL ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+    mov   x1, sp
+    add   x1, x0, x1
+    mov   sp, x1
+    ret
+
diff --git a/EmulatorPkg/Sec/AArch64/TempRam.c b/EmulatorPkg/Sec/AArch64/TempRam.c
new file mode 100644
index 0000000000..cce1dc559a
--- /dev/null
+++ b/EmulatorPkg/Sec/AArch64/TempRam.c
@@ -0,0 +1,58 @@
+/*++ @file
+  Temp RAM PPI
+
+Copyright (c) 2011, Apple Inc. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiPei.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+
+#include <Ppi/TemporaryRamSupport.h>
+
+VOID
+EFIAPI
+SecSwitchStack (
+  VOID  *StackDelta
+  );
+
+
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+  IN CONST EFI_PEI_SERVICES   **PeiServices,
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
+  IN UINTN                    CopySize
+  )
+{
+  //
+  // Migrate the whole temporary memory to permanent memory.
+  //
+  CopyMem (
+    (VOID*)(UINTN)PermanentMemoryBase,
+    (VOID*)(UINTN)TemporaryMemoryBase,
+    CopySize
+    );
+
+  //
+  // SecSwitchStack function must be invoked after the memory migration
+  // immediately, also we need fixup the stack change caused by new call into
+  // permanent memory.
+  //
+  SecSwitchStack ((VOID *)(PermanentMemoryBase - TemporaryMemoryBase));
+
+  //
+  // We need *not* fix the return address because currently,
+  // The PeiCore is executed in flash.
+  //
+
+  //
+  // Simulate to invalid temporary memory, terminate temporary memory
+  //
+  ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
+
+  return EFI_SUCCESS;
+}
diff --git a/EmulatorPkg/Sec/Sec.inf b/EmulatorPkg/Sec/Sec.inf
index 2f9e3d4780..83248fbaca 100644
--- a/EmulatorPkg/Sec/Sec.inf
+++ b/EmulatorPkg/Sec/Sec.inf
@@ -30,6 +30,10 @@
   Ia32/SwitchRam.asm
   Ia32/SwitchRam.S
 
+[Sources.AARCH64]
+  AArch64/TempRam.c
+  AArch64/SwitchRam.S
+
 [Packages]
   MdePkg/MdePkg.dec
   EmulatorPkg/EmulatorPkg.dec
-- 
2.33.0


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

* [RFC PATCH 3/4] EmulatorPkg/Unix/Host: Add AArch64 support
  2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
  2021-10-09 15:49 ` [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo Akira Moroo
  2021-10-09 15:49 ` [RFC PATCH 2/4] EmulatorPkg/Sec: Add AArch64 support Akira Moroo
@ 2021-10-09 15:49 ` Akira Moroo
  2021-10-09 15:49 ` [RFC PATCH 4/4] EmulatorPkg: Add AArch64 Unix host build support Akira Moroo
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Moroo @ 2021-10-09 15:49 UTC (permalink / raw)
  To: devel; +Cc: afish, ray.ni, Akira Moroo

Since there is no difference in calling convention between the Unix host
and the UEFI environment on AArch64, it does not require gaskets. In
this commit, it defines EmulatorPkg protocols that calls the host
functions without gaskets and adds AArch64 specific stack switch logic.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
---
 EmulatorPkg/Unix/Host/AArch64/Gasket.c       | 50 +++++++++++
 EmulatorPkg/Unix/Host/AArch64/SwitchStack.S  | 42 +++++++++
 EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c | 37 ++++++++
 EmulatorPkg/Unix/Host/BlockIo.c              | 26 ++++++
 EmulatorPkg/Unix/Host/EmuThunk.c             | 29 ++++++
 EmulatorPkg/Unix/Host/Host.c                 | 32 +++++++
 EmulatorPkg/Unix/Host/Host.inf               |  5 +-
 EmulatorPkg/Unix/Host/LinuxPacketFilter.c    | 38 ++++++++
 EmulatorPkg/Unix/Host/PosixFileSystem.c      | 94 +++++++++++++++++++-
 EmulatorPkg/Unix/Host/Pthreads.c             | 30 ++++++-
 EmulatorPkg/Unix/Host/X11GraphicsWindow.c    | 26 +++++-
 11 files changed, 405 insertions(+), 4 deletions(-)
 create mode 100644 EmulatorPkg/Unix/Host/AArch64/Gasket.c
 create mode 100644 EmulatorPkg/Unix/Host/AArch64/SwitchStack.S

diff --git a/EmulatorPkg/Unix/Host/AArch64/Gasket.c b/EmulatorPkg/Unix/Host/AArch64/Gasket.c
new file mode 100644
index 0000000000..69a728d408
--- /dev/null
+++ b/EmulatorPkg/Unix/Host/AArch64/Gasket.c
@@ -0,0 +1,50 @@
+/** @file
+
+  Copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
+  Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "Host.h"
+
+//
+// Reverse (UNIX to EFIAPI) gaskets
+//
+
+typedef
+UINTN
+(EFIAPI *CALL_BACK_1) (
+  UINT64 Delta
+  );
+
+UINTN
+ReverseGasketUint64 (
+  UINTN  CallBack,
+  UINT64 a
+  )
+{
+  return ((CALL_BACK_1) CallBack) (a);
+}
+
+//
+// UNIX ABI to EFI ABI call
+//
+
+typedef
+UINTN
+(EFIAPI *CALL_BACK_2) (
+  VOID  *Context,
+  VOID  *Key
+  );
+
+UINTN
+ReverseGasketUint64Uint64 (
+  VOID      *CallBack,
+  VOID      *Context,
+  VOID      *Key
+  )
+{
+  return ((CALL_BACK_2) CallBack) (Context, Key);
+}
diff --git a/EmulatorPkg/Unix/Host/AArch64/SwitchStack.S b/EmulatorPkg/Unix/Host/AArch64/SwitchStack.S
new file mode 100644
index 0000000000..6e903b94ef
--- /dev/null
+++ b/EmulatorPkg/Unix/Host/AArch64/SwitchStack.S
@@ -0,0 +1,42 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+# Portions copyright (c) 2011 - 2013, ARM Limited. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#------------------------------------------------------------------------------
+
+.text
+.align 5
+
+GCC_ASM_EXPORT(PeiSwitchStacks)
+
+#/**
+#
+#  This allows the caller to switch the stack and goes to the new entry point
+#
+# @param      EntryPoint   The pointer to the location to enter
+# @param      Context      Parameter to pass in
+# @param      Context2     Parameter2 to pass in
+# @param      NewStack     New Location of the stack
+#
+# @return     Nothing. Goes to the Entry Point passing in the new parameters
+#
+#**/
+#VOID
+#EFIAPI
+#PeiSwitchStacks (
+#  SWITCH_STACK_ENTRY_POINT EntryPoint,
+#  VOID  *Context,
+#  VOID  *Context2,
+#  VOID  *NewStack
+#  );
+#
+ASM_PFX(PeiSwitchStacks):
+  mov   x29, #0
+  mov   x30, x0
+  mov   sp, x3
+  mov   x0, x1
+  mov   x1, x2
+  ret
diff --git a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
index 441f1e8d0a..f591d94f4e 100644
--- a/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
+++ b/EmulatorPkg/Unix/Host/BerkeleyPacketFilter.c
@@ -972,6 +972,26 @@ EmuSnpReceive (
   return EFI_SUCCESS;
 }
 
+#if defined(__aarch64__)
+
+EMU_SNP_PROTOCOL gEmuSnpProtocol = {
+  EmuSnpCreateMapping,
+  EmuSnpStart,
+  EmuSnpStop,
+  EmuSnpInitialize,
+  EmuSnpReset,
+  EmuSnpShutdown,
+  EmuSnpReceiveFilters,
+  EmuSnpStationAddress,
+  EmuSnpStatistics,
+  EmuSnpMCastIpToMac,
+  EmuSnpNvData,
+  EmuSnpGetStatus,
+  EmuSnpTransmit,
+  EmuSnpReceive
+};
+
+#else
 
 EMU_SNP_PROTOCOL gEmuSnpProtocol = {
   GasketSnpCreateMapping,
@@ -990,6 +1010,8 @@ EMU_SNP_PROTOCOL gEmuSnpProtocol = {
   GasketSnpReceive
 };
 
+#endif
+
 EFI_STATUS
 GetInterfaceMacAddr (
   EMU_SNP_PRIVATE    *Private
@@ -1092,6 +1114,19 @@ EmuSnpThunkClose (
 }
 
 
+#if defined(__aarch64__)
+
+EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
+  &gEmuSnpProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  EmuSnpThunkOpen,
+  EmuSnpThunkClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
   &gEmuSnpProtocolGuid,
@@ -1104,3 +1139,5 @@ EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
 };
 
 #endif
+
+#endif
diff --git a/EmulatorPkg/Unix/Host/BlockIo.c b/EmulatorPkg/Unix/Host/BlockIo.c
index 18368060d5..b335db192e 100644
--- a/EmulatorPkg/Unix/Host/BlockIo.c
+++ b/EmulatorPkg/Unix/Host/BlockIo.c
@@ -594,6 +594,17 @@ StdDupUnicodeToAscii (
   return Ascii;
 }
 
+#if defined(__aarch64__)
+
+EMU_BLOCK_IO_PROTOCOL gEmuBlockIoProtocol = {
+  EmuBlockIoReset,
+  EmuBlockIoReadBlocks,
+  EmuBlockIoWriteBlocks,
+  EmuBlockIoFlushBlocks,
+  EmuBlockIoCreateMapping
+};
+
+#else
 
 EMU_BLOCK_IO_PROTOCOL gEmuBlockIoProtocol = {
   GasketEmuBlockIoReset,
@@ -603,6 +614,8 @@ EMU_BLOCK_IO_PROTOCOL gEmuBlockIoProtocol = {
   GasketEmuBlockIoCreateMapping
 };
 
+#endif
+
 EFI_STATUS
 EmuBlockIoThunkOpen (
   IN  EMU_IO_THUNK_PROTOCOL   *This
@@ -687,7 +700,19 @@ EmuBlockIoThunkClose (
   return EFI_SUCCESS;
 }
 
+#if defined(__aarch64__)
 
+EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo = {
+  &gEmuBlockIoProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  EmuBlockIoThunkOpen,
+  EmuBlockIoThunkClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo = {
   &gEmuBlockIoProtocolGuid,
@@ -699,4 +724,5 @@ EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo = {
   NULL
 };
 
+#endif
 
diff --git a/EmulatorPkg/Unix/Host/EmuThunk.c b/EmulatorPkg/Unix/Host/EmuThunk.c
index b8b0651c6a..bd78232f9c 100644
--- a/EmulatorPkg/Unix/Host/EmuThunk.c
+++ b/EmulatorPkg/Unix/Host/EmuThunk.c
@@ -396,6 +396,34 @@ SecGetNextProtocol (
   return GetNextThunkProtocol (EmuBusDriver, Instance);
 }
 
+#if defined(__aarch64__)
+
+EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
+  SecWriteStdErr,
+  SecConfigStdIn,
+  SecWriteStdOut,
+  SecReadStdIn,
+  SecPollStdIn,
+  SecMalloc,
+  SecValloc,
+  SecFree,
+  SecPeCoffGetEntryPoint,
+  SecPeCoffRelocateImageExtraAction,
+  SecPeCoffUnloadImageExtraAction,
+  SecEnableInterrupt,
+  SecDisableInterrupt,
+  QueryPerformanceFrequency,
+  QueryPerformanceCounter,
+  SecSleep,
+  SecCpuSleep,
+  SecExit,
+  SecGetTime,
+  SecSetTime,
+  SecSetTimer,
+  SecGetNextProtocol
+};
+
+#else
 
 EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
   GasketSecWriteStdErr,
@@ -422,6 +450,7 @@ EMU_THUNK_PROTOCOL gEmuThunkProtocol = {
   GasketSecGetNextProtocol
 };
 
+#endif
 
 VOID
 SecInitThunkProtocol (
diff --git a/EmulatorPkg/Unix/Host/Host.c b/EmulatorPkg/Unix/Host/Host.c
index b4e5510613..bba6282738 100644
--- a/EmulatorPkg/Unix/Host/Host.c
+++ b/EmulatorPkg/Unix/Host/Host.c
@@ -12,17 +12,49 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #define MAP_ANONYMOUS MAP_ANON
 #endif
 
+EFI_STATUS
+SecUnixPeiAutoScan (
+  IN  UINTN                 Index,
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,
+  OUT UINT64                *MemorySize
+  );
+
+EFI_STATUS
+SecUnixFdAddress (
+  IN     UINTN                 Index,
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,
+  IN OUT UINT64                *FdSize,
+  IN OUT EFI_PHYSICAL_ADDRESS  *FixUp
+  );
+
+VOID *
+SecEmuThunkAddress (
+  VOID
+  );
+
 
 //
 // Globals
 //
 
+#if defined(__aarch64__)
+
+EMU_THUNK_PPI mSecEmuThunkPpi = {
+  SecUnixPeiAutoScan,
+  SecUnixFdAddress,
+  SecEmuThunkAddress
+};
+
+#else
+
 EMU_THUNK_PPI mSecEmuThunkPpi = {
   GasketSecUnixPeiAutoScan,
   GasketSecUnixFdAddress,
   GasketSecEmuThunkAddress
 };
 
+#endif
+
 char *gGdbWorkingFileName = NULL;
 unsigned int mScriptSymbolChangesCount = 0;
 
diff --git a/EmulatorPkg/Unix/Host/Host.inf b/EmulatorPkg/Unix/Host/Host.inf
index c479d2b7d0..43cb55aa21 100644
--- a/EmulatorPkg/Unix/Host/Host.inf
+++ b/EmulatorPkg/Unix/Host/Host.inf
@@ -20,7 +20,7 @@
 #
 # The following information is for reference only and not required by the build tools.
 #
-#  VALID_ARCHITECTURES           = IA32 X64 EBC
+#  VALID_ARCHITECTURES           = IA32 X64 AARCH64 EBC
 #
 
 [Sources]
@@ -42,6 +42,9 @@
   Ia32/Gasket.S       # enforce 16-byte stack alignment for Mac OS X
   Ia32/SwitchStack.c
 
+[Sources.AARCH64]
+  AArch64/Gasket.c
+  AArch64/SwitchStack.S
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/EmulatorPkg/Unix/Host/LinuxPacketFilter.c b/EmulatorPkg/Unix/Host/LinuxPacketFilter.c
index 2b772ab884..9c696a8774 100644
--- a/EmulatorPkg/Unix/Host/LinuxPacketFilter.c
+++ b/EmulatorPkg/Unix/Host/LinuxPacketFilter.c
@@ -518,6 +518,27 @@ EmuSnpReceive (
 }
 
 
+#if defined(__aarch64__)
+
+EMU_SNP_PROTOCOL gEmuSnpProtocol = {
+  EmuSnpCreateMapping,
+  EmuSnpStart,
+  EmuSnpStop,
+  EmuSnpInitialize,
+  EmuSnpReset,
+  EmuSnpShutdown,
+  EmuSnpReceiveFilters,
+  EmuSnpStationAddress,
+  EmuSnpStatistics,
+  EmuSnpMCastIpToMac,
+  EmuSnpNvData,
+  EmuSnpGetStatus,
+  EmuSnpTransmit,
+  EmuSnpReceive
+};
+
+#else
+
 EMU_SNP_PROTOCOL gEmuSnpProtocol = {
   GasketSnpCreateMapping,
   GasketSnpStart,
@@ -535,6 +556,8 @@ EMU_SNP_PROTOCOL gEmuSnpProtocol = {
   GasketSnpReceive
 };
 
+#endif
+
 EFI_STATUS
 EmuSnpThunkOpen (
   IN  EMU_IO_THUNK_PROTOCOL   *This
@@ -584,6 +607,19 @@ EmuSnpThunkClose (
 }
 
 
+#if defined(__aarch64__)
+
+EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
+  &gEmuSnpProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  EmuSnpThunkOpen,
+  EmuSnpThunkClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
   &gEmuSnpProtocolGuid,
@@ -596,3 +632,5 @@ EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
 };
 
 #endif
+
+#endif
diff --git a/EmulatorPkg/Unix/Host/PosixFileSystem.c b/EmulatorPkg/Unix/Host/PosixFileSystem.c
index 0a618abcd8..4676f2f933 100644
--- a/EmulatorPkg/Unix/Host/PosixFileSystem.c
+++ b/EmulatorPkg/Unix/Host/PosixFileSystem.c
@@ -53,6 +53,51 @@ typedef struct {
       EMU_EFI_FILE_PRIVATE_SIGNATURE \
       )
 
+EFI_STATUS
+PosixFileOpen (
+  IN EFI_FILE_PROTOCOL        *This,
+  OUT EFI_FILE_PROTOCOL       **NewHandle,
+  IN CHAR16                   *FileName,
+  IN UINT64                   OpenMode,
+  IN UINT64                   Attributes
+  );
+
+EFI_STATUS
+PosixFileCLose (
+  IN EFI_FILE_PROTOCOL  *This
+  );
+
+EFI_STATUS
+PosixFileDelete (
+  IN EFI_FILE_PROTOCOL  *This
+  );
+
+EFI_STATUS
+PosixFileRead (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN OUT UINTN                *BufferSize,
+  OUT VOID                    *Buffer
+  );
+
+EFI_STATUS
+PosixFileWrite (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN OUT UINTN                *BufferSize,
+  IN VOID                     *Buffer
+  );
+
+EFI_STATUS
+PosixFileGetPossition (
+  IN EFI_FILE_PROTOCOL        *This,
+  OUT UINT64                  *Position
+  );
+
+EFI_STATUS
+PosixFileSetPossition (
+  IN EFI_FILE_PROTOCOL        *This,
+  IN UINT64                   Position
+  );
+
 EFI_STATUS
 PosixFileGetInfo (
   IN EFI_FILE_PROTOCOL        *This,
@@ -69,6 +114,39 @@ PosixFileSetInfo (
   IN VOID                     *Buffer
   );
 
+EFI_STATUS
+PosixFileFlush (
+  IN EFI_FILE_PROTOCOL  *This
+  );
+
+EFI_STATUS
+PosixOpenVolume (
+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL    *This,
+  OUT EFI_FILE_PROTOCOL                 **Root
+  );
+
+#if defined(__aarch64__)
+
+EFI_FILE_PROTOCOL gPosixFileProtocol = {
+  EFI_FILE_REVISION,
+  PosixFileOpen,
+  PosixFileCLose,
+  PosixFileDelete,
+  PosixFileRead,
+  PosixFileWrite,
+  PosixFileGetPossition,
+  PosixFileSetPossition,
+  PosixFileGetInfo,
+  PosixFileSetInfo,
+  PosixFileFlush
+};
+
+EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gPosixFileSystemProtocol = {
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
+  PosixOpenVolume,
+};
+
+#else
 
 EFI_FILE_PROTOCOL gPosixFileProtocol = {
   EFI_FILE_REVISION,
@@ -89,6 +167,7 @@ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL gPosixFileSystemProtocol = {
   GasketPosixOpenVolume,
 };
 
+#endif
 
 /**
   Open the root directory on a volume.
@@ -1573,6 +1652,19 @@ PosixFileSystmeThunkClose (
   return EFI_SUCCESS;
 }
 
+#if defined(__aarch64__)
+
+EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo = {
+  &gEfiSimpleFileSystemProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  PosixFileSystmeThunkOpen,
+  PosixFileSystmeThunkClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo = {
   &gEfiSimpleFileSystemProtocolGuid,
@@ -1584,4 +1676,4 @@ EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo = {
   NULL
 };
 
-
+#endif
diff --git a/EmulatorPkg/Unix/Host/Pthreads.c b/EmulatorPkg/Unix/Host/Pthreads.c
index 025687c356..3613e4cf60 100644
--- a/EmulatorPkg/Unix/Host/Pthreads.c
+++ b/EmulatorPkg/Unix/Host/Pthreads.c
@@ -173,6 +173,20 @@ PthreadSelf (
   return (UINTN)pthread_self ();
 }
 
+#if defined(__aarch64__)
+
+EMU_THREAD_THUNK_PROTOCOL gPthreadThunk = {
+  PthreadMutexLock,
+  PthreadMutexUnLock,
+  PthreadMutexTryLock,
+  PthreadMutexInit,
+  PthreadMutexDestroy,
+  PthreadCreate,
+  PthreadExit,
+  PthreadSelf
+};
+
+#else
 
 EMU_THREAD_THUNK_PROTOCOL gPthreadThunk = {
   GasketPthreadMutexLock,
@@ -185,6 +199,7 @@ EMU_THREAD_THUNK_PROTOCOL gPthreadThunk = {
   GasketPthreadSelf
 };
 
+#endif
 
 EFI_STATUS
 PthreadOpen (
@@ -215,6 +230,19 @@ PthreadClose (
   return EFI_SUCCESS;
 }
 
+#if defined(__aarch64__)
+
+EMU_IO_THUNK_PROTOCOL gPthreadThunkIo = {
+  &gEmuThreadThunkProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  PthreadOpen,
+  PthreadClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gPthreadThunkIo = {
   &gEmuThreadThunkProtocolGuid,
@@ -226,4 +254,4 @@ EMU_IO_THUNK_PROTOCOL gPthreadThunkIo = {
   NULL
 };
 
-
+#endif
diff --git a/EmulatorPkg/Unix/Host/X11GraphicsWindow.c b/EmulatorPkg/Unix/Host/X11GraphicsWindow.c
index 5325a0e35b..cff8a6f7b9 100644
--- a/EmulatorPkg/Unix/Host/X11GraphicsWindow.c
+++ b/EmulatorPkg/Unix/Host/X11GraphicsWindow.c
@@ -918,6 +918,16 @@ X11GraphicsWindowOpen (
     return EFI_OUT_OF_RESOURCES;
   }
 
+#if defined(__aarch64__)
+  Drv->GraphicsIo.Size                = X11Size;
+  Drv->GraphicsIo.CheckKey            = X11CheckKey;
+  Drv->GraphicsIo.GetKey              = X11GetKey;
+  Drv->GraphicsIo.KeySetState         = X11KeySetState;
+  Drv->GraphicsIo.RegisterKeyNotify   = X11RegisterKeyNotify;
+  Drv->GraphicsIo.Blt                 = X11Blt;
+  Drv->GraphicsIo.CheckPointer        = X11CheckPointer;
+  Drv->GraphicsIo.GetPointerState     = X11GetPointerState;
+#else
   Drv->GraphicsIo.Size                = GasketX11Size;
   Drv->GraphicsIo.CheckKey            = GasketX11CheckKey;
   Drv->GraphicsIo.GetKey              = GasketX11GetKey;
@@ -926,6 +936,7 @@ X11GraphicsWindowOpen (
   Drv->GraphicsIo.Blt                 = GasketX11Blt;
   Drv->GraphicsIo.CheckPointer        = GasketX11CheckPointer;
   Drv->GraphicsIo.GetPointerState     = GasketX11GetPointerState;
+#endif
 
 
   Drv->key_count = 0;
@@ -1008,6 +1019,19 @@ X11GraphicsWindowClose (
   return EFI_SUCCESS;
 }
 
+#if defined(__aarch64__)
+
+EMU_IO_THUNK_PROTOCOL gX11ThunkIo = {
+  &gEmuGraphicsWindowProtocolGuid,
+  NULL,
+  NULL,
+  0,
+  X11GraphicsWindowOpen,
+  X11GraphicsWindowClose,
+  NULL
+};
+
+#else
 
 EMU_IO_THUNK_PROTOCOL gX11ThunkIo = {
   &gEmuGraphicsWindowProtocolGuid,
@@ -1019,4 +1043,4 @@ EMU_IO_THUNK_PROTOCOL gX11ThunkIo = {
   NULL
 };
 
-
+#endif
-- 
2.33.0


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

* [RFC PATCH 4/4] EmulatorPkg: Add AArch64 Unix host build support
  2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
                   ` (2 preceding siblings ...)
  2021-10-09 15:49 ` [RFC PATCH 3/4] EmulatorPkg/Unix/Host: " Akira Moroo
@ 2021-10-09 15:49 ` Akira Moroo
  3 siblings, 0 replies; 5+ messages in thread
From: Akira Moroo @ 2021-10-09 15:49 UTC (permalink / raw)
  To: devel; +Cc: afish, ray.ni, Akira Moroo

This commit adds AArch64 Unix host build support for EmulatorPkg.

Signed-off-by: Akira Moroo <retrage01@gmail.com>
---
 EmulatorPkg/EmulatorPkg.dsc    | 15 ++++++++++++---
 EmulatorPkg/Readme.md          |  8 ++++++++
 EmulatorPkg/Unix/Host/Host.inf |  5 +++++
 EmulatorPkg/build.sh           |  8 ++++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 554c13ddb5..91d0176fc7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -19,7 +19,7 @@
   DSC_SPECIFICATION              = 0x00010005
   OUTPUT_DIRECTORY               = Build/Emulator$(ARCH)
 
-  SUPPORTED_ARCHITECTURES        = X64|IA32
+  SUPPORTED_ARCHITECTURES        = X64|IA32|AARCH64
   BUILD_TARGETS                  = DEBUG|RELEASE|NOOPT
   SKUID_IDENTIFIER               = DEFAULT
   FLASH_DEFINITION               = EmulatorPkg/EmulatorPkg.fdf
@@ -138,6 +138,13 @@
   AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
 !endif
 
+[LibraryClasses.AARCH64]
+  ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
+  ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
+  CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
+  NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+  NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf
+
 [LibraryClasses.common.SEC]
   PeiServicesLib|EmulatorPkg/Library/SecPeiServicesLib/SecPeiServicesLib.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
@@ -209,8 +216,10 @@
   TimerLib|EmulatorPkg/Library/DxeTimerLib/DxeTimerLib.inf
 
 [PcdsFeatureFlag]
-  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
   gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|FALSE
+
+[PcdsFeatureFlag.IA32,PcdsFeatureFlag.X64]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables|FALSE
 
 [PcdsFixedAtBuild]
@@ -288,7 +297,7 @@
   gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|L"Timeout"|gEfiGlobalVariableGuid|0x0|10
 
 [Components]
-!if "IA32" in $(ARCH) || "X64" in $(ARCH)
+!if "IA32" in $(ARCH) || "X64" in $(ARCH) || "AARCH64" in $(ARCH)
   !if "MSFT" in $(FAMILY) || $(WIN_HOST_BUILD) == TRUE
     ##
     #  Emulator, OS WIN application
diff --git a/EmulatorPkg/Readme.md b/EmulatorPkg/Readme.md
index 0c2eea6a9a..e3d0b58578 100644
--- a/EmulatorPkg/Readme.md
+++ b/EmulatorPkg/Readme.md
@@ -35,6 +35,10 @@ https://github.com/tianocore/tianocore.github.io/wiki/EmulatorPkg
 
     `build -p EmulatorPkg\EmulatorPkg.dsc -t GCC5 -a X64`
 
+  * AArch64 emulator in Linux:
+
+    `build -p EmulatorPkg\EmulatorPkg.dsc -t GCC5 -a AARCH64`
+
 **You can start/run the emulator using the following command:**
   * 32bit emulator in Windows:
 
@@ -52,6 +56,10 @@ https://github.com/tianocore/tianocore.github.io/wiki/EmulatorPkg
 
     `cd Build/EmulatorX64/DEBUG_GCC5/X64/ && ./Host`
 
+  * AArch64 emulator in Linux:
+
+    `cd Build/EmulatorAARCH64/DEBUG_GCC5/AARCH64/ && ./Host`
+
 **On posix-like environment with the bash shell you can use EmulatorPkg/build.sh to simplify building and running
 emulator.**
 
diff --git a/EmulatorPkg/Unix/Host/Host.inf b/EmulatorPkg/Unix/Host/Host.inf
index 43cb55aa21..fe4c6d511c 100644
--- a/EmulatorPkg/Unix/Host/Host.inf
+++ b/EmulatorPkg/Unix/Host/Host.inf
@@ -129,6 +129,11 @@
    GCC:*_*_X64_PP_FLAGS == -m64 -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
    GCC:*_*_X64_ASM_FLAGS == -m64 -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
 
+   GCC:*_*_AARCH64_DLINK_FLAGS == -fPIC -flto -o $(BIN_DIR)/Host -L/usr/X11R6/lib
+   GCC:*_*_AARCH64_ASM_FLAGS == -g -c -x assembler -imacros $(DEST_DIR_DEBUG)/AutoGen.h
+   GCC:*_*_AARCH64_PP_FLAGS == -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
+   GCC:*_*_AARCH64_CC_FLAGS == -c -O0 -g -fPIC -fshort-wchar -fno-strict-aliasing -idirafter/usr/include -include $(DEST_DIR_DEBUG)/AutoGen.h -DUSING_LTO -DSTRING_ARRAY_NAME=$(BASE_NAME)Strings
+
    GCC:*_*_*_DLINK2_FLAGS == -lpthread -ldl -lXext -lX11
 
 #
diff --git a/EmulatorPkg/build.sh b/EmulatorPkg/build.sh
index 76c22dfaf8..e2ce1b8e18 100755
--- a/EmulatorPkg/build.sh
+++ b/EmulatorPkg/build.sh
@@ -83,6 +83,9 @@ case `uname` in
       x86_64)
         HOST_PROCESSOR=X64
         ;;
+      aarch64)
+        HOST_PROCESSOR=AARCH64
+        ;;
     esac
 
     gcc_version=$(gcc -v 2>&1 | tail -1 | awk '{print $3}')
@@ -174,6 +177,11 @@ case $PROCESSOR in
     LIB_NAMES="ld-linux-x86-64.so.2 libdl.so.2 crt1.o crti.o crtn.o"
     LIB_SEARCH_PATHS="/usr/lib/x86_64-linux-gnu /usr/lib64 /lib64 /usr/lib /lib"
     ;;
+  AARCH64)
+    ARCH_SIZE=64
+    LIB_NAMES="ld-linux-aarch64.so.1 libdl.so.2 crt1.o crti.o crtn.o"
+    LIB_SEARCH_PATHS="/usr/lib/aarch64-linux-gnu /usr/lib /lib"
+    ;;
 esac
 
 for libname in $LIB_NAMES
-- 
2.33.0


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

end of thread, other threads:[~2021-10-09 15:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-09 15:49 [RFC PATCH 0/4] EmulatorPkg AArch64 Linux support retrage01
2021-10-09 15:49 ` [RFC PATCH 1/4] EmulatorPkg/Unix/Host: Fix typo Akira Moroo
2021-10-09 15:49 ` [RFC PATCH 2/4] EmulatorPkg/Sec: Add AArch64 support Akira Moroo
2021-10-09 15:49 ` [RFC PATCH 3/4] EmulatorPkg/Unix/Host: " Akira Moroo
2021-10-09 15:49 ` [RFC PATCH 4/4] EmulatorPkg: Add AArch64 Unix host build support Akira Moroo

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