Emulating X86 On Apple’s AARCH64 X64 Emulator

You might know [Evan Martin] as the developer of retrowin32. It’s a Windows and x86 emulator designed to run on a Mac or on the web. He’s recently been exploring how to run 32-bit x86 binaries on the AArch64 (aka ARM64) architecture.

[Evan] realized that Apple’s ARM-based Macs feature a high-quality x86 emulator, used via the Rosetta binary translation system. It only supports 64-bit x86-64 binaries, also known as x64, and thus he had initially discounted it for running older 32-bit x86 software. However, as it turns out, x64 features a special compatibility mode for running 32-bit code. [Evan] was able to leverage this to run 32-bit Windows executables rather neatly via the high-performance Rosetta emulator.

To run a 32-bit executable on a 64-bit processor in this way, one creates a 64-bit program that is tasked with loading the 32-bit executable. It’s a little fussy, involving some tricks to handle memory management between the 32-bit code and the 64-bit wrapper, and how to interface with the OS, but [Evan] explains deftly how it’s all done.

[Evan] notes that this hack may not work forever, especially if Apple changes or deprecates Rosetta’s remaining x86-64 emulation in the future. Regardless, Apple’s “Game Porting Toolkit” relies on similar techniques used by Wine. If you find yourself dancing across platforms, you might learn some nifty tricks from [Evan]’s example!

7 thoughts on “Emulating X86 On Apple’s AARCH64 X64 Emulator

  1. The asahi team did a short demo of running x86 steam and portal on the M1 under linux with FEX, but it required running the system on a 4K page kernel to match x86. Long term, that’s not feasible.

    The M1’s IOMMU only works in 16K page mode and is pretty important, and right now linux isn’t capable of running a mixed-page system like macOS where the IOMMU is handled in 16K chunks but the rest of the system runs with 4K pages. I think the asahi team had a hacked set of patches to try to do that, but they weren’t upstream-ready and might never be. Afaik they’re also more interested in getting applications to support 16K pages long-term, rather than be shackled to x86’s 4K.

    There have been some ideas tossed around to try to get FEX to emulate 4K pages on a 16K page system, but so far it’s mostly theory and it’ll probably either not be airtight enough to trick anticheat (not that wine doesn’t already set it off) or it’ll be super slow because it’s essentially single-stepping through the code.

  2. The last time Apple rolled out Rosetta was for the PowerPC to x86 transition. They supported it for a while and then took it out of… whatever version… 10.5? So yeah, Apple giveth and Apple taketh away. Consider it a short term hack and figure out how you’re going to get aarch64 versions of your various software.

    Note to pedants – it really was x86. The 2006 MBP had a Core Duo processor. Core 2 Duo, and hence 64 bit architecture, didn’t occur until the next year (ish).

    1. Hi there. I think it was 10.7..
      10.6 was Snow Leopard, which still shipped with Rosetta on the DVD (manual install).
      That was one of the reasons as to why “Snowy” had a cult following. Similar to Tiger (10.4, supported G3/G4/G5 and x86).

      1. Thank you – a combination of memory decline and laziness on my part.

        I bought a Powerbook in probably 04 and I’m pretty sure I ran 10.3.something. What was the name of the thing that let you run MacOS 9 68K applications on OSX? Or was it some sort of VM kind of thing, faintly like WSL version 2? Whatever it was, I remember it was pretty cool and let me run an ancient, paid-up version of Photoshop without re-licensing.

        1. I actually have a PowerBook booting Mac OS 9 and Tiger, so I can verify this. It was just called the Classic environment. If you tried to start a classic Mac executable, it would boot up your classic system folder, extensions and all, in a virtual machine and your application windows would appear seamlessly on your OS X desktop, though anything run within Classic would be Platinum themed, and the old menu bar would show up if a classic window was focused. Even though later PowerPC Macs could not boot OS 9, they included a system folder for use with Classic.

    2. Rosetta was for PowerPC to x86, yes… but Rosetta 2 is for x86 to Arm.

      BTW: congratulations to Hackaday for adding a simple popup to confirm that you want to report a comment. As usual, I pressed the wrong link when I wanted to reply this O:-)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.