Difference between revisions of "Development:ARM64EC"

From FEX-Emu Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
[[Category:Development]]
 
=== Building ===
 
=== Building ===
 
These instructions expect you to be building on an ARM64 host.  
 
These instructions expect you to be building on an ARM64 host.  
Line 6: Line 7:
 
  export PATH="<path to toolchain>/bin:$PATH"
 
  export PATH="<path to toolchain>/bin:$PATH"
 
note the toolchain must come before all other path entries as it needs to override the host ar binary.
 
note the toolchain must come before all other path entries as it needs to override the host ar binary.
 +
* Make sure to grab the tar.gz aarch64 files when compiling on Linux. The zip files are for a Windows toolchain which doesn't work for these instructions.
  
 
==== Wine ====
 
==== Wine ====
Line 18: Line 20:
 
  mkdir build-arm64ec
 
  mkdir build-arm64ec
 
  cd build-arm64ec
 
  cd build-arm64ec
  cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/arm64ec-windows -DENABLE_LTO=False -DMINGW_TRIPLE=arm64ec-w64-mingw32 <path to fex>
+
  cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/aarch64-windows -DENABLE_LTO=False -DMINGW_TRIPLE=arm64ec-w64-mingw32 -DBUILD_TESTS=False <path to fex>
 
  ninja
 
  ninja
 
  sudo ninja install
 
  sudo ninja install
Line 24: Line 26:
 
  mkdir build-wow64
 
  mkdir build-wow64
 
  cd build-wow64
 
  cd build-wow64
  cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/aarch64-windows -DENABLE_LTO=False -DMINGW_TRIPLE=aarch64-w64-mingw32 <path to fex>
+
  cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/aarch64-windows -DENABLE_LTO=False -DMINGW_TRIPLE=aarch64-w64-mingw32 -DBUILD_TESTS=False <path to fex>
 
  ninja
 
  ninja
 
  sudo ninja install
 
  sudo ninja install
Line 46: Line 48:
 
  cpu = 'aarch64'
 
  cpu = 'aarch64'
 
  endian = 'little'
 
  endian = 'little'
 +
 +
=== Windows ===
 +
ARM64EC FEX is usable as a drop-in replacement for xtajit64 on native WOA, build FEX with -DUSE_PDB_DEBUGINFO=True and copy the libarm64ecfex.{dll,pdb} binaries into C:/Windows/System32. To actually use FEX create an empty registry key at HKLM\\Software\\Microsoft\\Wow64\\amd64 and set its value to libarm64ecfex.dll, all subsequently launched programs will then use FEX. Logs/configuration is stored in %localappdata%.
  
 
=== Info ===
 
=== Info ===
 
Unlike Linux FEX, the Windows FEX modules purely handle CPU emulation, with syscall translation being done on either the wine side (WOW64) or ABI (ARM64EC). This is similarly the case for wine's unixcalls and as a result native ARM64 variants can be used for all .so libraries (Vulkan, wine, etc.) dropping the need for an x86 rootfs and FEX-side thunking.  
 
Unlike Linux FEX, the Windows FEX modules purely handle CPU emulation, with syscall translation being done on either the wine side (WOW64) or ABI (ARM64EC). This is similarly the case for wine's unixcalls and as a result native ARM64 variants can be used for all .so libraries (Vulkan, wine, etc.) dropping the need for an x86 rootfs and FEX-side thunking.  
 
 
  
 
WOW64 is fairly simple, every DLL is compiled with both x86 and ARM64 variants and in an x86 process only the x86 variants are loaded (with ARM64 FEX and ntdll) the only thunking done is for {unix,sys}calls so almost all Windows code is emulated.  
 
WOW64 is fairly simple, every DLL is compiled with both x86 and ARM64 variants and in an x86 process only the x86 variants are loaded (with ARM64 FEX and ntdll) the only thunking done is for {unix,sys}calls so almost all Windows code is emulated.  
 
 
  
 
ARM64EC on the otherhand avoids duplicating DLLs at all, instead choosing to introduce a new ARM64 ABI allowing for transparent compiler-aided interop with any existing x86_64 code. The following pages serve as a good introduction:  
 
ARM64EC on the otherhand avoids duplicating DLLs at all, instead choosing to introduce a new ARM64 ABI allowing for transparent compiler-aided interop with any existing x86_64 code. The following pages serve as a good introduction:  
  
<nowiki>https://learn.microsoft.com/en-us/windows/arm/arm64ec</nowiki>
+
https://learn.microsoft.com/en-us/windows/arm/arm64ec  
 
 
<nowiki>https://learn.microsoft.com/en-us/windows/arm/arm64ec-abi</nowiki>
 
  
<nowiki>https://gitlab.winehq.org/wine/wine/-/wikis/ARM64EC-Toolchain</nowiki>
+
https://learn.microsoft.com/en-us/windows/arm/arm64ec-abi
  
 +
