Box64 Documentation

repository·main·Indexed 25 days ago

https://github.com/ptitseb/box64

A Linux userspace x86_64 emulator designed to run 64-bit x86 programs on non-x86_64 Linux systems, such as ARM-based devices. It features a dynamic recompiler (DynaRec) for performance, support for Wine64 and Proton, and a library bundler for x86_64 and x86 libraries. The documentation covers installation via PKGBUILD, compilation options for various hardware platforms (Raspberry Pi, NVIDIA Jetson, Snapdragon), configuration via .box64rc files, and the use of the wrapperhelper tool for generating private headers.

Tokens
12.5K
Snippets
18
Records
81
Agent score
87%

What's inside Box64

  1. Overview of Box64

    main

    Box64 is an x86_64 Linux userspace emulator designed to run x86_64 Linux programs (such as games) on non-x86_64 Linux systems, such as ARM (provided the host system has a 64-bit endianness).

    Key features:

    • Uses native versions of system libraries (e.g., libc, libm, SDL, and OpenGL) for high performance and easy integration.
    • Integrates with DynaRec (a dynamic recompiler) on ARM64 and RV64 platforms, providing a 5-10x speed increase over pure interpretation.
    • Supports Wine64 and Proton.
  2. Create a DEBUG build of Box64 via PKGBUILD

    main

    If you require a debug build instead of the default RelWithDebInfo build, modify the PKGBUILD file by replacing the build type string using sed before running makepkg.

    sed -i 's/RelWithDebInfo/Debug/g' ./PKGBUILD
  3. Choose the appropriate Wine variant for Box64

    main

    Depending on your architecture and the Windows executables you need to run, you should choose one of the following Wine configurations:

    • x86 Wine: Runs x32 Windows executables. Requires a 32-bit Linux environment (e.g., armhf on Arm64). On architectures without 32-bit support (like RISC-V 64 or LoongArch64), you can use Box64 with the experimental BOX32 mode enabled.
    • x86_64 Wine: Runs x64 Windows executables. Works directly with Box64. Often includes x86 Wine, allowing a combination of Box86 + Box64 to run both 32-bit and 64-bit apps.
    • x86_64 Wine WOW64: Runs both x32 and x64 Windows executables. It handles 32-bit emulation internally, meaning you only need Box64 (no Box32 or Box86 required). Note: WineD3D performance for 32-bit programs is poor in this mode; it is highly recommended to use DXVK instead.
    • Arm64 Wine WOW64: Runs x32, x64, Arm32, and Arm64 Windows executables. Requires cpu.dll (WOW64 for 32-bit and Arm64EC for 64-bit). Box64 supports 32-bit WOW64 DLLs if the WOW64 CMake option is enabled during compilation.
  4. Cross-compile Box64 for a target architecture

    main

    To cross-compile Box64 (e.g., compiling for RISC-V on an x86 machine), follow these steps:

    1. Set up the Cross-Compiler: Obtain a prebuilt GNU toolchain for your target architecture (e.g., from riscv-gnu-toolchain).
    2. Configure CMake: Run CMake with the appropriate cross-compiler specified via -DCMAKE_C_COMPILER. Ensure the compiler version is compatible with your target's glibc version. You can check the target's glibc version by running ldd --version on the target machine.
    3. Verify with QEMU (Optional): You can run the compiled binary under QEMU to verify it works. You will need to provide the path to your target's sysroot.

    To run CTest-based tests under QEMU, use ctest.

  5. Run Windows programs via Wine and Box64

    main

    Box64 supports Wine64 and Proton.

    • 64-bit Windows programs: Can be run directly with Box64.
    • 32-bit Windows components: Require Box86 to be installed alongside Box64.
    • Experimental WOW64: You can use a Wine WOW64 build to run x86 Windows programs in Box64-only environments, which works in most cases.
  6. Compile and install Box64 using the general approach

    main

    To build Box64 from source, clone the repository, create a build directory, run cmake with your desired options, and then compile using make. After installation, you may need to restart systemd-binfmt to enable kernel-level executable recognition.

    Note: Use make -j1 or make -j2 if you are running low on memory. If you are on a Linux kernel mixed with Android (e.g., RK3588), add -DBAD_SIGNAL=ON to your cmake command.

    git clone https://github.com/ptitSeb/box64
    cd box64
    mkdir build; cd build; cmake .. ${OPTIONS}
    make -j4
    sudo make install
    sudo systemctl restart systemd-binfmt
  7. Run Unity games on ARM SBCs

    main

    Running Unity3D games may require OpenGL 3+ and support for compressed textures like BC7 (which many ARM integrated GPUs lack).

    Optimization for Raspberry Pi 4 and Pi 5: To prevent hangs and enable strong memory mode, use the following environment variables:

    MESA_GL_VERSION_OVERRIDE=3.2 BOX64_DYNAREC_STRONGMEM=1

    If the game starts but crashes before displaying anything, try using the Panfrost higher profile:

    PAN_MESA_DEBUG=gl3
  8. Install Box64 shared libraries on the target machine

    main

    When cross-compiling, make install does not run on the target machine. Therefore, you must manually install the Box64 shared libraries required for emulation.

    After cross-compiling, copy the x64lib (for x86_64) or x86lib (for i386) folder from the Box64 repository to your target device, rename it, and place it in a library search path like /usr/lib.

    # For x86_64 targets:
    $ mv x64lib box64-x86_64-linux-gnu
    $ mv box64-x86_64-linux-gnu /usr/lib
    
    # For i386 targets:
    $ mv x86lib box64-i386-linux-gnu
    $ mv box64-i386-linux-gnu /usr/lib
  9. Configure Box64 using configuration files

    main

    If you are using the regular Linux build, Box64 supports configuration files (rcfiles). Settings are applied based on priority: ~/.box64rc (highest) > /etc/box64.box64rc > environment variables.

    In WowBox64 (Wine WOW64 build), the configuration file is only checked at %USERPROFILE%/.box64rc.

    You can specify a custom configuration file location using the BOX64_RCFILE environment variable.

    [factorio]
    BOX64_DYNAREC_SAFEFLAGS=0
    BOX64_DYNAREC_BIGBLOCK=2
    BOX64_DYNAREC_FORWARD=1024
    BOX64_DYNAREC_CALLRET=1
    
    [*]
    # Global settings apply to all applications
    BOX64_DYNAREC_FASTNAN=1
  10. Optimize Unity games for ARM/RISC-V

    main

    Many Unity games require OpenGL 3+, which can be challenging on SBCs. Use the following environment variables to improve compatibility and stability:

    • For Raspberry Pi 4 and Pi 5 users: Set MESA_GL_VERSION_OVERRIDE=3.2 and BOX64_DYNAREC_STRONGMEM=1 to prevent freezes and enable strong memory mode.
    • For Panfrost users: Set PAN_MESA_DEBUG=gl3 to force a higher OpenGL Profile if games crash before displaying content.