https://gitlab.winehq.org/wine/wine/-/wikis/ARM64EC-Toolchain
  
 
Of note is the fact that FEX needs to run in a very reduced Windows environment - due to how early it is loaded it can only depend on ntdll and not say the system CRT. This is worked around by implementing/stubbing the subset of the CRT/Windows APIs necessary for FEX to run/link purely ontop of ntdll (see Common/Windows/{WinAPI,CRT}).
 
Of note is the fact that FEX needs to run in a very reduced Windows environment - due to how early it is loaded it can only depend on ntdll and not say the system CRT. This is worked around by implementing/stubbing the subset of the CRT/Windows APIs necessary for FEX to run/link purely ontop of ntdll (see Common/Windows/{WinAPI,CRT}).

Latest revision as of 01:39, 5 October 2024

Building

These instructions expect you to be building on an ARM64 host.

Toolchain

Scripts and instructions to build an ARM64EC toolchain can be found here, with prebuilt binaries for ARM64/x86 hosts on the releases page. Once built/downloaded, add it to your environment with

export PATH="<path to toolchain>/bin:$PATH"

note the toolchain must come before all other path entries as it needs to override the host ar binary.

  • Make sure to grab the tar.gz aarch64 files when compiling on Linux. The zip files are for a Windows toolchain which doesn't work for these instructions.

Wine

Upstream wine has various things missing for full FEX/ARM64EC support, while it can be used, my fork will give the best results for now. Make sure to install the deps listed here before building.

 ./configure --enable-archs=arm64ec,aarch64,i386 --with-mingw=clang
 make -j$(nproc)
 sudo make install

FEX

FEX must be built twice, once for the x86 (WOW64) emulation module and once for x86_64 emulation module (ARM64EC)

mkdir build-arm64ec
cd build-arm64ec
cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/aarch64-windows -DENABLE_LTO=False -DMINGW_TRIPLE=arm64ec-w64-mingw32 -DBUILD_TESTS=False <path to fex>
ninja
sudo ninja install
cd ..
mkdir build-wow64
cd build-wow64
cmake -GNinja -DCMAKE_BUILD_TYPE=<desire build type> -DCMAKE_TOOLCHAIN_FILE=/data/Proton/FEX/toolchain_mingw.cmake -DCMAKE_INSTALL_LIBDIR=/usr/local/lib/wine/aarch64-windows -DENABLE_LTO=False -DMINGW_TRIPLE=aarch64-w64-mingw32 -DBUILD_TESTS=False <path to fex>
ninja
sudo ninja install
cd ..

dxvk/vkd3d-proton

Both can be built and installed as instructed on their respective github pages, except that a path to the following cross file should be passed to meson with --cross-file:

[binaries]
ar = 'arm64ec-w64-mingw32-ar'
c = 'arm64ec-w64-mingw32-gcc'
cpp = 'arm64ec-w64-mingw32-g++'
ld = 'arm64ec-w64-mingw32-ld'
windres = 'arm64ec-w64-mingw32-windres'
strip = 'strip'
widl = 'arm64ec-w64-mingw32-widl'
pkgconfig = 'aarch64-linux-gnu-pkg-config'
[host_machine]
system = 'windows'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

Windows

ARM64EC FEX is usable as a drop-in replacement for xtajit64 on native WOA, build FEX with -DUSE_PDB_DEBUGINFO=True and copy the libarm64ecfex.{dll,pdb} binaries into C:/Windows/System32. To actually use FEX create an empty registry key at HKLM\\Software\\Microsoft\\Wow64\\amd64 and set its value to libarm64ecfex.dll, all subsequently launched programs will then use FEX. Logs/configuration is stored in %localappdata%.

Info

Unlike Linux FEX, the Windows FEX modules purely handle CPU emulation, with syscall translation being done on either the wine side (WOW64) or ABI (ARM64EC). This is similarly the case for wine's unixcalls and as a result native ARM64 variants can be used for all .so libraries (Vulkan, wine, etc.) dropping the need for an x86 rootfs and FEX-side thunking.

WOW64 is fairly simple, every DLL is compiled with both x86 and ARM64 variants and in an x86 process only the x86 variants are loaded (with ARM64 FEX and ntdll) the only thunking done is for {unix,sys}calls so almost all Windows code is emulated.

ARM64EC on the otherhand avoids duplicating DLLs at all, instead choosing to introduce a new ARM64 ABI allowing for transparent compiler-aided interop with any existing x86_64 code. The following pages serve as a good introduction:

https://learn.microsoft.com/en-us/windows/arm/arm64ec

https://learn.microsoft.com/en-us/windows/arm/arm64ec-abi

https://gitlab.winehq.org/wine/wine/-/wikis/ARM64EC-Toolchain

Of note is the fact that FEX needs to run in a very reduced Windows environment - due to how early it is loaded it can only depend on ntdll and not say the system CRT. This is worked around by implementing/stubbing the subset of the CRT/Windows APIs necessary for FEX to run/link purely ontop of ntdll (see Common/Windows/{WinAPI,CRT}).